diff --git a/examples/multilingual/src/main.rs b/examples/multilingual/src/main.rs index 961d2097..debb0665 100644 --- a/examples/multilingual/src/main.rs +++ b/examples/multilingual/src/main.rs @@ -21,6 +21,7 @@ fn get_labels_german() -> FileDialogLabels { reload: "⟲ Neu laden".to_string(), show_hidden: " Versteckte Dateien anzeigen".to_string(), + show_system_files: " Systemdateien anzeigen".to_string(), heading_pinned: "Angeheftet".to_string(), heading_places: "Orte".to_string(), diff --git a/src/config/labels.rs b/src/config/labels.rs index f00762a7..8ba0899e 100644 --- a/src/config/labels.rs +++ b/src/config/labels.rs @@ -43,6 +43,8 @@ pub struct FileDialogLabels { pub reload: String, /// Text used for the option to show or hide hidden files and folders. pub show_hidden: String, + /// Text used for the option to show or hide system files. + pub show_system_files: String, // ------------------------------------------------------------------------ // Left panel: @@ -128,6 +130,7 @@ impl Default for FileDialogLabels { reload: "⟲ Reload".to_string(), show_hidden: " Show hidden".to_string(), + show_system_files: " Show system files".to_string(), heading_pinned: "Pinned".to_string(), heading_places: "Places".to_string(), diff --git a/src/config/mod.rs b/src/config/mod.rs index 5d343ee3..58ad044c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -18,6 +18,8 @@ pub struct FileDialogStorage { pub pinned_folders: Vec, /// If hidden files and folders should be listed inside the directory view. pub show_hidden: bool, + /// If system files should be listed inside the directory view. + pub show_system_files: bool, } impl Default for FileDialogStorage { @@ -26,6 +28,7 @@ impl Default for FileDialogStorage { Self { pinned_folders: Vec::new(), show_hidden: false, + show_system_files: false, } } } @@ -175,6 +178,8 @@ pub struct FileDialogConfig { pub show_reload_button: bool, /// If the show hidden files and folders option inside the top panel menu should be visible. pub show_hidden_option: bool, + /// If the show system files option inside the top panel menu should be visible. + pub show_system_files_option: bool, /// If the search input in the top panel should be visible. pub show_search: bool, @@ -245,6 +250,7 @@ impl Default for FileDialogConfig { show_menu_button: true, show_reload_button: true, show_hidden_option: true, + show_system_files_option: SHOW_SYSTEM_FILES_OPTION_DEFAULT, show_search: true, show_left_panel: true, @@ -256,6 +262,13 @@ impl Default for FileDialogConfig { } } +/// On Windows, displaying system files is troublesome, the option should only +/// be enabled on explicit request. +#[cfg(windows)] +const SHOW_SYSTEM_FILES_OPTION_DEFAULT: bool = false; +#[cfg(not(windows))] +const SHOW_SYSTEM_FILES_OPTION_DEFAULT: bool = true; + impl FileDialogConfig { /// Sets the storage used by the file dialog. /// Storage includes all data that is persistently stored between multiple diff --git a/src/data/directory_content.rs b/src/data/directory_content.rs index 65fd470a..dd5732d9 100644 --- a/src/data/directory_content.rs +++ b/src/data/directory_content.rs @@ -129,10 +129,18 @@ impl DirectoryContent { path: &Path, include_files: bool, show_hidden: bool, + show_system_files: bool, file_filter: Option<&FileFilter>, ) -> io::Result { Ok(Self { - content: load_directory(config, path, include_files, show_hidden, file_filter)?, + content: load_directory( + config, + path, + include_files, + show_hidden, + show_system_files, + file_filter, + )?, }) } @@ -190,6 +198,7 @@ fn load_directory( path: &Path, include_files: bool, show_hidden: bool, + show_system_files: bool, file_filter: Option<&FileFilter>, ) -> io::Result> { let paths = fs::read_dir(path)?; @@ -200,7 +209,7 @@ fn load_directory( Ok(entry) => { let entry = DirectoryEntry::from_path(config, entry.path().as_path()); - if entry.is_system_file() { + if !show_system_files && entry.is_system_file() { continue; } diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 71a0e8fa..3a6e6873 100644 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -886,6 +886,16 @@ impl FileDialog { self } + /// Sets whether the show system files option inside the top panel + /// menu should be visible. + /// + /// Has no effect when `FileDialog::show_top_panel` or + /// `FileDialog::show_menu_button` is disabled. + pub const fn show_system_files_option(mut self, show_system_files_option: bool) -> Self { + self.config.show_system_files_option = show_system_files_option; + self + } + /// Sets whether the search input should be visible in the top panel. /// /// Has no effect when `FileDialog::show_top_panel` is disabled. @@ -1230,7 +1240,9 @@ impl FileDialog { // Menu button containing reload button and different options if self.config.show_menu_button - && (self.config.show_reload_button || self.config.show_hidden_option) + && (self.config.show_reload_button + || self.config.show_hidden_option + || self.config.show_system_files_option) { ui.allocate_ui_with_layout( BUTTON_SIZE, @@ -1255,6 +1267,18 @@ impl FileDialog { self.refresh(); ui.close_menu(); } + + if self.config.show_system_files_option + && ui + .checkbox( + &mut self.config.storage.show_system_files, + &self.config.labels.show_system_files, + ) + .clicked() + { + self.refresh(); + ui.close_menu(); + } }); }, ); @@ -2924,6 +2948,7 @@ impl FileDialog { path, self.show_files, self.config.storage.show_hidden, + self.config.storage.show_system_files, self.get_selected_file_filter(), ) { Ok(content) => content,