Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select dropped item #197

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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