use std::sync::Arc;
use super::{ClipboardContent, ClipboardImage, ClipboardKinds, EventControl};
use crate::core::NodeId;
#[derive(Clone)]
pub struct PasteEvent {
content: Arc<ClipboardContent>,
pub target_id: NodeId,
pub input_id: NodeId,
pub(crate) control: EventControl,
}
impl PasteEvent {
pub(crate) fn new(content: Arc<ClipboardContent>, input_id: NodeId) -> Self {
Self {
content,
target_id: input_id,
input_id,
control: EventControl::new(),
}
}
pub(crate) fn at(&self, target_id: NodeId) -> Self {
Self {
content: Arc::clone(&self.content),
target_id,
input_id: self.input_id,
control: self.control.clone(),
}
}
pub fn content(&self) -> &ClipboardContent {
&self.content
}
pub fn kinds(&self) -> ClipboardKinds {
self.content.kinds()
}
pub fn text(&self) -> Option<&str> {
self.content.text_content()
}
pub fn markdown(&self) -> Option<&str> {
self.content.markdown_content()
}
pub fn image(&self) -> Option<&ClipboardImage> {
self.content.image_content()
}
pub fn files(&self) -> &[std::path::PathBuf] {
self.content.file_paths()
}
pub fn prevent_default(&self) {
self.control.prevent_default();
}
pub fn default_prevented(&self) -> bool {
self.control.default_prevented()
}
pub fn stop_propagation(&self) {
self.control.stop_propagation();
}
pub fn propagation_stopped(&self) -> bool {
self.control.propagation_stopped()
}
pub fn stop_immediate_propagation(&self) {
self.control.stop_immediate_propagation();
}
pub fn immediate_propagation_stopped(&self) -> bool {
self.control.immediate_propagation_stopped()
}
}
impl std::fmt::Debug for PasteEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PasteEvent")
.field("kinds", &self.kinds())
.field("target_id", &self.target_id)
.field("input_id", &self.input_id)
.finish()
}
}