Skip to content

Commit

Permalink
feat: select dropped item (fluxxcode#197)
Browse files Browse the repository at this point in the history
* select dropped item
  • Loading branch information
hacknus authored Nov 19, 2024
1 parent d88895a commit e983dd0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -229,6 +232,7 @@ impl FileDialog {
init_search: false,

any_focused_last_frame: false,
new_file_dropped: false,
}
}

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

0 comments on commit e983dd0

Please sign in to comment.