Fix #5161
This commit is contained in:
parent
313136803c
commit
609bcd68dd
@ -2482,30 +2482,15 @@ void _glfwPlatformSetClipboardString(const char* string)
|
|||||||
const char* _glfwPlatformGetClipboardString(void)
|
const char* _glfwPlatformGetClipboardString(void)
|
||||||
{
|
{
|
||||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
if (![[pasteboard types] containsObject:NSPasteboardTypeString])
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
||||||
"Cocoa: Failed to retrieve string from pasteboard");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString* object = [pasteboard stringForType:NSPasteboardTypeString];
|
|
||||||
if (!object)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
||||||
"Cocoa: Failed to retrieve object from pasteboard");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
free(_glfw.ns.clipboardString); _glfw.ns.clipboardString = NULL;
|
free(_glfw.ns.clipboardString); _glfw.ns.clipboardString = NULL;
|
||||||
|
|
||||||
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
|
NSDictionary* options = @{NSPasteboardURLReadingFileURLsOnlyKey:@YES};
|
||||||
NSArray* objs = [pasteboard readObjectsForClasses:@[[NSURL class], [NSString class]] options:options];
|
NSArray* objs = [pasteboard readObjectsForClasses:@[[NSURL class], [NSString class]] options:options];
|
||||||
if (!objs) return NULL;
|
if (objs) {
|
||||||
const NSUInteger count = [objs count];
|
const NSUInteger count = [objs count];
|
||||||
if (count) {
|
if (count) {
|
||||||
NSMutableString *path_list = [NSMutableString stringWithCapacity:4096]; // auto-released
|
NSMutableString *path_list = [NSMutableString stringWithCapacity:4096]; // auto-released
|
||||||
const char *text = NULL;
|
NSMutableString *text_list = [NSMutableString stringWithCapacity:4096]; // auto-released
|
||||||
for (NSUInteger i = 0; i < count; i++) {
|
for (NSUInteger i = 0; i < count; i++) {
|
||||||
id obj = objs[i];
|
id obj = objs[i];
|
||||||
if ([obj isKindOfClass:[NSURL class]]) {
|
if ([obj isKindOfClass:[NSURL class]]) {
|
||||||
@ -2515,12 +2500,17 @@ const char* _glfwPlatformGetClipboardString(void)
|
|||||||
[path_list appendString:@(url.fileSystemRepresentation)];
|
[path_list appendString:@(url.fileSystemRepresentation)];
|
||||||
}
|
}
|
||||||
} else if ([obj isKindOfClass:[NSString class]]) {
|
} else if ([obj isKindOfClass:[NSString class]]) {
|
||||||
text = [obj UTF8String];
|
if ([text_list length] > 0) [text_list appendString:@("\n")];
|
||||||
|
[text_list appendString:obj];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (path_list.length > 0) _glfw.ns.clipboardString = _glfw_strdup([path_list UTF8String]);
|
const char *text = NULL;
|
||||||
else if (text) _glfw.ns.clipboardString = _glfw_strdup([path_list UTF8String]);
|
if (path_list.length > 0) text = [path_list UTF8String];
|
||||||
|
else if (text_list.length > 0) text = [text_list UTF8String];
|
||||||
|
if (text) _glfw.ns.clipboardString = _glfw_strdup(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!_glfw.ns.clipboardString) _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to retrieve object from pasteboard");
|
||||||
return _glfw.ns.clipboardString;
|
return _glfw.ns.clipboardString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user