Make primary clipboard Linux only (#11843)
I guess only Linux supports the primary clipboard. Release Notes: - N/A
This commit is contained in:
parent
1c62839295
commit
4ae3396253
7 changed files with 42 additions and 37 deletions
|
@ -547,6 +547,7 @@ impl AppContext {
|
|||
|
||||
/// Writes data to the primary selection buffer.
|
||||
/// Only available on Linux.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn write_to_primary(&self, item: ClipboardItem) {
|
||||
self.platform.write_to_primary(item)
|
||||
}
|
||||
|
@ -558,6 +559,7 @@ impl AppContext {
|
|||
|
||||
/// Reads data from the primary selection buffer.
|
||||
/// Only available on Linux.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn read_from_primary(&self) -> Option<ClipboardItem> {
|
||||
self.platform.read_from_primary()
|
||||
}
|
||||
|
|
|
@ -147,8 +147,10 @@ pub(crate) trait Platform: 'static {
|
|||
fn set_cursor_style(&self, style: CursorStyle);
|
||||
fn should_auto_hide_scrollbars(&self) -> bool;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn write_to_primary(&self, item: ClipboardItem);
|
||||
fn write_to_clipboard(&self, item: ClipboardItem);
|
||||
#[cfg(target_os = "linux")]
|
||||
fn read_from_primary(&self) -> Option<ClipboardItem>;
|
||||
fn read_from_clipboard(&self) -> Option<ClipboardItem>;
|
||||
|
||||
|
|
|
@ -817,8 +817,6 @@ impl Platform for MacPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_to_primary(&self, _item: ClipboardItem) {}
|
||||
|
||||
fn write_to_clipboard(&self, item: ClipboardItem) {
|
||||
let state = self.0.lock();
|
||||
unsafe {
|
||||
|
@ -856,10 +854,6 @@ impl Platform for MacPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_from_primary(&self) -> Option<ClipboardItem> {
|
||||
None
|
||||
}
|
||||
|
||||
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
|
||||
let state = self.0.lock();
|
||||
unsafe {
|
||||
|
|
|
@ -23,6 +23,7 @@ pub(crate) struct TestPlatform {
|
|||
active_display: Rc<dyn PlatformDisplay>,
|
||||
active_cursor: Mutex<CursorStyle>,
|
||||
current_clipboard_item: Mutex<Option<ClipboardItem>>,
|
||||
#[cfg(target_os = "linux")]
|
||||
current_primary_item: Mutex<Option<ClipboardItem>>,
|
||||
pub(crate) prompts: RefCell<TestPrompts>,
|
||||
pub opened_url: RefCell<Option<String>>,
|
||||
|
@ -45,6 +46,7 @@ impl TestPlatform {
|
|||
active_display: Rc::new(TestDisplay::new()),
|
||||
active_window: Default::default(),
|
||||
current_clipboard_item: Mutex::new(None),
|
||||
#[cfg(target_os = "linux")]
|
||||
current_primary_item: Mutex::new(None),
|
||||
weak: weak.clone(),
|
||||
opened_url: Default::default(),
|
||||
|
@ -272,6 +274,7 @@ impl Platform for TestPlatform {
|
|||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn write_to_primary(&self, item: ClipboardItem) {
|
||||
*self.current_primary_item.lock() = Some(item);
|
||||
}
|
||||
|
@ -280,6 +283,7 @@ impl Platform for TestPlatform {
|
|||
*self.current_clipboard_item.lock() = Some(item);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn read_from_primary(&self) -> Option<ClipboardItem> {
|
||||
self.current_primary_item.lock().clone()
|
||||
}
|
||||
|
|
|
@ -625,8 +625,6 @@ impl Platform for WindowsPlatform {
|
|||
false
|
||||
}
|
||||
|
||||
fn write_to_primary(&self, _item: ClipboardItem) {}
|
||||
|
||||
fn write_to_clipboard(&self, item: ClipboardItem) {
|
||||
if item.text.len() > 0 {
|
||||
let mut ctx = ClipboardContext::new().unwrap();
|
||||
|
@ -634,10 +632,6 @@ impl Platform for WindowsPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_from_primary(&self) -> Option<ClipboardItem> {
|
||||
None
|
||||
}
|
||||
|
||||
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
|
||||
let mut ctx = ClipboardContext::new().unwrap();
|
||||
let content = ctx.get_contents().ok()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue