Add support for primary clipboard
This commit is contained in:
parent
7615b2240c
commit
4155edab8d
7 changed files with 96 additions and 1 deletions
|
|
@ -51,3 +51,17 @@ pub fn read<Message>(
|
|||
pub fn write<Message>(contents: String) -> Command<Message> {
|
||||
Command::single(command::Action::Clipboard(Action::Write(contents)))
|
||||
}
|
||||
|
||||
/// Read the current contents of primary.
|
||||
pub fn read_primary<Message>(
|
||||
f: impl Fn(Option<String>) -> Message + 'static,
|
||||
) -> Command<Message> {
|
||||
Command::single(command::Action::ClipboardPrimary(Action::Read(Box::new(
|
||||
f,
|
||||
))))
|
||||
}
|
||||
|
||||
/// Write the given contents to primary.
|
||||
pub fn write_primary<Message>(contents: String) -> Command<Message> {
|
||||
Command::single(command::Action::ClipboardPrimary(Action::Write(contents)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ 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>),
|
||||
|
||||
|
|
@ -66,6 +69,9 @@ 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) => {
|
||||
|
|
@ -88,6 +94,9 @@ 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:?})")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue