From 508b3fe1f1405bdb8b860d0d63e2c7adfbbd51ca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 13 Feb 2024 03:14:08 +0100 Subject: Introduce `Kind` in `core::clipboard` --- runtime/src/clipboard.rs | 49 ++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'runtime/src/clipboard.rs') diff --git a/runtime/src/clipboard.rs b/runtime/src/clipboard.rs index 49044a0f..dd47c47d 100644 --- a/runtime/src/clipboard.rs +++ b/runtime/src/clipboard.rs @@ -1,5 +1,6 @@ //! Access the clipboard. use crate::command::{self, Command}; +use crate::core::clipboard::Kind; use crate::futures::MaybeSend; use std::fmt; @@ -9,10 +10,10 @@ use std::fmt; /// [`Command`]: crate::Command pub enum Action { /// Read the clipboard and produce `T` with the result. - Read(Box) -> T>), + Read(Box) -> T>, Kind), /// Write the given contents to the clipboard. - Write(String), + Write(String, Kind), } impl Action { @@ -25,8 +26,10 @@ impl Action { T: 'static, { match self { - Self::Read(o) => Action::Read(Box::new(move |s| f(o(s)))), - Self::Write(content) => Action::Write(content), + Self::Read(o, target) => { + Action::Read(Box::new(move |s| f(o(s))), target) + } + Self::Write(content, target) => Action::Write(content, target), } } } @@ -34,8 +37,8 @@ impl Action { impl fmt::Debug for Action { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Read(_) => write!(f, "Action::Read"), - Self::Write(_) => write!(f, "Action::Write"), + Self::Read(_, target) => write!(f, "Action::Read{target:?}"), + Self::Write(_, target) => write!(f, "Action::Write({target:?})"), } } } @@ -44,24 +47,34 @@ impl fmt::Debug for Action { pub fn read( f: impl Fn(Option) -> Message + 'static, ) -> Command { - Command::single(command::Action::Clipboard(Action::Read(Box::new(f)))) + Command::single(command::Action::Clipboard(Action::Read( + Box::new(f), + Kind::Standard, + ))) } -/// Write the given contents to the clipboard. -pub fn write(contents: String) -> Command { - Command::single(command::Action::Clipboard(Action::Write(contents))) -} - -/// Read the current contents of primary. +/// Read the current contents of the primary clipboard. pub fn read_primary( f: impl Fn(Option) -> Message + 'static, ) -> Command { - Command::single(command::Action::ClipboardPrimary(Action::Read(Box::new( - f, - )))) + Command::single(command::Action::Clipboard(Action::Read( + Box::new(f), + Kind::Primary, + ))) +} + +/// Write the given contents to the clipboard. +pub fn write(contents: String) -> Command { + Command::single(command::Action::Clipboard(Action::Write( + contents, + Kind::Standard, + ))) } -/// Write the given contents to primary. +/// Write the given contents to the primary clipboard. pub fn write_primary(contents: String) -> Command { - Command::single(command::Action::ClipboardPrimary(Action::Write(contents))) + Command::single(command::Action::Clipboard(Action::Write( + contents, + Kind::Primary, + ))) } -- cgit