From 49117a39a3e67da4a1c0d546df45ad9d69d905d8 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 30 Sep 2025 13:13:34 -0500 Subject: [PATCH] make drag and drop a little better --- src/core/kinds.rs | 19 ++++++++++++++++++- src/main.rs | 22 ++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/core/kinds.rs b/src/core/kinds.rs index df3a6de..16c793f 100644 --- a/src/core/kinds.rs +++ b/src/core/kinds.rs @@ -2,7 +2,10 @@ use std::{error::Error, fmt::Display}; use serde::{Deserialize, Serialize}; -use crate::Slide; +use crate::{ + core::{content::Content, service_items::ServiceItem}, + Slide, +}; use super::{ images::Image, presentations::Presentation, songs::Song, @@ -30,6 +33,20 @@ impl ServiceItemKind { ServiceItemKind::Content(slide) => todo!(), } } + + pub fn to_service_item(&self) -> ServiceItem { + match self { + ServiceItemKind::Song(song) => song.to_service_item(), + ServiceItemKind::Video(video) => video.to_service_item(), + ServiceItemKind::Image(image) => image.to_service_item(), + ServiceItemKind::Presentation(presentation) => { + presentation.to_service_item() + } + ServiceItemKind::Content(slide) => { + todo!() + } + } + } } impl std::fmt::Display for ServiceItemKind { diff --git a/src/main.rs b/src/main.rs index 80d49c7..6c6b376 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,7 +134,7 @@ struct App { presentation_editor: PresentationEditor, searching: bool, search_query: String, - search_results: Vec, + search_results: Vec, search_id: cosmic::widget::Id, library_dragged_item: Option, fontdb: Arc, @@ -170,13 +170,15 @@ enum Message { RemoveServiceItem(usize), AddServiceItemDrop(usize), AppendServiceItem(ServiceItem), + AppendServiceItemKind(ServiceItemKind), ReorderService(usize, usize), ContextMenuItem(usize), SearchFocus, Search(String), CloseSearch, - UpdateSearchResults(Vec), + UpdateSearchResults(Vec), OpenEditor(ServiceItem), + OpenEditorKind(ServiceItemKind), New, Open, OpenFile(PathBuf), @@ -671,8 +673,8 @@ impl cosmic::Application for App { .search_results .iter() .map(|item| { - let title = text::title4(item.title.clone()); - let subtitle = text::body(item.kind.to_string()); + let title = text::title4(item.title().clone()); + let subtitle = text::body(item.to_string()); Element::from(Container::new( row![ column![title, subtitle].spacing( @@ -692,7 +694,7 @@ impl cosmic::Application for App { .space_l() ) .on_press( - Message::AppendServiceItem( + Message::AppendServiceItemKind( item.clone() ) ), @@ -709,7 +711,7 @@ impl cosmic::Application for App { .cosmic() .space_l() ) - .on_press(Message::OpenEditor( + .on_press(Message::OpenEditorKind( item.clone() )), "Edit Item", @@ -1289,6 +1291,10 @@ impl cosmic::Application for App { self.presenter.update_items(self.service.clone()); Task::none() } + Message::AppendServiceItemKind(item) => { + let item = item.to_service_item(); + return self.update(Message::AppendServiceItem(item)); + } Message::ReorderService(index, target_index) => { let item = self.service.remove(index); self.service.insert(target_index, item); @@ -1340,6 +1346,10 @@ impl cosmic::Application for App { ServiceItemKind::Content(_slide) => todo!(), } } + Message::OpenEditorKind(item) => { + let item = item.to_service_item(); + return self.update(Message::OpenEditor(item)); + } Message::New => { debug!("new file"); Task::none()