Merge pull request #22685 from remmah/patch-1
Modernized copy/paste APIs on macOS #7185
This commit is contained in:
commit
da6646dd5e
|
@ -1859,28 +1859,30 @@ bool OS_OSX::can_draw() const {
|
|||
|
||||
void OS_OSX::set_clipboard(const String &p_text) {
|
||||
|
||||
NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
|
||||
NSString *copiedString = [NSString stringWithUTF8String:p_text.utf8().get_data()];
|
||||
NSArray *copiedStringArray = [NSArray arrayWithObject:copiedString];
|
||||
|
||||
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
||||
[pasteboard declareTypes:types owner:nil];
|
||||
[pasteboard setString:[NSString stringWithUTF8String:p_text.utf8().get_data()]
|
||||
forType:NSStringPboardType];
|
||||
[pasteboard clearContents];
|
||||
[pasteboard writeObjects:copiedStringArray];
|
||||
}
|
||||
|
||||
String OS_OSX::get_clipboard() const {
|
||||
|
||||
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
||||
NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
|
||||
NSDictionary *options = [NSDictionary dictionary];
|
||||
|
||||
if (![[pasteboard types] containsObject:NSStringPboardType]) {
|
||||
BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
|
||||
|
||||
if (!ok) {
|
||||
return "";
|
||||
}
|
||||
|
||||
NSString *object = [pasteboard stringForType:NSStringPboardType];
|
||||
if (!object) {
|
||||
return "";
|
||||
}
|
||||
NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
|
||||
NSString *string = [objectsToPaste objectAtIndex:0];
|
||||
|
||||
char *utfs = strdup([object UTF8String]);
|
||||
char *utfs = strdup([string UTF8String]);
|
||||
String ret;
|
||||
ret.parse_utf8(utfs);
|
||||
free(utfs);
|
||||
|
|
Loading…
Reference in New Issue