From 89f8f0014a963d2717b5ffc0e1eb5eeed3eeced1 Mon Sep 17 00:00:00 2001 From: Jannis <55352293+fluxxcode@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:21:19 +0200 Subject: [PATCH] Fix directory filters not being applied using user directory shortcuts (#178) * Cleanup directory content constructor * Fix filters not beeing applied using user directories --- src/config/mod.rs | 9 +------ src/data/directory_content.rs | 48 +++++------------------------------ src/file_dialog.rs | 20 +++++++-------- 3 files changed, 16 insertions(+), 61 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index cdff8dde..bc093a2e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -255,7 +255,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_system_files_option: true, show_search: true, show_left_panel: true, @@ -267,13 +267,6 @@ 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 41ec3557..7384168d 100644 --- a/src/data/directory_content.rs +++ b/src/data/directory_content.rs @@ -177,28 +177,12 @@ impl DirectoryContent { config: &FileDialogConfig, path: &Path, include_files: bool, - show_hidden: bool, - show_system_files: bool, file_filter: Option<&FileFilter>, ) -> Self { if config.load_via_thread { - Self::with_thread( - config, - path, - include_files, - show_hidden, - show_system_files, - file_filter, - ) + Self::with_thread(config, path, include_files, file_filter) } else { - Self::without_thread( - config, - path, - include_files, - show_hidden, - show_system_files, - file_filter, - ) + Self::without_thread(config, path, include_files, file_filter) } } @@ -206,8 +190,6 @@ impl DirectoryContent { config: &FileDialogConfig, path: &Path, include_files: bool, - show_hidden: bool, - show_system_files: bool, file_filter: Option<&FileFilter>, ) -> Self { let (tx, rx) = mpsc::channel(); @@ -216,14 +198,7 @@ impl DirectoryContent { let p = path.to_path_buf(); let f = file_filter.cloned(); thread::spawn(move || { - let _ = tx.send(load_directory( - &c, - &p, - include_files, - show_hidden, - show_system_files, - f.as_ref(), - )); + let _ = tx.send(load_directory(&c, &p, include_files, f.as_ref())); }); Self { @@ -237,18 +212,9 @@ impl DirectoryContent { config: &FileDialogConfig, path: &Path, include_files: bool, - show_hidden: bool, - show_system_files: bool, file_filter: Option<&FileFilter>, ) -> Self { - match load_directory( - config, - path, - include_files, - show_hidden, - show_system_files, - file_filter, - ) { + match load_directory(config, path, include_files, file_filter) { Ok(c) => Self { state: DirectoryContentState::Success, content: c, @@ -357,8 +323,6 @@ fn load_directory( config: &FileDialogConfig, path: &Path, include_files: bool, - show_hidden: bool, - show_system_files: bool, file_filter: Option<&FileFilter>, ) -> io::Result> { let paths = fs::read_dir(path)?; @@ -369,7 +333,7 @@ fn load_directory( Ok(entry) => { let entry = DirectoryEntry::from_path(config, entry.path().as_path()); - if !show_system_files && entry.is_system_file() { + if !config.storage.show_system_files && entry.is_system_file() { continue; } @@ -377,7 +341,7 @@ fn load_directory( continue; } - if !show_hidden && entry.is_hidden() { + if !config.storage.show_hidden && entry.is_hidden() { continue; } diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 9e62cc9d..b5092b09 100644 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -1681,7 +1681,7 @@ impl FileDialog { // This is done so that we don't have to clone the user directories and // configured display names. let user_directories = std::mem::take(&mut self.user_directories); - let config = std::mem::take(&mut self.config); + let labels = std::mem::take(&mut self.config.labels); let mut visible = false; @@ -1690,33 +1690,33 @@ impl FileDialog { ui.label(self.config.labels.heading_places.as_str()); if let Some(path) = dirs.home_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.home_dir, path); + self.ui_update_left_panel_entry(ui, &labels.home_dir, path); } if let Some(path) = dirs.desktop_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.desktop_dir, path); + self.ui_update_left_panel_entry(ui, &labels.desktop_dir, path); } if let Some(path) = dirs.document_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.documents_dir, path); + self.ui_update_left_panel_entry(ui, &labels.documents_dir, path); } if let Some(path) = dirs.download_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.downloads_dir, path); + self.ui_update_left_panel_entry(ui, &labels.downloads_dir, path); } if let Some(path) = dirs.audio_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.audio_dir, path); + self.ui_update_left_panel_entry(ui, &labels.audio_dir, path); } if let Some(path) = dirs.picture_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.pictures_dir, path); + self.ui_update_left_panel_entry(ui, &labels.pictures_dir, path); } if let Some(path) = dirs.video_dir() { - self.ui_update_left_panel_entry(ui, &config.labels.videos_dir, path); + self.ui_update_left_panel_entry(ui, &labels.videos_dir, path); } visible = true; } self.user_directories = user_directories; - self.config = config; + self.config.labels = labels; visible } @@ -2973,8 +2973,6 @@ impl FileDialog { &self.config, path, self.show_files, - self.config.storage.show_hidden, - self.config.storage.show_system_files, self.get_selected_file_filter(), );