Skip to content

Commit

Permalink
Fix directory filters not being applied using user directory shortcuts (
Browse files Browse the repository at this point in the history
fluxxcode#178)

* Cleanup directory content constructor

* Fix filters not beeing applied using user directories
  • Loading branch information
fluxxcode authored Oct 26, 2024
1 parent 89784ca commit 89f8f00
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 61 deletions.
9 changes: 1 addition & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
48 changes: 6 additions & 42 deletions src/data/directory_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,37 +177,19 @@ 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)
}
}

fn with_thread(
config: &FileDialogConfig,
path: &Path,
include_files: bool,
show_hidden: bool,
show_system_files: bool,
file_filter: Option<&FileFilter>,
) -> Self {
let (tx, rx) = mpsc::channel();
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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<Vec<DirectoryEntry>> {
let paths = fs::read_dir(path)?;
Expand All @@ -369,15 +333,15 @@ 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;
}

if !include_files && entry.is_file() {
continue;
}

if !show_hidden && entry.is_hidden() {
if !config.storage.show_hidden && entry.is_hidden() {
continue;
}

Expand Down
20 changes: 9 additions & 11 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}
Expand Down Expand Up @@ -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(),
);

Expand Down

0 comments on commit 89f8f00

Please sign in to comment.