🍎 Add additional options for Mac's save dialog
Support additional attributes available in macOS's NSSavePanel: message, nameFieldLabel and showsTagField
This commit is contained in:
parent
9163b601a4
commit
1d612a12a1
9 changed files with 72 additions and 9 deletions
|
@ -92,6 +92,9 @@ void ShowSaveDialog(const std::string& title,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const file_dialog::Filters& filters,
|
const file_dialog::Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
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();
|
||||||
|
@ -100,11 +103,13 @@ void ShowSaveDialog(const std::string& title,
|
||||||
peek,
|
peek,
|
||||||
&callback)) {
|
&callback)) {
|
||||||
file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
||||||
filters, callback);
|
filters, message, name_field_label,
|
||||||
|
shows_tag_field, callback);
|
||||||
} else {
|
} else {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
if (file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
||||||
filters, &path))
|
filters, message, name_field_label,
|
||||||
|
shows_tag_field, &path))
|
||||||
args->Return(path);
|
args->Return(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
if (path.empty() && file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
if (path.empty() && file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
||||||
"", default_path,
|
"", default_path,
|
||||||
file_dialog::Filters(),
|
file_dialog::Filters(),
|
||||||
|
"", "", false,
|
||||||
&path)) {
|
&path)) {
|
||||||
// Remember the last selected download directory.
|
// Remember the last selected download directory.
|
||||||
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
||||||
|
|
|
@ -297,7 +297,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile(
|
||||||
file_dialog::Filters filters;
|
file_dialog::Filters filters;
|
||||||
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
|
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
|
||||||
if (!file_dialog::ShowSaveDialog(owner_window(), url, "", default_path,
|
if (!file_dialog::ShowSaveDialog(owner_window(), url, "", default_path,
|
||||||
filters, &path)) {
|
filters, "", "", false, &path)) {
|
||||||
base::StringValue url_value(url);
|
base::StringValue url_value(url);
|
||||||
web_contents_->CallClientFunction(
|
web_contents_->CallClientFunction(
|
||||||
"DevToolsAPI.canceledSaveURL", &url_value, nullptr, nullptr);
|
"DevToolsAPI.canceledSaveURL", &url_value, nullptr, nullptr);
|
||||||
|
|
|
@ -58,6 +58,9 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
base::FilePath* path);
|
base::FilePath* path);
|
||||||
|
|
||||||
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
@ -65,6 +68,9 @@ void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
const SaveDialogCallback& callback);
|
const SaveDialogCallback& callback);
|
||||||
|
|
||||||
} // namespace file_dialog
|
} // namespace file_dialog
|
||||||
|
|
|
@ -275,6 +275,9 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
base::FilePath* path) {
|
base::FilePath* path) {
|
||||||
FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, parent_window,
|
FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, parent_window,
|
||||||
title, button_label, default_path, filters);
|
title, button_label, default_path, filters);
|
||||||
|
|
|
@ -47,13 +47,24 @@ void SetupDialog(NSSavePanel* dialog,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters) {
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field) {
|
||||||
if (!title.empty())
|
if (!title.empty())
|
||||||
[dialog setTitle:base::SysUTF8ToNSString(title)];
|
[dialog setTitle:base::SysUTF8ToNSString(title)];
|
||||||
|
|
||||||
if (!button_label.empty())
|
if (!button_label.empty())
|
||||||
[dialog setPrompt:base::SysUTF8ToNSString(button_label)];
|
[dialog setPrompt:base::SysUTF8ToNSString(button_label)];
|
||||||
|
|
||||||
|
if (!message.empty())
|
||||||
|
[dialog setMessage:base::SysUTF8ToNSString(message)];
|
||||||
|
|
||||||
|
if (!name_field_label.empty())
|
||||||
|
[dialog setNameFieldLabel:base::SysUTF8ToNSString(name_field_label)];
|
||||||
|
|
||||||
|
[dialog setShowsTagField:shows_tag_field];
|
||||||
|
|
||||||
NSString* default_dir = nil;
|
NSString* default_dir = nil;
|
||||||
NSString* default_filename = nil;
|
NSString* default_filename = nil;
|
||||||
if (!default_path.empty()) {
|
if (!default_path.empty()) {
|
||||||
|
@ -127,7 +138,8 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
DCHECK(paths);
|
DCHECK(paths);
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters);
|
// TODO yamgent: Fix this
|
||||||
|
SetupDialog(dialog, title, button_label, default_path, filters, "", "", false);
|
||||||
SetupDialogForProperties(dialog, properties);
|
SetupDialogForProperties(dialog, properties);
|
||||||
|
|
||||||
int chosen = RunModalDialog(dialog, parent_window);
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
|
@ -147,7 +159,8 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const OpenDialogCallback& c) {
|
const OpenDialogCallback& c) {
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters);
|
// TODO yamgent: Fix this
|
||||||
|
SetupDialog(dialog, title, button_label, default_path, filters, "", "", 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
|
||||||
|
@ -172,11 +185,15 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
base::FilePath* path) {
|
base::FilePath* path) {
|
||||||
DCHECK(path);
|
DCHECK(path);
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters, message,
|
||||||
|
name_field_label, shows_tag_field);
|
||||||
|
|
||||||
int chosen = RunModalDialog(dialog, parent_window);
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
||||||
|
@ -191,10 +208,14 @@ void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
const SaveDialogCallback& c) {
|
const SaveDialogCallback& c) {
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, button_label, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters, message,
|
||||||
|
name_field_label, shows_tag_field);
|
||||||
[dialog setCanSelectHiddenExtension:YES];
|
[dialog setCanSelectHiddenExtension:YES];
|
||||||
|
|
||||||
__block SaveDialogCallback callback = c;
|
__block SaveDialogCallback callback = c;
|
||||||
|
|
|
@ -268,6 +268,9 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
base::FilePath* path) {
|
base::FilePath* path) {
|
||||||
FileDialog<CShellFileSaveDialog> save_dialog(
|
FileDialog<CShellFileSaveDialog> save_dialog(
|
||||||
default_path, title, button_label, filters,
|
default_path, title, button_label, filters,
|
||||||
|
@ -289,6 +292,9 @@ void ShowSaveDialog(atom::NativeWindow* parent,
|
||||||
const std::string& button_label,
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& name_field_label,
|
||||||
|
const bool& shows_tag_field,
|
||||||
const SaveDialogCallback& callback) {
|
const SaveDialogCallback& callback) {
|
||||||
RunState run_state;
|
RunState run_state;
|
||||||
if (!CreateDialogThread(&run_state)) {
|
if (!CreateDialogThread(&run_state)) {
|
||||||
|
|
|
@ -90,6 +90,9 @@ void WebDialogHelper::RunFileChooser(
|
||||||
"",
|
"",
|
||||||
params.default_file_name,
|
params.default_file_name,
|
||||||
filters,
|
filters,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
false,
|
||||||
&path)) {
|
&path)) {
|
||||||
content::FileChooserFileInfo info;
|
content::FileChooserFileInfo info;
|
||||||
info.file_path = path;
|
info.file_path = path;
|
||||||
|
|
|
@ -136,7 +136,8 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let {buttonLabel, defaultPath, filters, title} = options
|
let {buttonLabel, defaultPath, filters, title, message, nameFieldLabel,
|
||||||
|
showsTagField} = options
|
||||||
|
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = ''
|
title = ''
|
||||||
|
@ -160,10 +161,27 @@ module.exports = {
|
||||||
filters = []
|
filters = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message == null) {
|
||||||
|
message = ''
|
||||||
|
} else if (typeof message !== 'string') {
|
||||||
|
throw new TypeError('Message must be a string')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameFieldLabel == null) {
|
||||||
|
nameFieldLabel = ''
|
||||||
|
} else if (typeof nameFieldLabel !== 'string') {
|
||||||
|
throw new TypeError('Name field label must be a string')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showsTagField == null) {
|
||||||
|
showsTagField = false
|
||||||
|
}
|
||||||
|
|
||||||
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.showSaveDialog(title, buttonLabel, defaultPath, filters,
|
return binding.showSaveDialog(title, buttonLabel, defaultPath, filters,
|
||||||
|
message, nameFieldLabel, showsTagField,
|
||||||
window, wrappedCallback)
|
window, wrappedCallback)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue