starting to do my own dnd
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-08-14 13:11:21 -05:00
parent 117d3d60f1
commit 1f3609d7df
3 changed files with 29 additions and 12 deletions

View file

@ -118,7 +118,7 @@ enum Message {
SongEditor(song_editor::Message),
File(PathBuf),
DndEnter(Entity, Vec<String>),
DndDrop(Entity, Option<ServiceItem>, DndAction),
DndDrop,
OpenWindow,
CloseWindow(Option<window::Id>),
WindowOpened(window::Id, Option<Point>),
@ -634,16 +634,26 @@ impl cosmic::Application for App {
debug!(?data);
Task::none()
}
Message::DndDrop(entity, service_item, action) => {
debug!(?entity);
debug!(?action);
debug!(?service_item);
Message::DndDrop => {
// debug!(?entity);
// debug!(?action);
// debug!(?service_item);
if let Some(item) = service_item {
self.nav_model
.insert()
.text(item.title.clone())
.data(item);
if let Some(library) = self.library {
if let Some((lib, item)) = library.dragged_item {
// match lib {
// core::model::LibraryKind::Song => ,
// core::model::LibraryKind::Video => todo!(),
// core::model::LibraryKind::Image => todo!(),
// core::model::LibraryKind::Presentation => todo!(),
// }
let item = library.get_song(item).unwrap();
let item = ServiceItem::from(item);
self.nav_model
.insert()
.text(item.title.clone())
.data(item);
}
}
Task::none()
}

View file

@ -39,13 +39,14 @@ pub(crate) struct Library {
library_hovered: Option<LibraryKind>,
selected_item: Option<(LibraryKind, i32)>,
hovered_item: Option<(LibraryKind, i32)>,
dragged_item: Option<(LibraryKind, i32)>,
pub dragged_item: Option<(LibraryKind, i32)>,
editing_item: Option<(LibraryKind, i32)>,
db: SqlitePool,
}
pub(crate) enum Action {
OpenItem(Option<(LibraryKind, i32)>),
DraggedItem(Option<(LibraryKind, i32)>),
Task(Task<Message>),
None,
}
@ -59,6 +60,7 @@ pub(crate) enum Message {
OpenLibrary(Option<LibraryKind>),
HoverItem(Option<(LibraryKind, i32)>),
SelectItem(Option<(LibraryKind, i32)>),
DragItem(Option<(LibraryKind, i32)>),
UpdateSong(Song),
SongChanged,
UpdateImage(Image),
@ -118,6 +120,10 @@ impl<'a> Library {
Message::SelectItem(item) => {
self.selected_item = item;
}
Message::DragItem(item) => {
self.dragged_item = item;
// return Action::DraggedItem(item);
}
Message::UpdateSong(song) => {
let Some((kind, index)) = self.editing_item else {
error!("Not editing an item");
@ -366,6 +372,7 @@ impl<'a> Library {
.map(|_| Message::None);
DndSource::<Message, ServiceItem>::new(
mouse_area(visual_item)
.on_drag(Message::DragItem(Some((model.kind, index as i32))))
.on_enter(Message::HoverItem(
Some((
model.kind,