}
void ShowOpenDialog(const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const file_dialog::Filters& filters,
int properties,
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
peek,
&callback)) {
- file_dialog::ShowOpenDialog(window, title, default_path, filters,
- properties, callback);
+ file_dialog::ShowOpenDialog(window, title, button_label, default_path,
+ filters, properties, callback);
} else {
std::vector<base::FilePath> paths;
- if (file_dialog::ShowOpenDialog(window, title, default_path, filters,
- properties, &paths))
+ if (file_dialog::ShowOpenDialog(window, title, button_label, default_path,
+ filters, properties, &paths))
args->Return(paths);
}
}
void ShowSaveDialog(const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const file_dialog::Filters& filters,
atom::NativeWindow* window,
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
peek,
&callback)) {
- file_dialog::ShowSaveDialog(window, title, default_path, filters, callback);
+ file_dialog::ShowSaveDialog(window, title, button_label, default_path,
+ filters, callback);
} else {
base::FilePath path;
- if (file_dialog::ShowSaveDialog(window, title, default_path, filters,
- &path))
+ if (file_dialog::ShowSaveDialog(window, title, button_label, default_path,
+ filters, &path))
args->Return(path);
}
}
window = relay->window.get();
base::FilePath path;
- if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(), default_path,
+ if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
+ "Save", default_path,
file_dialog::Filters(), &path)) {
// Remember the last selected download directory.
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
} else {
file_dialog::Filters filters;
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
- if (!file_dialog::ShowSaveDialog(owner_window(), url, default_path,
+ if (!file_dialog::ShowSaveDialog(owner_window(), url, "Save", default_path,
filters, &path)) {
base::StringValue url_value(url);
web_contents_->CallClientFunction(
base::FilePath default_path;
std::vector<base::FilePath> paths;
int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
- if (!file_dialog::ShowOpenDialog(owner_window(), "", default_path,
+ if (!file_dialog::ShowOpenDialog(owner_window(), "", "Open", default_path,
filters, flag, &paths))
return;
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
base::FilePath* path);
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
const SaveDialogCallback& callback);
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
base::FilePath* path) {
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
const SaveDialogCallback& callback) {
void SetupDialog(NSSavePanel* dialog,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters) {
if (!title.empty())
[dialog setTitle:base::SysUTF8ToNSString(title)];
+ if (!button_label.empty())
+ [dialog setPrompt:base::SysUTF8ToNSString(button_label)];
+
NSString* default_dir = nil;
NSString* default_filename = nil;
if (!default_path.empty()) {
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
DCHECK(paths);
NSOpenPanel* dialog = [NSOpenPanel openPanel];
- SetupDialog(dialog, title, default_path, filters);
+ SetupDialog(dialog, title, button_label, default_path, filters);
SetupDialogForProperties(dialog, properties);
int chosen = RunModalDialog(dialog, parent_window);
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
const OpenDialogCallback& c) {
NSOpenPanel* dialog = [NSOpenPanel openPanel];
- SetupDialog(dialog, title, default_path, filters);
+ SetupDialog(dialog, title, button_label, default_path, filters);
SetupDialogForProperties(dialog, properties);
// Duplicate the callback object here since c is a reference and gcd would
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
base::FilePath* path) {
DCHECK(path);
NSSavePanel* dialog = [NSSavePanel savePanel];
- SetupDialog(dialog, title, default_path, filters);
+ SetupDialog(dialog, title, button_label, default_path, filters);
int chosen = RunModalDialog(dialog, parent_window);
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
const SaveDialogCallback& c) {
NSSavePanel* dialog = [NSSavePanel savePanel];
- SetupDialog(dialog, title, default_path, filters);
+ SetupDialog(dialog, title, button_label, default_path, filters);
__block SaveDialogCallback callback = c;
template <typename T>
class FileDialog {
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) {
std::wstring file_part;
if (!IsDirectory(default_path))
if (!title.empty())
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
// Electron, we disable it to make a better experience.
//
void RunOpenDialogInNewThread(const RunState& run_state,
atom::NativeWindow* parent,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
const OpenDialogCallback& callback) {
std::vector<base::FilePath> paths;
- bool result = ShowOpenDialog(parent, title, default_path, filters, properties,
- &paths);
+ bool result = ShowOpenDialog(parent, title, button_label, default_path,
+ filters, properties, &paths);
run_state.ui_message_loop->PostTask(FROM_HERE,
base::Bind(callback, result, paths));
run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
void RunSaveDialogInNewThread(const RunState& run_state,
atom::NativeWindow* parent,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
const SaveDialogCallback& callback) {
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
void ShowOpenDialog(atom::NativeWindow* parent,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
int properties,
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
base::FilePath* path) {
void ShowSaveDialog(atom::NativeWindow* parent,
const std::string& title,
+ const std::string& button_label,
const base::FilePath& default_path,
const Filters& filters,
const SaveDialogCallback& callback) {
base::FilePath path;
if (file_dialog::ShowSaveDialog(window_,
base::UTF16ToUTF8(params.title),
+ "Save",
params.default_file_name,
filters,
&path)) {
prefs::kSelectFileLastDirectory).Append(params.default_file_name);
if (file_dialog::ShowOpenDialog(window_,
base::UTF16ToUTF8(params.title),
+ "Open",
default_file_path,
filters,
flags,
* `options` Object
* `title` String
* `defaultPath` String
+ * `buttonLabel` String
* `filters` Array
* `properties` Array - Contains which features the dialog should use, can
contain `openFile`, `openDirectory`, `multiSelections` and
} else if (typeof options.title !== 'string') {
throw new TypeError('Title must be a string')
}
+ if (options.buttonLabel == null) {
+ if (options.properties.indexOf('openDirectory') !== -1) {
+ options.buttonLabel = 'Choose'
+ } else {
+ options.buttonLabel = 'Open'
+ }
+ } else if (typeof options.buttonLabel !== 'string') {
+ throw new TypeError('buttonLabel must be a string')
+ }
if (options.defaultPath == null) {
options.defaultPath = ''
} else if (typeof options.defaultPath !== 'string') {
wrappedCallback = typeof callback === 'function' ? function (success, result) {
return callback(success ? result : void 0)
} : null
- return binding.showOpenDialog(String(options.title), String(options.defaultPath), options.filters, properties, window, wrappedCallback)
+ return binding.showOpenDialog(String(options.title), String(options.buttonLabel), String(options.defaultPath), options.filters, properties, window, wrappedCallback)
},
showSaveDialog: function (...args) {
} else if (typeof options.title !== 'string') {
throw new TypeError('Title must be a string')
}
+ if (options.buttonLabel == null) {
+ options.buttonLabel = 'Save'
+ } else if (typeof options.buttonLabel !== 'string') {
+ throw new TypeError('buttonLabel must be a string')
+ }
if (options.defaultPath == null) {
options.defaultPath = ''
} else if (typeof options.defaultPath !== 'string') {
wrappedCallback = typeof callback === 'function' ? function (success, result) {
return callback(success ? result : void 0)
} : null
- return binding.showSaveDialog(String(options.title), String(options.defaultPath), options.filters, window, wrappedCallback)
+ return binding.showSaveDialog(String(options.title), String(options.buttonLabel), String(options.defaultPath), options.filters, window, wrappedCallback)
},
showMessageBox: function (...args) {