From e983dd08e3e2fe3ab32beaa1b1f4fbf79728dcc5 Mon Sep 17 00:00:00 2001 From: hacknus <33124824+hacknus@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:23:44 +0100 Subject: [PATCH] feat: select dropped item (#197) * select dropped item --- src/file_dialog.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 1a0956d5..57f5de1e 100644 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -155,6 +155,9 @@ pub struct FileDialog { /// This is used to prevent the dialog from closing when pressing the escape key /// inside a text input. any_focused_last_frame: bool, + + /// flag to set if files have been dropped + new_file_dropped: bool, } /// This tests if file dialog is send and sync. @@ -229,6 +232,7 @@ impl FileDialog { init_search: false, any_focused_last_frame: false, + new_file_dropped: false, } } @@ -1136,8 +1140,6 @@ impl FileDialog { self.cancel(); } - let mut new_file_dropped = false; - // Collect dropped files: ctx.input(|i| { // check if files were dropped @@ -1146,18 +1148,20 @@ impl FileDialog { if path.is_dir() { // if we dropped a directory, go there self.load_directory(path.as_path()); - new_file_dropped = true; + self.new_file_dropped = true; } else if let Some(parent) = path.parent() { // else, go to the parent directory self.load_directory(parent); - new_file_dropped = true; + self.select_item(&mut DirectoryEntry::from_path(&self.config, path)); + self.scroll_to_selection = true; + self.new_file_dropped = true; } } } }); // update GUI if we dropped a file - if new_file_dropped { + if self.new_file_dropped { ctx.request_repaint(); } } @@ -2048,6 +2052,12 @@ impl FileDialog { true } DirectoryContentState::Finished => { + // don't override the selected dropped item with the active directory + if self.new_file_dropped { + // clear the flag and return + self.new_file_dropped = false; + return true; + } if let Some(dir) = self.current_directory() { let mut dir_entry = DirectoryEntry::from_path(&self.config, dir); self.select_item(&mut dir_entry);