accept dnd drops from app library prototype
This commit is contained in:
parent
b9247e37c4
commit
83b6f3da5e
9 changed files with 215 additions and 47 deletions
|
|
@ -2,6 +2,7 @@ use crate::app_group::AppGroup;
|
|||
use gdk4::ContentProvider;
|
||||
use gdk4::Display;
|
||||
use gio::File;
|
||||
use gio::Icon;
|
||||
use gtk4 as gtk;
|
||||
use gtk4::traits::WidgetExt;
|
||||
use gtk4::DragSource;
|
||||
|
|
@ -33,19 +34,23 @@ impl GridItem {
|
|||
let self_ = imp::GridItem::from_instance(self);
|
||||
self_.name.set_text(&app_info.name());
|
||||
|
||||
let drag = DragSource::builder()
|
||||
let drag_controller = DragSource::builder()
|
||||
.name("application library drag source")
|
||||
.actions(gdk4::DragAction::COPY)
|
||||
// .content()
|
||||
.build();
|
||||
self.add_controller(&drag);
|
||||
self.add_controller(&drag_controller);
|
||||
if let Some(file) = app_info.filename() {
|
||||
let file = File::for_path(file);
|
||||
let provider = ContentProvider::for_value(&file.to_value());
|
||||
drag.set_content(Some(&provider));
|
||||
drag_controller.set_content(Some(&provider));
|
||||
}
|
||||
if let Some(icon) = app_info.icon() {
|
||||
self_.image.set_from_gicon(&icon);
|
||||
let icon = app_info
|
||||
.icon()
|
||||
.unwrap_or(Icon::for_string("image-missing").expect("Failed to set default icon"));
|
||||
self_.image.set_from_gicon(&icon);
|
||||
drag_controller.connect_drag_begin(glib::clone!(@weak icon, => move |_self, drag| {
|
||||
drag.set_selected_action(gdk4::DragAction::MOVE);
|
||||
// set drag source icon if possible...
|
||||
// gio Icon is not easily converted to a Paintable, but this seems to be the correct method
|
||||
if let Some(default_display) = &Display::default() {
|
||||
|
|
@ -57,11 +62,11 @@ impl GridItem {
|
|||
gtk4::TextDirection::None,
|
||||
gtk4::IconLookupFlags::empty(),
|
||||
) {
|
||||
drag.set_icon(Some(&paintable_icon), 32, 32);
|
||||
_self.set_icon(Some(&paintable_icon), 32, 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn set_group_info(&self, app_group: AppGroup) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue