Skip to content

Commit

Permalink
feat: implement drag and drop (fluxxcode#192)
Browse files Browse the repository at this point in the history
* implement drag and drop
  • Loading branch information
hacknus authored Nov 18, 2024
1 parent 4008551 commit 3f6cc40
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use egui::text::{CCursor, CCursorRange};
use std::fmt::Debug;
use std::io;
use std::path::{Path, PathBuf};

use egui::text::{CCursor, CCursorRange};

use crate::config::{
FileDialogConfig, FileDialogKeyBindings, FileDialogLabels, FileDialogStorage, FileFilter,
Filter, QuickAccess,
Expand Down Expand Up @@ -1136,6 +1135,31 @@ impl FileDialog {
if !is_open {
self.cancel();
}

let mut new_file_dropped = false;

// Collect dropped files:
ctx.input(|i| {
// check if files were dropped
if let Some(dropped_file) = i.raw.dropped_files.last() {
if let Some(path) = &dropped_file.path {
if path.is_dir() {
// if we dropped a directory, go there
self.load_directory(path.as_path());
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;
}
}
}
});

// update GUI if we dropped a file
if new_file_dropped {
ctx.request_repaint();
}
}

/// Updates the main modal background of the file dialog window.
Expand Down

0 comments on commit 3f6cc40

Please sign in to comment.