diff --git a/atom/browser/ui/file_dialog.h b/atom/browser/ui/file_dialog.h index b857648161b5..f65204c10e47 100644 --- a/atom/browser/ui/file_dialog.h +++ b/atom/browser/ui/file_dialog.h @@ -23,10 +23,11 @@ typedef std::pair > Filter; typedef std::vector Filters; enum FileDialogProperty { - FILE_DIALOG_OPEN_FILE = 1 << 0, - FILE_DIALOG_OPEN_DIRECTORY = 1 << 1, - FILE_DIALOG_MULTI_SELECTIONS = 1 << 2, - FILE_DIALOG_CREATE_DIRECTORY = 1 << 3, + FILE_DIALOG_OPEN_FILE = 1 << 0, + FILE_DIALOG_OPEN_DIRECTORY = 1 << 1, + FILE_DIALOG_MULTI_SELECTIONS = 1 << 2, + FILE_DIALOG_CREATE_DIRECTORY = 1 << 3, + FILE_DIALOG_SHOW_HIDDEN_FILES = 1 << 4, }; typedef base::CallbackSetEnabled(true); } + void SetupProperties(int properties) { + if (properties & FILE_DIALOG_MULTI_SELECTIONS) + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog()), TRUE); + if (properties & FILE_DIALOG_SHOW_HIDDEN_FILES) + g_object_set(dialog(), "show-hidden", TRUE, NULL); + } + void RunAsynchronous() { g_signal_connect(dialog_, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); @@ -235,9 +242,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; FileChooserDialog open_dialog(action, parent_window, title, button_label, default_path, filters); - if (properties & FILE_DIALOG_MULTI_SELECTIONS) - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(open_dialog.dialog()), - TRUE); + open_dialog.SetupProperties(properties); gtk_widget_show_all(open_dialog.dialog()); int response = gtk_dialog_run(GTK_DIALOG(open_dialog.dialog())); @@ -261,10 +266,7 @@ void ShowOpenDialog(atom::NativeWindow* parent_window, action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; FileChooserDialog* open_dialog = new FileChooserDialog( action, parent_window, title, button_label, default_path, filters); - if (properties & FILE_DIALOG_MULTI_SELECTIONS) - gtk_file_chooser_set_select_multiple( - GTK_FILE_CHOOSER(open_dialog->dialog()), TRUE); - + open_dialog->SetupProperties(properties); open_dialog->RunOpenAsynchronous(callback); } diff --git a/atom/browser/ui/file_dialog_mac.mm b/atom/browser/ui/file_dialog_mac.mm index d674817a2a41..398357b0b125 100644 --- a/atom/browser/ui/file_dialog_mac.mm +++ b/atom/browser/ui/file_dialog_mac.mm @@ -86,6 +86,8 @@ void SetupDialogForProperties(NSOpenPanel* dialog, int properties) { [dialog setCanCreateDirectories:YES]; if (properties & FILE_DIALOG_MULTI_SELECTIONS) [dialog setAllowsMultipleSelection:YES]; + if (properties & FILE_DIALOG_SHOW_HIDDEN_FILES) + [dialog setShowsHiddenFiles:YES]; } // Run modal dialog with parent window and return user's choice. diff --git a/atom/browser/ui/file_dialog_win.cc b/atom/browser/ui/file_dialog_win.cc index 5314b63a45a8..88c847efc8cf 100644 --- a/atom/browser/ui/file_dialog_win.cc +++ b/atom/browser/ui/file_dialog_win.cc @@ -201,6 +201,8 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window, options |= FOS_PICKFOLDERS; if (properties & FILE_DIALOG_MULTI_SELECTIONS) options |= FOS_ALLOWMULTISELECT; + if (properties & FILE_DIALOG_SHOW_HIDDEN_FILES) + options |= FOS_FORCESHOWHIDDEN; FileDialog open_dialog( default_path, title, button_label, filters, options); diff --git a/docs/api/dialog.md b/docs/api/dialog.md index afc32afda467..d71109e9dfdc 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -32,8 +32,8 @@ The `dialog` module has the following methods: left empty the default label will be used. * `filters` Array * `properties` Array - Contains which features the dialog should use, can - contain `openFile`, `openDirectory`, `multiSelections` and - `createDirectory` + contain `openFile`, `openDirectory`, `multiSelections`, `createDirectory` + and `showHiddenFiles`. * `callback` Function (optional) On success this method returns an array of file paths chosen by the user, diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index 07b7edd2b122..d24a1f98a7d8 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -6,11 +6,12 @@ const v8Util = process.atomBinding('v8_util') var includes = [].includes -var fileDialogProperties = { +const fileDialogProperties = { openFile: 1 << 0, openDirectory: 1 << 1, multiSelections: 1 << 2, - createDirectory: 1 << 3 + createDirectory: 1 << 3, + showHiddenFiles: 1 << 4 } var messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']