Merge pull request #6431 from electron/show-hidden-files
Add showHiddenFiles property for dialog.showOpenDialog
This commit is contained in:
commit
d5a7b3b7fd
6 changed files with 24 additions and 16 deletions
|
@ -23,10 +23,11 @@ typedef std::pair<std::string, std::vector<std::string> > Filter;
|
|||
typedef std::vector<Filter> 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::Callback<void(
|
||||
|
|
|
@ -87,12 +87,19 @@ class FileChooserDialog {
|
|||
AddFilters(filters);
|
||||
}
|
||||
|
||||
virtual ~FileChooserDialog() {
|
||||
~FileChooserDialog() {
|
||||
gtk_widget_destroy(dialog_);
|
||||
if (parent_)
|
||||
parent_->SetEnabled(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<CShellFileOpenDialog> open_dialog(
|
||||
default_path, title, button_label, filters, options);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue