From 36209ddd90a1a54534eee88ef2d98da4758bcc77 Mon Sep 17 00:00:00 2001 From: Tan Wang Leng Date: Thu, 2 Feb 2017 00:01:01 +0800 Subject: [PATCH] :apple: Add additional options for Mac's open dialog Support an additional attributes available in macOS's NSOpenPanel: message. --- atom/browser/api/atom_api_dialog.cc | 5 +++-- atom/browser/common_web_contents_delegate.cc | 2 +- atom/browser/ui/file_dialog.h | 2 ++ atom/browser/ui/file_dialog_gtk.cc | 2 ++ atom/browser/ui/file_dialog_mac.mm | 12 ++++++++---- atom/browser/ui/file_dialog_win.cc | 2 ++ atom/browser/web_dialog_helper.cc | 1 + lib/browser/api/dialog.js | 12 ++++++++++-- 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 1efb78d72d24..d99480712d5e 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -71,6 +71,7 @@ void ShowOpenDialog(const std::string& title, const base::FilePath& default_path, const file_dialog::Filters& filters, int properties, + const std::string& message, atom::NativeWindow* window, mate::Arguments* args) { v8::Local peek = args->PeekNext(); @@ -79,11 +80,11 @@ void ShowOpenDialog(const std::string& title, peek, &callback)) { file_dialog::ShowOpenDialog(window, title, button_label, default_path, - filters, properties, callback); + filters, properties, message, callback); } else { std::vector paths; if (file_dialog::ShowOpenDialog(window, title, button_label, default_path, - filters, properties, &paths)) + filters, properties, message, &paths)) args->Return(paths); } } diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index c3cca231c31c..5b3961464cd3 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -363,7 +363,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem( std::vector paths; int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY; if (!file_dialog::ShowOpenDialog(owner_window(), "", "", default_path, - filters, flag, &paths)) + filters, flag, "", &paths)) return; path = paths[0]; diff --git a/atom/browser/ui/file_dialog.h b/atom/browser/ui/file_dialog.h index 8b2d7f0d99e3..4759e503b2af 100644 --- a/atom/browser/ui/file_dialog.h +++ b/atom/browser/ui/file_dialog.h @@ -43,6 +43,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, std::vector* paths); void ShowOpenDialog(atom::NativeWindow* parent_window, @@ -51,6 +52,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, const OpenDialogCallback& callback); bool ShowSaveDialog(atom::NativeWindow* parent_window, diff --git a/atom/browser/ui/file_dialog_gtk.cc b/atom/browser/ui/file_dialog_gtk.cc index c39281d8f6e0..db79ceb171b8 100644 --- a/atom/browser/ui/file_dialog_gtk.cc +++ b/atom/browser/ui/file_dialog_gtk.cc @@ -236,6 +236,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, std::vector* paths) { GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; if (properties & FILE_DIALOG_OPEN_DIRECTORY) @@ -260,6 +261,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, const OpenDialogCallback& callback) { GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; if (properties & FILE_DIALOG_OPEN_DIRECTORY) diff --git a/atom/browser/ui/file_dialog_mac.mm b/atom/browser/ui/file_dialog_mac.mm index ee07d2af0041..8c88531bd1a9 100644 --- a/atom/browser/ui/file_dialog_mac.mm +++ b/atom/browser/ui/file_dialog_mac.mm @@ -134,12 +134,14 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, std::vector* paths) { DCHECK(paths); NSOpenPanel* dialog = [NSOpenPanel openPanel]; -// TODO yamgent: Fix this - SetupDialog(dialog, title, button_label, default_path, filters, "", "", false); + SetupDialog(dialog, title, button_label, default_path, filters, message, + // NSOpenPanel does not support name_field_label and shows_tag_field + "", false); SetupDialogForProperties(dialog, properties); int chosen = RunModalDialog(dialog, parent_window); @@ -156,11 +158,13 @@ void ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, const OpenDialogCallback& c) { NSOpenPanel* dialog = [NSOpenPanel openPanel]; -// TODO yamgent: Fix this - SetupDialog(dialog, title, button_label, default_path, filters, "", "", false); + SetupDialog(dialog, title, button_label, default_path, filters, message, + // NSOpenPanel does not support name_field_label and shows_tag_field + "", false); SetupDialogForProperties(dialog, properties); // Duplicate the callback object here since c is a reference and gcd would diff --git a/atom/browser/ui/file_dialog_win.cc b/atom/browser/ui/file_dialog_win.cc index 2c8017562488..dc28acb34889 100644 --- a/atom/browser/ui/file_dialog_win.cc +++ b/atom/browser/ui/file_dialog_win.cc @@ -198,6 +198,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, std::vector* paths) { int options = FOS_FORCEFILESYSTEM | FOS_FILEMUSTEXIST; if (properties & FILE_DIALOG_OPEN_DIRECTORY) @@ -250,6 +251,7 @@ void ShowOpenDialog(atom::NativeWindow* parent, const base::FilePath& default_path, const Filters& filters, int properties, + const std::string& message, const OpenDialogCallback& callback) { RunState run_state; if (!CreateDialogThread(&run_state)) { diff --git a/atom/browser/web_dialog_helper.cc b/atom/browser/web_dialog_helper.cc index e5bd46672fd8..0e28b07525b1 100644 --- a/atom/browser/web_dialog_helper.cc +++ b/atom/browser/web_dialog_helper.cc @@ -125,6 +125,7 @@ void WebDialogHelper::RunFileChooser( default_file_path, filters, flags, + "", &paths)) { for (auto& path : paths) { content::FileChooserFileInfo info; diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index 4088431c1518..73a519cc20b1 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -81,7 +81,8 @@ module.exports = { } } - let {buttonLabel, defaultPath, filters, properties, title} = options + let {buttonLabel, defaultPath, filters, properties, title, + message} = options if (properties == null) { properties = ['openFile'] @@ -118,11 +119,18 @@ module.exports = { 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) { return callback(success ? result : void 0) } : null return binding.showOpenDialog(title, buttonLabel, defaultPath, filters, - dialogProperties, window, wrappedCallback) + dialogProperties, message, window, + wrappedCallback) }, showSaveDialog: function (...args) {