diff options
Diffstat (limited to '')
-rw-r--r-- | runtime/src/clipboard.rs (renamed from native/src/clipboard.rs) | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/native/src/clipboard.rs b/runtime/src/clipboard.rs index c9105bc0..bc450912 100644 --- a/native/src/clipboard.rs +++ b/runtime/src/clipboard.rs @@ -1,30 +1,9 @@ //! Access the clipboard. -use iced_futures::MaybeSend; +use crate::command::{self, Command}; +use crate::futures::MaybeSend; use std::fmt; -/// A buffer for short-term storage and transfer within and between -/// applications. -pub trait Clipboard { - /// Reads the current content of the [`Clipboard`] as text. - fn read(&self) -> Option<String>; - - /// Writes the given text contents to the [`Clipboard`]. - fn write(&mut self, contents: String); -} - -/// A null implementation of the [`Clipboard`] trait. -#[derive(Debug, Clone, Copy)] -pub struct Null; - -impl Clipboard for Null { - fn read(&self) -> Option<String> { - None - } - - fn write(&mut self, _contents: String) {} -} - /// A clipboard action to be performed by some [`Command`]. /// /// [`Command`]: crate::Command @@ -60,3 +39,15 @@ impl<T> fmt::Debug for Action<T> { } } } + +/// Read the current contents of the clipboard. +pub fn read<Message>( + f: impl Fn(Option<String>) -> Message + 'static, +) -> Command<Message> { + Command::single(command::Action::Clipboard(Action::Read(Box::new(f)))) +} + +/// Write the given contents to the clipboard. +pub fn write<Message>(contents: String) -> Command<Message> { + Command::single(command::Action::Clipboard(Action::Write(contents))) +} |