DnD from app library prototype into dock intyo correct index
This commit is contained in:
parent
4e033665cb
commit
da46175abe
2 changed files with 27 additions and 4 deletions
|
|
@ -62,12 +62,16 @@ impl DockItem {
|
||||||
if let Some(drag_controller) = self_.drag_controller.get() {
|
if let Some(drag_controller) = self_.drag_controller.get() {
|
||||||
// if let Some(file) = app_info.filename() {
|
// if let Some(file) = app_info.filename() {
|
||||||
// let file = File::for_path(file);
|
// let file = File::for_path(file);
|
||||||
let provider = ContentProvider::for_value(&app_info.to_value());
|
if let Some(file) = app_info.filename() {
|
||||||
drag_controller.set_content(Some(&provider));
|
let file = File::for_path(file);
|
||||||
|
let provider = ContentProvider::for_value(&file.to_value());
|
||||||
|
drag_controller.set_content(Some(&provider));
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
drag_controller.connect_drag_end(move |_self, _drag, delete_data| {
|
drag_controller.connect_drag_end(move |_self, _drag, delete_data| {
|
||||||
dbg!("removing", delete_data);
|
dbg!("removing", delete_data);
|
||||||
});
|
});
|
||||||
|
//TODO investigate X11 errors when reordering dock items
|
||||||
drag_controller.connect_drag_cancel(
|
drag_controller.connect_drag_cancel(
|
||||||
glib::clone!(@weak saved_app_model => @default-return true, move |_self, _drag, _delete_data| {
|
glib::clone!(@weak saved_app_model => @default-return true, move |_self, _drag, _delete_data| {
|
||||||
dbg!("removing {}", i);
|
dbg!("removing {}", i);
|
||||||
|
|
|
||||||
|
|
@ -223,15 +223,34 @@ impl Window {
|
||||||
// None => drag.actions(),
|
// None => drag.actions(),
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
let saved_app_list_view = saved_app_list_view.get();
|
||||||
drop_controller.connect_drop(
|
drop_controller.connect_drop(
|
||||||
glib::clone!(@weak saved_app_model => @default-return true, move |_self, drop_value, x, y| {
|
glib::clone!(@weak saved_app_model, @weak saved_app_list_view => @default-return true, move |_self, drop_value, x, y| {
|
||||||
|
dbg!(x);
|
||||||
|
dbg!(y);
|
||||||
|
let max_y = saved_app_list_view.allocated_height();
|
||||||
|
let max_x = saved_app_list_view.allocated_width();
|
||||||
|
dbg!(max_x);
|
||||||
|
dbg!(max_y);
|
||||||
|
let n_buckets = saved_app_model.n_items() * 2;
|
||||||
|
|
||||||
|
let drop_bucket = (x * n_buckets as f64 / (max_x as f64 + 0.1)) as u32;
|
||||||
|
let index = if drop_bucket == 0 {
|
||||||
|
0
|
||||||
|
} else if drop_bucket == n_buckets - 1 {
|
||||||
|
saved_app_model.n_items()
|
||||||
|
} else {
|
||||||
|
(drop_bucket + 1) / 2
|
||||||
|
};
|
||||||
|
dbg!(index);
|
||||||
dbg!("dropped it!");
|
dbg!("dropped it!");
|
||||||
if let Ok(Some(path)) = drop_value.get::<Option<String>>() {
|
if let Ok(Some(path)) = drop_value.get::<Option<String>>() {
|
||||||
dbg!(&path);
|
dbg!(&path);
|
||||||
if let Some(path) = &Path::new(&path).file_name() {
|
if let Some(path) = &Path::new(&path).file_name() {
|
||||||
if let Some(app_info) = gio::DesktopAppInfo::new(&path.to_string_lossy()) {
|
if let Some(app_info) = gio::DesktopAppInfo::new(&path.to_string_lossy()) {
|
||||||
dbg!(app_info.name());
|
dbg!(app_info.name());
|
||||||
saved_app_model.append(&app_info);
|
saved_app_model.insert(index, &app_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue