🍎 Add additional options for Mac's open dialog
Support an additional attributes available in macOS's NSOpenPanel: message.
This commit is contained in:
parent
cc22149beb
commit
36209ddd90
8 changed files with 29 additions and 9 deletions
|
@ -71,6 +71,7 @@ void ShowOpenDialog(const std::string& title,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const file_dialog::Filters& filters,
|
const file_dialog::Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
atom::NativeWindow* window,
|
atom::NativeWindow* window,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
v8::Local<v8::Value> peek = args->PeekNext();
|
v8::Local<v8::Value> peek = args->PeekNext();
|
||||||
|
@ -79,11 +80,11 @@ void ShowOpenDialog(const std::string& title,
|
||||||
peek,
|
peek,
|
||||||
&callback)) {
|
&callback)) {
|
||||||
file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
||||||
filters, properties, callback);
|
filters, properties, message, callback);
|
||||||
} else {
|
} else {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
if (file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
if (file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
||||||
filters, properties, &paths))
|
filters, properties, message, &paths))
|
||||||
args->Return(paths);
|
args->Return(paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,7 +363,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem(
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
|
int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
|
||||||
if (!file_dialog::ShowOpenDialog(owner_window(), "", "", default_path,
|
if (!file_dialog::ShowOpenDialog(owner_window(), "", "", default_path,
|
||||||
filters, flag, &paths))
|
filters, flag, "", &paths))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path = paths[0];
|
path = paths[0];
|
||||||
|
|
|
@ -43,6 +43,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
std::vector<base::FilePath>* paths);
|
std::vector<base::FilePath>* paths);
|
||||||
|
|
||||||
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
@ -51,6 +52,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
const OpenDialogCallback& callback);
|
const OpenDialogCallback& callback);
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
|
@ -236,6 +236,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
std::vector<base::FilePath>* paths) {
|
std::vector<base::FilePath>* paths) {
|
||||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
||||||
|
@ -260,6 +261,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
const OpenDialogCallback& callback) {
|
const OpenDialogCallback& callback) {
|
||||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
||||||
|
|
|
@ -134,12 +134,14 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
std::vector<base::FilePath>* paths) {
|
std::vector<base::FilePath>* paths) {
|
||||||
DCHECK(paths);
|
DCHECK(paths);
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
// TODO yamgent: Fix this
|
SetupDialog(dialog, title, button_label, default_path, filters, message,
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters, "", "", false);
|
// NSOpenPanel does not support name_field_label and shows_tag_field
|
||||||
|
"", false);
|
||||||
SetupDialogForProperties(dialog, properties);
|
SetupDialogForProperties(dialog, properties);
|
||||||
|
|
||||||
int chosen = RunModalDialog(dialog, parent_window);
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
|
@ -156,11 +158,13 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
const OpenDialogCallback& c) {
|
const OpenDialogCallback& c) {
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
// TODO yamgent: Fix this
|
SetupDialog(dialog, title, button_label, default_path, filters, message,
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters, "", "", false);
|
// NSOpenPanel does not support name_field_label and shows_tag_field
|
||||||
|
"", false);
|
||||||
SetupDialogForProperties(dialog, properties);
|
SetupDialogForProperties(dialog, properties);
|
||||||
|
|
||||||
// Duplicate the callback object here since c is a reference and gcd would
|
// Duplicate the callback object here since c is a reference and gcd would
|
||||||
|
|
|
@ -198,6 +198,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
std::vector<base::FilePath>* paths) {
|
std::vector<base::FilePath>* paths) {
|
||||||
int options = FOS_FORCEFILESYSTEM | FOS_FILEMUSTEXIST;
|
int options = FOS_FORCEFILESYSTEM | FOS_FILEMUSTEXIST;
|
||||||
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
||||||
|
@ -250,6 +251,7 @@ void ShowOpenDialog(atom::NativeWindow* parent,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
const std::string& message,
|
||||||
const OpenDialogCallback& callback) {
|
const OpenDialogCallback& callback) {
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
|
|
|
@ -125,6 +125,7 @@ void WebDialogHelper::RunFileChooser(
|
||||||
default_file_path,
|
default_file_path,
|
||||||
filters,
|
filters,
|
||||||
flags,
|
flags,
|
||||||
|
"",
|
||||||
&paths)) {
|
&paths)) {
|
||||||
for (auto& path : paths) {
|
for (auto& path : paths) {
|
||||||
content::FileChooserFileInfo info;
|
content::FileChooserFileInfo info;
|
||||||
|
|
|
@ -81,7 +81,8 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let {buttonLabel, defaultPath, filters, properties, title} = options
|
let {buttonLabel, defaultPath, filters, properties, title,
|
||||||
|
message} = options
|
||||||
|
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
properties = ['openFile']
|
properties = ['openFile']
|
||||||
|
@ -118,11 +119,18 @@ module.exports = {
|
||||||
filters = []
|
filters = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message == null) {
|
||||||
|
message = ''
|
||||||
|
} else if (typeof message !== 'string') {
|
||||||
|
throw new TypeError('Message must be a string')
|
||||||
|
}
|
||||||
|
|
||||||
const wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
const wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
||||||
return callback(success ? result : void 0)
|
return callback(success ? result : void 0)
|
||||||
} : null
|
} : null
|
||||||
return binding.showOpenDialog(title, buttonLabel, defaultPath, filters,
|
return binding.showOpenDialog(title, buttonLabel, defaultPath, filters,
|
||||||
dialogProperties, window, wrappedCallback)
|
dialogProperties, message, window,
|
||||||
|
wrappedCallback)
|
||||||
},
|
},
|
||||||
|
|
||||||
showSaveDialog: function (...args) {
|
showSaveDialog: function (...args) {
|
||||||
|
|
Loading…
Reference in a new issue