Merge pull request #5509 from electron/bengotow/dialog-titles
Add buttonLabel param to showOpen/showSave dialogs
This commit is contained in:
commit
57f082055a
10 changed files with 83 additions and 31 deletions
|
@ -67,6 +67,7 @@ void ShowMessageBox(int type,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowOpenDialog(const std::string& title,
|
void ShowOpenDialog(const std::string& title,
|
||||||
|
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,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -77,17 +78,18 @@ void ShowOpenDialog(const std::string& title,
|
||||||
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
|
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
|
||||||
peek,
|
peek,
|
||||||
&callback)) {
|
&callback)) {
|
||||||
file_dialog::ShowOpenDialog(window, title, default_path, filters,
|
file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
||||||
properties, callback);
|
filters, properties, callback);
|
||||||
} else {
|
} else {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
if (file_dialog::ShowOpenDialog(window, title, default_path, filters,
|
if (file_dialog::ShowOpenDialog(window, title, button_label, default_path,
|
||||||
properties, &paths))
|
filters, properties, &paths))
|
||||||
args->Return(paths);
|
args->Return(paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const std::string& title,
|
void ShowSaveDialog(const std::string& title,
|
||||||
|
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,
|
||||||
atom::NativeWindow* window,
|
atom::NativeWindow* window,
|
||||||
|
@ -97,11 +99,12 @@ void ShowSaveDialog(const std::string& title,
|
||||||
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
|
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
|
||||||
peek,
|
peek,
|
||||||
&callback)) {
|
&callback)) {
|
||||||
file_dialog::ShowSaveDialog(window, title, default_path, filters, callback);
|
file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
||||||
|
filters, callback);
|
||||||
} else {
|
} else {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (file_dialog::ShowSaveDialog(window, title, default_path, filters,
|
if (file_dialog::ShowSaveDialog(window, title, button_label, default_path,
|
||||||
&path))
|
filters, &path))
|
||||||
args->Return(path);
|
args->Return(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,8 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
window = relay->window.get();
|
window = relay->window.get();
|
||||||
|
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(), default_path,
|
if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
||||||
|
"", default_path,
|
||||||
file_dialog::Filters(), &path)) {
|
file_dialog::Filters(), &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*>(
|
||||||
|
|
|
@ -389,7 +389,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile(
|
||||||
} else {
|
} else {
|
||||||
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, &path)) {
|
||||||
base::StringValue url_value(url);
|
base::StringValue url_value(url);
|
||||||
web_contents_->CallClientFunction(
|
web_contents_->CallClientFunction(
|
||||||
|
@ -455,7 +455,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem(
|
||||||
base::FilePath default_path;
|
base::FilePath default_path;
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef base::Callback<void(
|
||||||
|
|
||||||
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -44,6 +45,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -51,12 +53,14 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
base::FilePath* path);
|
base::FilePath* path);
|
||||||
|
|
||||||
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& callback);
|
const SaveDialogCallback& callback);
|
||||||
|
|
|
@ -37,12 +37,16 @@ class FileChooserDialog {
|
||||||
FileChooserDialog(GtkFileChooserAction action,
|
FileChooserDialog(GtkFileChooserAction action,
|
||||||
atom::NativeWindow* parent_window,
|
atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters)
|
const Filters& filters)
|
||||||
: dialog_scope_(parent_window),
|
: dialog_scope_(parent_window),
|
||||||
filters_(filters) {
|
filters_(filters) {
|
||||||
const char* confirm_text = GTK_STOCK_OK;
|
const char* confirm_text = GTK_STOCK_OK;
|
||||||
if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
|
||||||
|
if (!button_label.empty())
|
||||||
|
confirm_text = button_label.c_str();
|
||||||
|
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
||||||
confirm_text = GTK_STOCK_SAVE;
|
confirm_text = GTK_STOCK_SAVE;
|
||||||
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||||
confirm_text = GTK_STOCK_OPEN;
|
confirm_text = GTK_STOCK_OPEN;
|
||||||
|
@ -216,6 +220,7 @@ base::FilePath FileChooserDialog::AddExtensionForFilename(
|
||||||
|
|
||||||
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -223,8 +228,8 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
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)
|
||||||
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||||
FileChooserDialog open_dialog(action, parent_window, title, default_path,
|
FileChooserDialog open_dialog(action, parent_window, title, button_label,
|
||||||
filters);
|
default_path, filters);
|
||||||
if (properties & FILE_DIALOG_MULTI_SELECTIONS)
|
if (properties & FILE_DIALOG_MULTI_SELECTIONS)
|
||||||
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(open_dialog.dialog()),
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(open_dialog.dialog()),
|
||||||
TRUE);
|
TRUE);
|
||||||
|
@ -241,6 +246,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -249,7 +255,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
if (properties & FILE_DIALOG_OPEN_DIRECTORY)
|
||||||
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||||
FileChooserDialog* open_dialog = new FileChooserDialog(
|
FileChooserDialog* open_dialog = new FileChooserDialog(
|
||||||
action, parent_window, title, default_path, filters);
|
action, parent_window, title, button_label, default_path, filters);
|
||||||
if (properties & FILE_DIALOG_MULTI_SELECTIONS)
|
if (properties & FILE_DIALOG_MULTI_SELECTIONS)
|
||||||
gtk_file_chooser_set_select_multiple(
|
gtk_file_chooser_set_select_multiple(
|
||||||
GTK_FILE_CHOOSER(open_dialog->dialog()), TRUE);
|
GTK_FILE_CHOOSER(open_dialog->dialog()), TRUE);
|
||||||
|
@ -259,11 +265,12 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
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, default_path, filters);
|
title, button_label, default_path, filters);
|
||||||
gtk_widget_show_all(save_dialog.dialog());
|
gtk_widget_show_all(save_dialog.dialog());
|
||||||
int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog()));
|
int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog()));
|
||||||
if (response == GTK_RESPONSE_ACCEPT) {
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
|
@ -276,12 +283,13 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& callback) {
|
const SaveDialogCallback& callback) {
|
||||||
FileChooserDialog* save_dialog = new FileChooserDialog(
|
FileChooserDialog* save_dialog = new FileChooserDialog(
|
||||||
GTK_FILE_CHOOSER_ACTION_SAVE, parent_window, title, default_path,
|
GTK_FILE_CHOOSER_ACTION_SAVE, parent_window, title, button_label,
|
||||||
filters);
|
default_path, filters);
|
||||||
save_dialog->RunSaveAsynchronous(callback);
|
save_dialog->RunSaveAsynchronous(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,15 @@ void SetAllowedFileTypes(NSSavePanel* dialog, const Filters& filters) {
|
||||||
|
|
||||||
void SetupDialog(NSSavePanel* dialog,
|
void SetupDialog(NSSavePanel* dialog,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters) {
|
const Filters& filters) {
|
||||||
if (!title.empty())
|
if (!title.empty())
|
||||||
[dialog setTitle:base::SysUTF8ToNSString(title)];
|
[dialog setTitle:base::SysUTF8ToNSString(title)];
|
||||||
|
|
||||||
|
if (!button_label.empty())
|
||||||
|
[dialog setPrompt:base::SysUTF8ToNSString(button_label)];
|
||||||
|
|
||||||
NSString* default_dir = nil;
|
NSString* default_dir = nil;
|
||||||
NSString* default_filename = nil;
|
NSString* default_filename = nil;
|
||||||
if (!default_path.empty()) {
|
if (!default_path.empty()) {
|
||||||
|
@ -114,6 +118,7 @@ void ReadDialogPaths(NSOpenPanel* dialog, std::vector<base::FilePath>* paths) {
|
||||||
|
|
||||||
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -121,7 +126,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
DCHECK(paths);
|
DCHECK(paths);
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters);
|
||||||
SetupDialogForProperties(dialog, properties);
|
SetupDialogForProperties(dialog, properties);
|
||||||
|
|
||||||
int chosen = RunModalDialog(dialog, parent_window);
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
|
@ -134,13 +139,14 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
const OpenDialogCallback& c) {
|
const OpenDialogCallback& c) {
|
||||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters);
|
||||||
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
|
||||||
|
@ -162,13 +168,14 @@ void ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
base::FilePath* path) {
|
base::FilePath* path) {
|
||||||
DCHECK(path);
|
DCHECK(path);
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters);
|
||||||
|
|
||||||
int chosen = RunModalDialog(dialog, parent_window);
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
||||||
|
@ -180,12 +187,13 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
void ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& c) {
|
const SaveDialogCallback& c) {
|
||||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||||
|
|
||||||
SetupDialog(dialog, title, default_path, filters);
|
SetupDialog(dialog, title, button_label, default_path, filters);
|
||||||
|
|
||||||
__block SaveDialogCallback callback = c;
|
__block SaveDialogCallback callback = c;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,9 @@ void ConvertFilters(const Filters& filters,
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FileDialog {
|
class FileDialog {
|
||||||
public:
|
public:
|
||||||
FileDialog(const base::FilePath& default_path, const std::string& title,
|
FileDialog(const base::FilePath& default_path,
|
||||||
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const Filters& filters, int options) {
|
const Filters& filters, int options) {
|
||||||
std::wstring file_part;
|
std::wstring file_part;
|
||||||
if (!IsDirectory(default_path))
|
if (!IsDirectory(default_path))
|
||||||
|
@ -79,6 +81,9 @@ class FileDialog {
|
||||||
if (!title.empty())
|
if (!title.empty())
|
||||||
GetPtr()->SetTitle(base::UTF8ToUTF16(title).c_str());
|
GetPtr()->SetTitle(base::UTF8ToUTF16(title).c_str());
|
||||||
|
|
||||||
|
if (!button_label.empty())
|
||||||
|
GetPtr()->SetOkButtonLabel(base::UTF8ToUTF16(button_label).c_str());
|
||||||
|
|
||||||
// By default, *.* will be added to the file name if file type is "*.*". In
|
// By default, *.* will be added to the file name if file type is "*.*". In
|
||||||
// Electron, we disable it to make a better experience.
|
// Electron, we disable it to make a better experience.
|
||||||
//
|
//
|
||||||
|
@ -154,13 +159,14 @@ bool CreateDialogThread(RunState* run_state) {
|
||||||
void RunOpenDialogInNewThread(const RunState& run_state,
|
void RunOpenDialogInNewThread(const RunState& run_state,
|
||||||
atom::NativeWindow* parent,
|
atom::NativeWindow* parent,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
const OpenDialogCallback& callback) {
|
const OpenDialogCallback& callback) {
|
||||||
std::vector<base::FilePath> paths;
|
std::vector<base::FilePath> paths;
|
||||||
bool result = ShowOpenDialog(parent, title, default_path, filters, properties,
|
bool result = ShowOpenDialog(parent, title, button_label, default_path,
|
||||||
&paths);
|
filters, properties, &paths);
|
||||||
run_state.ui_message_loop->PostTask(FROM_HERE,
|
run_state.ui_message_loop->PostTask(FROM_HERE,
|
||||||
base::Bind(callback, result, paths));
|
base::Bind(callback, result, paths));
|
||||||
run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
||||||
|
@ -169,11 +175,13 @@ void RunOpenDialogInNewThread(const RunState& run_state,
|
||||||
void RunSaveDialogInNewThread(const RunState& run_state,
|
void RunSaveDialogInNewThread(const RunState& run_state,
|
||||||
atom::NativeWindow* parent,
|
atom::NativeWindow* parent,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& callback) {
|
const SaveDialogCallback& callback) {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
bool result = ShowSaveDialog(parent, title, default_path, filters, &path);
|
bool result = ShowSaveDialog(parent, title, button_label, default_path,
|
||||||
|
filters, &path);
|
||||||
run_state.ui_message_loop->PostTask(FROM_HERE,
|
run_state.ui_message_loop->PostTask(FROM_HERE,
|
||||||
base::Bind(callback, result, path));
|
base::Bind(callback, result, path));
|
||||||
run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
|
||||||
|
@ -183,6 +191,7 @@ void RunSaveDialogInNewThread(const RunState& run_state,
|
||||||
|
|
||||||
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -194,7 +203,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
options |= FOS_ALLOWMULTISELECT;
|
options |= FOS_ALLOWMULTISELECT;
|
||||||
|
|
||||||
FileDialog<CShellFileOpenDialog> open_dialog(
|
FileDialog<CShellFileOpenDialog> open_dialog(
|
||||||
default_path, title, filters, options);
|
default_path, title, button_label, filters, options);
|
||||||
if (!open_dialog.Show(parent_window))
|
if (!open_dialog.Show(parent_window))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -230,6 +239,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowOpenDialog(atom::NativeWindow* parent,
|
void ShowOpenDialog(atom::NativeWindow* parent,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
|
@ -243,16 +253,17 @@ void ShowOpenDialog(atom::NativeWindow* parent,
|
||||||
run_state.dialog_thread->message_loop()->PostTask(
|
run_state.dialog_thread->message_loop()->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&RunOpenDialogInNewThread, run_state, parent, title,
|
base::Bind(&RunOpenDialogInNewThread, run_state, parent, title,
|
||||||
default_path, filters, properties, callback));
|
button_label, default_path, filters, properties, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
base::FilePath* path) {
|
base::FilePath* path) {
|
||||||
FileDialog<CShellFileSaveDialog> save_dialog(
|
FileDialog<CShellFileSaveDialog> save_dialog(
|
||||||
default_path, title, filters,
|
default_path, title, button_label, filters,
|
||||||
FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT);
|
FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT);
|
||||||
if (!save_dialog.Show(parent_window))
|
if (!save_dialog.Show(parent_window))
|
||||||
return false;
|
return false;
|
||||||
|
@ -268,6 +279,7 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
void ShowSaveDialog(atom::NativeWindow* parent,
|
void ShowSaveDialog(atom::NativeWindow* parent,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
const std::string& button_label,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& callback) {
|
const SaveDialogCallback& callback) {
|
||||||
|
@ -280,7 +292,7 @@ void ShowSaveDialog(atom::NativeWindow* parent,
|
||||||
run_state.dialog_thread->message_loop()->PostTask(
|
run_state.dialog_thread->message_loop()->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&RunSaveDialogInNewThread, run_state, parent, title,
|
base::Bind(&RunSaveDialogInNewThread, run_state, parent, title,
|
||||||
default_path, filters, callback));
|
button_label, default_path, filters, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace file_dialog
|
} // namespace file_dialog
|
||||||
|
|
|
@ -84,6 +84,7 @@ void WebDialogHelper::RunFileChooser(content::WebContents* web_contents,
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (file_dialog::ShowSaveDialog(window_,
|
if (file_dialog::ShowSaveDialog(window_,
|
||||||
base::UTF16ToUTF8(params.title),
|
base::UTF16ToUTF8(params.title),
|
||||||
|
"",
|
||||||
params.default_file_name,
|
params.default_file_name,
|
||||||
filters,
|
filters,
|
||||||
&path)) {
|
&path)) {
|
||||||
|
@ -114,6 +115,7 @@ void WebDialogHelper::RunFileChooser(content::WebContents* web_contents,
|
||||||
prefs::kSelectFileLastDirectory).Append(params.default_file_name);
|
prefs::kSelectFileLastDirectory).Append(params.default_file_name);
|
||||||
if (file_dialog::ShowOpenDialog(window_,
|
if (file_dialog::ShowOpenDialog(window_,
|
||||||
base::UTF16ToUTF8(params.title),
|
base::UTF16ToUTF8(params.title),
|
||||||
|
"",
|
||||||
default_file_path,
|
default_file_path,
|
||||||
filters,
|
filters,
|
||||||
flags,
|
flags,
|
||||||
|
|
|
@ -28,6 +28,8 @@ The `dialog` module has the following methods:
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `title` String
|
* `title` String
|
||||||
* `defaultPath` String
|
* `defaultPath` String
|
||||||
|
* `buttonLabel` String - Custom label for the confirmation button, when
|
||||||
|
left empty the default label will be used.
|
||||||
* `filters` Array
|
* `filters` Array
|
||||||
* `properties` Array - Contains which features the dialog should use, can
|
* `properties` Array - Contains which features the dialog should use, can
|
||||||
contain `openFile`, `openDirectory`, `multiSelections` and
|
contain `openFile`, `openDirectory`, `multiSelections` and
|
||||||
|
@ -69,6 +71,8 @@ shown.
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `title` String
|
* `title` String
|
||||||
* `defaultPath` String
|
* `defaultPath` String
|
||||||
|
* `buttonLabel` String - Custom label for the confirmation button, when
|
||||||
|
left empty the default label will be used.
|
||||||
* `filters` Array
|
* `filters` Array
|
||||||
* `callback` Function (optional)
|
* `callback` Function (optional)
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,11 @@ module.exports = {
|
||||||
} else if (typeof options.title !== 'string') {
|
} else if (typeof options.title !== 'string') {
|
||||||
throw new TypeError('Title must be a string')
|
throw new TypeError('Title must be a string')
|
||||||
}
|
}
|
||||||
|
if (options.buttonLabel == null) {
|
||||||
|
options.buttonLabel = ''
|
||||||
|
} else if (typeof options.buttonLabel !== 'string') {
|
||||||
|
throw new TypeError('buttonLabel must be a string')
|
||||||
|
}
|
||||||
if (options.defaultPath == null) {
|
if (options.defaultPath == null) {
|
||||||
options.defaultPath = ''
|
options.defaultPath = ''
|
||||||
} else if (typeof options.defaultPath !== 'string') {
|
} else if (typeof options.defaultPath !== 'string') {
|
||||||
|
@ -86,7 +91,7 @@ module.exports = {
|
||||||
wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
||||||
return callback(success ? result : void 0)
|
return callback(success ? result : void 0)
|
||||||
} : null
|
} : null
|
||||||
return binding.showOpenDialog(String(options.title), String(options.defaultPath), options.filters, properties, window, wrappedCallback)
|
return binding.showOpenDialog(options.title, options.buttonLabel, options.defaultPath, options.filters, properties, window, wrappedCallback)
|
||||||
},
|
},
|
||||||
|
|
||||||
showSaveDialog: function (...args) {
|
showSaveDialog: function (...args) {
|
||||||
|
@ -103,6 +108,11 @@ module.exports = {
|
||||||
} else if (typeof options.title !== 'string') {
|
} else if (typeof options.title !== 'string') {
|
||||||
throw new TypeError('Title must be a string')
|
throw new TypeError('Title must be a string')
|
||||||
}
|
}
|
||||||
|
if (options.buttonLabel == null) {
|
||||||
|
options.buttonLabel = ''
|
||||||
|
} else if (typeof options.buttonLabel !== 'string') {
|
||||||
|
throw new TypeError('buttonLabel must be a string')
|
||||||
|
}
|
||||||
if (options.defaultPath == null) {
|
if (options.defaultPath == null) {
|
||||||
options.defaultPath = ''
|
options.defaultPath = ''
|
||||||
} else if (typeof options.defaultPath !== 'string') {
|
} else if (typeof options.defaultPath !== 'string') {
|
||||||
|
@ -114,7 +124,7 @@ module.exports = {
|
||||||
wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
wrappedCallback = typeof callback === 'function' ? function (success, result) {
|
||||||
return callback(success ? result : void 0)
|
return callback(success ? result : void 0)
|
||||||
} : null
|
} : null
|
||||||
return binding.showSaveDialog(String(options.title), String(options.defaultPath), options.filters, window, wrappedCallback)
|
return binding.showSaveDialog(options.title, options.buttonLabel, options.defaultPath, options.filters, window, wrappedCallback)
|
||||||
},
|
},
|
||||||
|
|
||||||
showMessageBox: function (...args) {
|
showMessageBox: function (...args) {
|
||||||
|
|
Loading…
Reference in a new issue