Add copy_to_clipboard.
This commit is contained in:
parent
7001c2521f
commit
ffdc278e97
|
@ -5,11 +5,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cocoa::appkit::{
|
use cocoa::appkit::{
|
||||||
NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreBuffered, NSView,
|
NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreBuffered,
|
||||||
NSWindow, NSWindowStyleMask,
|
NSPasteboard, NSView, NSWindow, NSWindowStyleMask,
|
||||||
};
|
};
|
||||||
use cocoa::base::{id, nil, NO, YES};
|
use cocoa::base::{id, nil, NO, YES};
|
||||||
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
|
use cocoa::foundation::{NSAutoreleasePool, NSData, NSPoint, NSRect, NSSize, NSString};
|
||||||
use core_foundation::runloop::{
|
use core_foundation::runloop::{
|
||||||
CFRunLoop, CFRunLoopTimer, CFRunLoopTimerContext, __CFRunLoopTimer, kCFRunLoopDefaultMode,
|
CFRunLoop, CFRunLoopTimer, CFRunLoopTimerContext, __CFRunLoopTimer, kCFRunLoopDefaultMode,
|
||||||
};
|
};
|
||||||
|
@ -483,3 +483,22 @@ unsafe impl HasRawWindowHandle for Window {
|
||||||
RawWindowHandle::AppKit(handle)
|
RawWindowHandle::AppKit(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum ClipboardDataType {
|
||||||
|
String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_to_clipboard(data: String, dataType: ClipboardDataType) {
|
||||||
|
unsafe {
|
||||||
|
let pb = NSPasteboard::generalPasteboard(nil);
|
||||||
|
|
||||||
|
let data =
|
||||||
|
NSData::dataWithBytes_length_(nil, data.as_ptr() as *const c_void, data.len() as u64);
|
||||||
|
|
||||||
|
let pb_type = match dataType {
|
||||||
|
ClipboardDataType::String => cocoa::appkit::NSPasteboardTypeString,
|
||||||
|
};
|
||||||
|
|
||||||
|
pb.setData_forType(data, pb_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue