2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
2020-07-07 22:06:48 +00:00
|
|
|
// Copyright (C) 2020-2021 Igara Studio S.A.
|
2018-02-21 13:39:30 +00:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 15:16:25 +00:00
|
|
|
//
|
2016-08-26 20:02:58 +00:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-06-16 02:37:59 +00:00
|
|
|
#include "config.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#endif
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2015-03-02 19:07:35 +00:00
|
|
|
#include "app/file_selector.h"
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/pref/preferences.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/ui/file_selector.h"
|
2018-08-09 15:58:43 +00:00
|
|
|
#include "os/native_dialogs.h"
|
|
|
|
#include "os/system.h"
|
2020-07-07 22:06:48 +00:00
|
|
|
#include "os/window.h"
|
2012-06-16 02:37:59 +00:00
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
2017-04-08 03:06:25 +00:00
|
|
|
bool show_file_selector(
|
2015-06-03 19:34:27 +00:00
|
|
|
const std::string& title,
|
2014-04-20 22:53:27 +00:00
|
|
|
const std::string& initialPath,
|
2018-02-21 13:39:30 +00:00
|
|
|
const base::paths& extensions,
|
2015-06-03 19:34:27 +00:00
|
|
|
FileSelectorType type,
|
2018-03-15 23:34:01 +00:00
|
|
|
base::paths& output)
|
2012-06-16 02:37:59 +00:00
|
|
|
{
|
2018-02-23 13:32:02 +00:00
|
|
|
const std::string defExtension =
|
|
|
|
Preferences::instance().saveFile.defaultExtension();
|
|
|
|
|
2015-05-18 19:53:25 +00:00
|
|
|
if (Preferences::instance().experimental.useNativeFileDialog() &&
|
2018-08-09 15:58:43 +00:00
|
|
|
os::instance()->nativeDialogs()) {
|
2020-07-07 22:06:48 +00:00
|
|
|
os::FileDialogRef dlg =
|
|
|
|
os::instance()->nativeDialogs()->makeFileDialog();
|
2015-03-02 19:07:35 +00:00
|
|
|
|
|
|
|
if (dlg) {
|
|
|
|
dlg->setTitle(title);
|
|
|
|
dlg->setFileName(initialPath);
|
|
|
|
|
2018-08-09 15:58:43 +00:00
|
|
|
os::FileDialog::Type nativeType = os::FileDialog::Type::OpenFile;
|
2017-04-08 03:06:25 +00:00
|
|
|
switch (type) {
|
|
|
|
case FileSelectorType::Open:
|
2018-08-09 15:58:43 +00:00
|
|
|
nativeType = os::FileDialog::Type::OpenFile;
|
2017-12-21 19:34:17 +00:00
|
|
|
break;
|
2017-04-08 03:06:25 +00:00
|
|
|
case FileSelectorType::OpenMultiple:
|
2018-08-09 15:58:43 +00:00
|
|
|
nativeType = os::FileDialog::Type::OpenFiles;
|
2017-04-08 03:06:25 +00:00
|
|
|
break;
|
|
|
|
case FileSelectorType::Save:
|
2018-08-09 15:58:43 +00:00
|
|
|
nativeType = os::FileDialog::Type::SaveFile;
|
2017-04-08 03:06:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-12-21 19:34:17 +00:00
|
|
|
dlg->setType(nativeType);
|
2015-03-02 19:07:35 +00:00
|
|
|
|
2018-02-21 13:39:30 +00:00
|
|
|
for (const auto& ext : extensions)
|
|
|
|
dlg->addFilter(ext, ext + " files (*." + ext + ")");
|
2015-03-02 19:07:35 +00:00
|
|
|
|
2018-02-23 13:32:02 +00:00
|
|
|
if (!defExtension.empty())
|
|
|
|
dlg->setDefaultExtension(defExtension);
|
|
|
|
|
2020-07-07 22:06:48 +00:00
|
|
|
bool res = dlg->show(os::instance()->defaultWindow());
|
2017-04-08 03:06:25 +00:00
|
|
|
if (res) {
|
|
|
|
if (type == FileSelectorType::OpenMultiple)
|
|
|
|
dlg->getMultipleFileNames(output);
|
|
|
|
else
|
|
|
|
output.push_back(dlg->fileName());
|
|
|
|
}
|
2015-03-02 19:07:35 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 23:34:01 +00:00
|
|
|
FileSelector fileSelector(type);
|
2018-02-23 13:32:02 +00:00
|
|
|
|
|
|
|
if (!defExtension.empty())
|
|
|
|
fileSelector.setDefaultExtension(defExtension);
|
|
|
|
|
2018-02-21 13:39:30 +00:00
|
|
|
return fileSelector.show(title, initialPath, extensions, output);
|
2012-06-16 02:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace app
|