2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
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"
|
2015-03-02 19:07:35 +00:00
|
|
|
#include "base/split_string.h"
|
|
|
|
#include "she/display.h"
|
|
|
|
#include "she/native_dialogs.h"
|
|
|
|
#include "she/system.h"
|
2012-06-16 02:37:59 +00:00
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
2014-04-20 22:53:27 +00:00
|
|
|
std::string show_file_selector(const std::string& title,
|
|
|
|
const std::string& initialPath,
|
2015-03-02 19:07:35 +00:00
|
|
|
const std::string& showExtensions,
|
|
|
|
FileSelectorType type)
|
2012-06-16 02:37:59 +00:00
|
|
|
{
|
2015-05-18 19:53:25 +00:00
|
|
|
if (Preferences::instance().experimental.useNativeFileDialog() &&
|
2015-03-02 19:07:35 +00:00
|
|
|
she::instance()->nativeDialogs()) {
|
|
|
|
she::FileDialog* dlg =
|
|
|
|
she::instance()->nativeDialogs()->createFileDialog();
|
|
|
|
|
|
|
|
if (dlg) {
|
|
|
|
std::string res;
|
|
|
|
|
|
|
|
dlg->setTitle(title);
|
|
|
|
dlg->setFileName(initialPath);
|
|
|
|
|
|
|
|
if (type == FileSelectorType::Save)
|
|
|
|
dlg->toSaveFile();
|
|
|
|
else
|
|
|
|
dlg->toOpenFile();
|
|
|
|
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
base::split_string(showExtensions, tokens, ",");
|
|
|
|
for (const auto& tok : tokens)
|
2015-05-28 19:29:01 +00:00
|
|
|
dlg->addFilter(tok, tok + " files (*." + tok + ")");
|
2015-03-02 19:07:35 +00:00
|
|
|
|
2015-05-28 19:13:07 +00:00
|
|
|
if (dlg->show(she::instance()->defaultDisplay()))
|
2015-03-02 19:07:35 +00:00
|
|
|
res = dlg->getFileName();
|
2015-05-21 13:52:58 +00:00
|
|
|
|
|
|
|
dlg->dispose();
|
2015-03-02 19:07:35 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
FileSelector fileSelector;
|
2015-05-28 19:11:06 +00:00
|
|
|
return fileSelector.show(
|
|
|
|
title, initialPath, showExtensions,
|
|
|
|
(type == FileSelectorType::Open ? FileSelector::Open:
|
|
|
|
FileSelector::Save));
|
2012-06-16 02:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace app
|