diff options
| author | 2024-02-13 03:14:08 +0100 | |
|---|---|---|
| committer | 2024-02-13 03:15:21 +0100 | |
| commit | 508b3fe1f1405bdb8b860d0d63e2c7adfbbd51ca (patch) | |
| tree | 0419f7eb42b0647a47d71ba3615eb15ad456aa3e /runtime | |
| parent | 4155edab8d123b767ddad67e24ca2d4c50f31ece (diff) | |
| download | iced-508b3fe1f1405bdb8b860d0d63e2c7adfbbd51ca.tar.gz iced-508b3fe1f1405bdb8b860d0d63e2c7adfbbd51ca.tar.bz2 iced-508b3fe1f1405bdb8b860d0d63e2c7adfbbd51ca.zip  | |
Introduce `Kind` in `core::clipboard`
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/src/clipboard.rs | 49 | ||||
| -rw-r--r-- | runtime/src/command/action.rs | 9 | 
2 files changed, 31 insertions, 27 deletions
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<T> {      /// Read the clipboard and produce `T` with the result. -    Read(Box<dyn Fn(Option<String>) -> T>), +    Read(Box<dyn Fn(Option<String>) -> T>, Kind),      /// Write the given contents to the clipboard. -    Write(String), +    Write(String, Kind),  }  impl<T> Action<T> { @@ -25,8 +26,10 @@ impl<T> Action<T> {          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<T> Action<T> {  impl<T> fmt::Debug for Action<T> {      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<T> fmt::Debug for Action<T> {  pub fn read<Message>(      f: impl Fn(Option<String>) -> Message + 'static,  ) -> Command<Message> { -    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<Message>(contents: String) -> Command<Message> { -    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<Message>(      f: impl Fn(Option<String>) -> Message + 'static,  ) -> Command<Message> { -    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<Message>(contents: String) -> Command<Message> { +    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<Message>(contents: String) -> Command<Message> { -    Command::single(command::Action::ClipboardPrimary(Action::Write(contents))) +    Command::single(command::Action::Clipboard(Action::Write( +        contents, +        Kind::Primary, +    )))  } diff --git a/runtime/src/command/action.rs b/runtime/src/command/action.rs index f04c642c..c9ffe801 100644 --- a/runtime/src/command/action.rs +++ b/runtime/src/command/action.rs @@ -26,9 +26,6 @@ pub enum Action<T> {      /// Run a clipboard action.      Clipboard(clipboard::Action<T>), -    /// Run a clipboard action on primary. -    ClipboardPrimary(clipboard::Action<T>), -      /// Run a window action.      Window(window::Action<T>), @@ -69,9 +66,6 @@ impl<T> Action<T> {              Self::Future(future) => Action::Future(Box::pin(future.map(f))),              Self::Stream(stream) => Action::Stream(Box::pin(stream.map(f))),              Self::Clipboard(action) => Action::Clipboard(action.map(f)), -            Self::ClipboardPrimary(action) => { -                Action::ClipboardPrimary(action.map(f)) -            }              Self::Window(window) => Action::Window(window.map(f)),              Self::System(system) => Action::System(system.map(f)),              Self::Widget(operation) => { @@ -94,9 +88,6 @@ impl<T> fmt::Debug for Action<T> {              Self::Clipboard(action) => {                  write!(f, "Action::Clipboard({action:?})")              } -            Self::ClipboardPrimary(action) => { -                write!(f, "Action::ClipboardPrimary({action:?})") -            }              Self::Window(action) => {                  write!(f, "Action::Window({action:?})")              }  | 
