-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFileExecuteCallback.cpp
89 lines (71 loc) · 2.78 KB
/
FileExecuteCallback.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "FileExecuteCallback"
#include "ExecuteCallback"
#include "BrowserClient"
using namespace osgEarth::Cef;
#define LC "[FileExecuteCallback] "
namespace
{
class LocalFileDialogCallback : public CefRunFileDialogCallback
{
public:
LocalFileDialogCallback(CefRefPtr<CefMessageRouterBrowserSide::Callback> callback) : _browserCallback(callback) { }
void OnFileDialogDismissed(int selected_accept_filter, const std::vector<CefString>& file_paths)
{
if (_browserCallback)
{
if (file_paths.size() == 0)
{
_browserCallback->Failure(-1, "");
}
else
{
std::string s = "";
for (int i=0; i < file_paths.size(); i++)
s.append(file_paths[i].ToString() + (i < file_paths.size() - 1 ? "," : ""));
_browserCallback->Success(s);
}
}
}
protected:
CefRefPtr<CefMessageRouterBrowserSide::Callback> _browserCallback;
IMPLEMENT_REFCOUNTING(LocalFileDialogCallback);
DISALLOW_COPY_AND_ASSIGN(LocalFileDialogCallback);
};
}
ExecuteCallback::ReturnVal* FileExecuteCallback::execute( int64 query_id, const std::string& command, const JsonArguments &args, bool persistent, CefRefPtr<CefMessageRouterBrowserSide::Callback> callback )
{
if (command == "_OE_open_file_dialog" || command == "_OE_open_multifile_dialog" || command == "_OE_open_folder_dialog")
{
bool multiple = command == "_OE_open_multifile_dialog";
bool folder = command == "_OE_open_folder_dialog";
CefString path = args["path"];
std::vector<CefString> filters;
std::string filterString = args["filters"];
while (filterString.length() > 0)
{
std::string::size_type pos = filterString.find_first_of(", ");
if (pos == std::string::npos)
{
filters.push_back(filterString);
filterString = "";
}
else
{
if (pos > 0)
{
filters.push_back(filterString.substr(0, pos));
}
filterString = filterString.substr(pos + 1);
}
}
_client->getBrowser()->GetHost()->RunFileDialog(
(multiple ? CefBrowserHost::FileDialogMode::FILE_DIALOG_OPEN_MULTIPLE : folder ? CefBrowserHost::FileDialogMode::FILE_DIALOG_OPEN_FOLDER : CefBrowserHost::FileDialogMode::FILE_DIALOG_OPEN),
"", // title
path, // default_file_path
filters, // accept_filters
0, // selected_accept_filter
new LocalFileDialogCallback(callback));
return new ReturnVal(true);
}
return 0L;
}