forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_selector.cpp
More file actions
63 lines (50 loc) · 1.55 KB
/
file_selector.cpp
File metadata and controls
63 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/file_selector.h"
#include "app/app.h"
#include "app/pref/preferences.h"
#include "app/ui/file_selector.h"
#include "base/split_string.h"
#include "she/display.h"
#include "she/native_dialogs.h"
#include "she/system.h"
namespace app {
std::string show_file_selector(
const std::string& title,
const std::string& initialPath,
const std::string& showExtensions,
FileSelectorType type,
FileSelectorDelegate* delegate)
{
if (Preferences::instance().experimental.useNativeFileDialog() &&
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)
dlg->addFilter(tok, tok + " files (*." + tok + ")");
if (dlg->show(she::instance()->defaultDisplay()))
res = dlg->fileName();
dlg->dispose();
return res;
}
}
FileSelector fileSelector(type, delegate);
return fileSelector.show(title, initialPath, showExtensions);
}
} // namespace app