Start on copy-paste
This commit is contained in:
@@ -1215,6 +1215,10 @@ impl MutableAppContext {
|
||||
pub fn copy(&self, text: &str) {
|
||||
self.platform.copy(text);
|
||||
}
|
||||
|
||||
pub fn paste(&self) -> Option<String> {
|
||||
self.platform.paste()
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadModel for MutableAppContext {
|
||||
|
||||
@@ -26,6 +26,7 @@ use std::{
|
||||
path::PathBuf,
|
||||
ptr,
|
||||
rc::Rc,
|
||||
slice,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -299,6 +300,19 @@ impl platform::Platform for MacPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
fn paste(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let pasteboard = NSPasteboard::generalPasteboard(nil);
|
||||
let data = pasteboard.dataForType(NSPasteboardTypeString);
|
||||
if data == nil {
|
||||
None
|
||||
} else {
|
||||
let bytes = slice::from_raw_parts(data.bytes() as *mut u8, data.length() as usize);
|
||||
Some(String::from_utf8_unchecked(bytes.to_vec()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_menus(&self, menus: Vec<Menu>) {
|
||||
unsafe {
|
||||
let app: id = msg_send![APP_CLASS, sharedApplication];
|
||||
|
||||
@@ -43,6 +43,7 @@ pub trait Platform {
|
||||
fn prompt_for_paths(&self, options: PathPromptOptions) -> Option<Vec<PathBuf>>;
|
||||
fn quit(&self);
|
||||
fn copy(&self, text: &str);
|
||||
fn paste(&self) -> Option<String>;
|
||||
fn set_menus(&self, menus: Vec<Menu>);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,10 @@ impl super::Platform for Platform {
|
||||
}
|
||||
|
||||
fn copy(&self, _: &str) {}
|
||||
|
||||
fn paste(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
||||
Reference in New Issue
Block a user