prototype DnD that works with plank dock
This commit is contained in:
parent
f45f2b1826
commit
14b8112bd7
4 changed files with 40 additions and 19 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
use crate::app_group::AppGroup;
|
use crate::app_group::AppGroup;
|
||||||
|
use gdk4::ContentProvider;
|
||||||
|
use gdk4::Display;
|
||||||
|
use gio::File;
|
||||||
use gtk4 as gtk;
|
use gtk4 as gtk;
|
||||||
|
use gtk4::traits::WidgetExt;
|
||||||
|
use gtk4::DragSource;
|
||||||
|
use gtk4::IconTheme;
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
@ -26,8 +32,35 @@ impl GridItem {
|
||||||
pub fn set_app_info(&self, app_info: &gio::DesktopAppInfo) {
|
pub fn set_app_info(&self, app_info: &gio::DesktopAppInfo) {
|
||||||
let self_ = imp::GridItem::from_instance(self);
|
let self_ = imp::GridItem::from_instance(self);
|
||||||
self_.name.set_text(&app_info.name());
|
self_.name.set_text(&app_info.name());
|
||||||
|
|
||||||
|
let drag = DragSource::builder()
|
||||||
|
.name("application library drag source")
|
||||||
|
.actions(gdk4::DragAction::COPY)
|
||||||
|
// .content()
|
||||||
|
.build();
|
||||||
|
self.add_controller(&drag);
|
||||||
|
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));
|
||||||
|
}
|
||||||
if let Some(icon) = app_info.icon() {
|
if let Some(icon) = app_info.icon() {
|
||||||
self_.image.set_from_gicon(&icon);
|
self_.image.set_from_gicon(&icon);
|
||||||
|
// 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() {
|
||||||
|
if let Some(icon_theme) = IconTheme::for_display(default_display) {
|
||||||
|
if let Some(paintable_icon) = icon_theme.lookup_by_gicon(
|
||||||
|
&icon,
|
||||||
|
64,
|
||||||
|
1,
|
||||||
|
gtk4::TextDirection::None,
|
||||||
|
gtk4::IconLookupFlags::empty(),
|
||||||
|
) {
|
||||||
|
drag.set_icon(Some(&paintable_icon), 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,15 @@ use window::Window;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = gtk::Application::new(Some("com.cosmic.app_library"), Default::default());
|
let app = gtk::Application::new(Some("com.cosmic.app_library"), Default::default());
|
||||||
app.connect_startup(|_app| load_css());
|
app.connect_startup(|app| {
|
||||||
|
load_css();
|
||||||
app.connect_activate(|app| {
|
build_ui(&app);
|
||||||
build_ui(app);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// app.connect_activate(|app| {
|
||||||
|
// build_ui(app);
|
||||||
|
// });
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1 @@
|
||||||
description {
|
|
||||||
line-height: 1.5em;
|
|
||||||
background-image: none;
|
|
||||||
background-color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
row.row1 {
|
|
||||||
background-image: none;
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
shortcut {
|
|
||||||
background-image: none;
|
|
||||||
background-color: green;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@
|
||||||
<property name="propagate-natural-height">true</property>
|
<property name="propagate-natural-height">true</property>
|
||||||
<property name="min-content-height">150</property>
|
<property name="min-content-height">150</property>
|
||||||
<property name="max-content-height">300</property>
|
<property name="max-content-height">300</property>
|
||||||
<property name="margin-top">12</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkGridView" id="group_grid_view">
|
<object class="GtkGridView" id="group_grid_view">
|
||||||
<property name="min-columns">8</property>
|
<property name="min-columns">8</property>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue