adding base for drag n drop

This commit is contained in:
Chris Cochrun 2025-02-18 16:43:39 -06:00
parent f79e61f2ed
commit 1ce365fc04
8 changed files with 139 additions and 49 deletions

View file

@ -1,6 +1,7 @@
use super::kinds::ServiceItemKind;
use super::{kinds::ServiceItemKind, service_items::ServiceItem};
pub trait Content {
fn title(&self) -> String;
fn kind(&self) -> ServiceItemKind;
fn to_service_item(&self) -> ServiceItem;
}

View file

@ -30,6 +30,10 @@ impl Content for Image {
fn kind(&self) -> ServiceItemKind {
ServiceItemKind::Image(self.clone())
}
fn to_service_item(&self) -> super::service_items::ServiceItem {
self.into()
}
}
impl From<Value> for Image {

View file

@ -44,6 +44,10 @@ impl Content for Presentation {
fn kind(&self) -> ServiceItemKind {
ServiceItemKind::Presentation(self.clone())
}
fn to_service_item(&self) -> super::service_items::ServiceItem {
self.into()
}
}
impl From<Value> for Presentation {

View file

@ -1,7 +1,9 @@
use std::borrow::Cow;
use std::ops::Deref;
use cosmic::iced::clipboard::mime::{AllowedMimeTypes, AsMimeTypes};
use crisp::types::{Keyword, Symbol, Value};
use miette::Result;
use miette::{miette, Result};
use tracing::{debug, error};
use crate::Slide;
@ -22,6 +24,48 @@ pub struct ServiceItem {
// pub item: Box<dyn ServiceTrait>,
}
impl TryFrom<(Vec<u8>, String)> for ServiceItem {
type Error = miette::Error;
fn try_from(
value: (Vec<u8>, String),
) -> std::result::Result<Self, Self::Error> {
let sto = value.0.to_owned();
let song = Song {
title: "Death Was Arrested".to_string(),
..Default::default()
};
debug!(?value);
Ok(Self::from(&song))
}
}
impl AllowedMimeTypes for ServiceItem {
fn allowed() -> Cow<'static, [String]> {
Cow::from(vec!["application/service-item".to_string()])
}
}
impl AsMimeTypes for ServiceItem {
fn available(&self) -> std::borrow::Cow<'static, [String]> {
debug!(?self);
Cow::from(vec!["application/service-item".to_string()])
}
fn as_bytes(
&self,
mime_type: &str,
) -> Option<std::borrow::Cow<'static, [u8]>> {
todo!();
debug!(?self);
debug!(mime_type);
Some(Cow::from(
r#"(slide :background (image :source "~/pics/frodo.jpg" :fit fill)
(text "This is frodo" :font-size 70))"#.to_string().into_bytes()
))
}
}
impl ServiceItem {
pub fn title(&self) -> String {
self.title.clone()

View file

@ -44,6 +44,10 @@ impl Content for Song {
fn kind(&self) -> ServiceItemKind {
ServiceItemKind::Song(self.clone())
}
fn to_service_item(&self) -> super::service_items::ServiceItem {
self.into()
}
}
impl ServiceTrait for Song {

View file

@ -35,6 +35,10 @@ impl Content for Video {
fn kind(&self) -> ServiceItemKind {
ServiceItemKind::Video(self.clone())
}
fn to_service_item(&self) -> super::service_items::ServiceItem {
self.into()
}
}
impl From<Value> for Video {