Add icon preview to drag-and-drop dialog

Fast icon extraction pulls .DirIcon from the squashfs without full
analysis. Single-file drops show a 64px preview in the dialog while
the user chooses an import option.
This commit is contained in:
lashman
2026-02-27 23:58:09 +02:00
parent 843af0a8a5
commit 00a1ed3599
2 changed files with 67 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use std::rc::Rc;
use crate::core::analysis;
use crate::core::database::Database;
use crate::core::discovery;
use crate::core::inspector;
use crate::i18n::{i18n, ni18n_f};
/// Registered file info returned by the fast registration phase.
@@ -63,6 +64,28 @@ pub fn show_drop_dialog(
.body(&body)
.build();
// For single file, try fast icon extraction for a preview
if count == 1 {
let file_path = files[0].clone();
let dialog_ref = dialog.clone();
glib::spawn_future_local(async move {
let result = gio::spawn_blocking(move || {
inspector::extract_icon_fast(&file_path)
})
.await;
if let Ok(Some(icon_path)) = result {
let image = gtk::Image::builder()
.file(icon_path.to_string_lossy().as_ref())
.pixel_size(64)
.halign(gtk::Align::Center)
.margin_top(12)
.build();
dialog_ref.set_extra_child(Some(&image));
}
});
}
dialog.add_response("cancel", &i18n("Cancel"));
dialog.add_response("keep-in-place", &i18n("Keep in place"));
dialog.add_response("copy-only", &i18n("Copy to Applications"));