use std::sync::Arc;
use parking_lot::Mutex;
use super::EventControl;
use crate::core::NodeId;
#[derive(Clone)]
pub struct CopyEvent {
text: Arc<Mutex<Option<String>>>,
cut: bool,
pub target_id: NodeId,
pub focus_id: NodeId,
pub(crate) control: EventControl,
}
impl CopyEvent {
pub(crate) fn new(focus_id: NodeId, cut: bool) -> Self {
Self {
text: Arc::new(Mutex::new(None)),
cut,
target_id: focus_id,
focus_id,
control: EventControl::new(),
}
}
pub(crate) fn at(&self, target_id: NodeId) -> Self {
Self {
text: Arc::clone(&self.text),
cut: self.cut,
target_id,
focus_id: self.focus_id,
control: self.control.clone(),
}
}
pub fn set_text(&self, text: impl Into<String>) {
*self.text.lock() = Some(text.into());
}
pub fn text(&self) -> Option<String> {
self.text.lock().clone()
}
pub fn is_cut(&self) -> bool {
self.cut
}
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 CopyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CopyEvent")
.field("cut", &self.cut)
.field("target_id", &self.target_id)
.field("focus_id", &self.focus_id)
.finish()
}
}