make drag and drop a little better
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-30 13:13:34 -05:00
parent 085c8244f9
commit 49117a39a3
2 changed files with 34 additions and 7 deletions

View file

@ -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 {

View file

@ -134,7 +134,7 @@ struct App {
presentation_editor: PresentationEditor,
searching: bool,
search_query: String,
search_results: Vec<ServiceItem>,
search_results: Vec<ServiceItemKind>,
search_id: cosmic::widget::Id,
library_dragged_item: Option<ServiceItem>,
fontdb: Arc<fontdb::Database>,
@ -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<ServiceItem>),
UpdateSearchResults(Vec<ServiceItemKind>),
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()