Implement and expose read and write helpers for clipboard

This commit is contained in:
Héctor Ramón Jiménez 2021-09-02 15:12:55 +07:00
parent 6887afdb2c
commit 7a335a0408
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
4 changed files with 22 additions and 1 deletions

View file

@ -1,6 +1,8 @@
//! Access the clipboard.
pub use iced_native::clipboard::Action;
use crate::command::{self, Command};
/// A buffer for short-term storage and transfer within and between
/// applications.
#[allow(missing_debug_implementations)]
@ -55,3 +57,15 @@ impl iced_native::Clipboard for Clipboard {
self.write(contents)
}
}
/// 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)))
}