mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Replace copypasta with arboard (#1475)
* Replace copypasta with arboard Closes https://github.com/emilk/egui/issues/1474 * Clean up deny.toml
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
/// Handles interfacing either with the OS clipboard.
|
||||
/// If the "clipboard" feature is off it will instead simulate the clipboard locally.
|
||||
pub struct Clipboard {
|
||||
#[cfg(feature = "copypasta")]
|
||||
copypasta: Option<copypasta::ClipboardContext>,
|
||||
#[cfg(feature = "arboard")]
|
||||
arboard: Option<arboard::Clipboard>,
|
||||
|
||||
/// Fallback manual clipboard.
|
||||
#[cfg(not(feature = "copypasta"))]
|
||||
#[cfg(not(feature = "arboard"))]
|
||||
clipboard: String,
|
||||
}
|
||||
|
||||
impl Default for Clipboard {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#[cfg(feature = "copypasta")]
|
||||
copypasta: init_copypasta(),
|
||||
#[cfg(feature = "arboard")]
|
||||
arboard: init_arboard(),
|
||||
|
||||
#[cfg(not(feature = "copypasta"))]
|
||||
#[cfg(not(feature = "arboard"))]
|
||||
clipboard: String::default(),
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,10 @@ impl Default for Clipboard {
|
||||
|
||||
impl Clipboard {
|
||||
pub fn get(&mut self) -> Option<String> {
|
||||
#[cfg(feature = "copypasta")]
|
||||
if let Some(clipboard) = &mut self.copypasta {
|
||||
use copypasta::ClipboardProvider as _;
|
||||
match clipboard.get_contents() {
|
||||
Ok(contents) => Some(contents),
|
||||
#[cfg(feature = "arboard")]
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
match clipboard.get_text() {
|
||||
Ok(text) => Some(text),
|
||||
Err(err) => {
|
||||
tracing::error!("Paste error: {}", err);
|
||||
None
|
||||
@@ -37,29 +36,28 @@ impl Clipboard {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "copypasta"))]
|
||||
#[cfg(not(feature = "arboard"))]
|
||||
Some(self.clipboard.clone())
|
||||
}
|
||||
|
||||
pub fn set(&mut self, text: String) {
|
||||
#[cfg(feature = "copypasta")]
|
||||
if let Some(clipboard) = &mut self.copypasta {
|
||||
use copypasta::ClipboardProvider as _;
|
||||
if let Err(err) = clipboard.set_contents(text) {
|
||||
#[cfg(feature = "arboard")]
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
if let Err(err) = clipboard.set_text(text) {
|
||||
tracing::error!("Copy/Cut error: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "copypasta"))]
|
||||
#[cfg(not(feature = "arboard"))]
|
||||
{
|
||||
self.clipboard = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "copypasta")]
|
||||
fn init_copypasta() -> Option<copypasta::ClipboardContext> {
|
||||
match copypasta::ClipboardContext::new() {
|
||||
#[cfg(feature = "arboard")]
|
||||
fn init_arboard() -> Option<arboard::Clipboard> {
|
||||
match arboard::Clipboard::new() {
|
||||
Ok(clipboard) => Some(clipboard),
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to initialize clipboard: {}", err);
|
||||
|
||||
Reference in New Issue
Block a user