fluxxcode / egui-file-dialog

Full featured and customizable file dialog for egui
MIT License
88 stars 14 forks source link

Drag&Drop should select dropped item #196

Closed hacknus closed 3 days ago

hacknus commented 4 days ago

Sorry, I noticed this a bit too late. I think we should select the item that we dropped. Right now it only opens up the folder or the parent folder (if we dropped a file). We somehow need to call self.select_item() but I'm not sure how we can access it?

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);
            let mut entry = DirectoryEntry::from_path(&self.config, &path);
            self.select_item(&mut entry);
            new_file_dropped = true;
        }
    }
}

This here somehow only works if we drop the file a second time, after the first time it seems that it is only briefly selected and then cleared again. Do you have any idea, how we get the item here? We should also select the directory, if we are in the corresponding mode.

fluxxcode commented 4 days ago

That's how it should work. I'll have to take a closer look tomorrow to see what's going wrong.

hacknus commented 3 days ago

The issue is here in update_directory_content():

DirectoryContentState::Finished => {
         if let Some(dir) = self.current_directory() {
             let mut dir_entry = DirectoryEntry::from_path(&self.config, dir);
            self.select_item(&mut dir_entry);
        }
    false
}

after the directory is loaded, it selects the directory and overrides the dropped file. I think we need to have an if-statement there or something... Do you have an idea?