diff options
author | Neil Hodgson <nyamatongwe@gmail.com> | 2023-02-24 10:25:54 +1100 |
---|---|---|
committer | Neil Hodgson <nyamatongwe@gmail.com> | 2023-02-24 10:25:54 +1100 |
commit | 778dc10b3ee2f621d8548b1d074429c44bd3ae62 (patch) | |
tree | 9f7e7b2dbefc838c93092e6be9d8ae8a2f8d2ebf /cocoa | |
parent | d75ac05416e341c02195260d1106a17932a3032f (diff) | |
download | scintilla-mirror-778dc10b3ee2f621d8548b1d074429c44bd3ae62.tar.gz |
On macOS 10.13+, use new NSPasteboardTypeFileURL type to receive files dragged
onto Scintilla but continue using NSFilenamesPboardType on older systems.
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 52 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 10 |
2 files changed, 47 insertions, 15 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index c12bf3efb..884a976d0 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -1563,8 +1563,16 @@ NSDragOperation ScintillaCocoa::DraggingUpdated(id <NSDraggingInfo> info) { [pasteboard.types containsObject: ScintillaRecPboardType]) return (sourceDragMask & NSDragOperationMove) ? NSDragOperationMove : NSDragOperationCopy; - if ([pasteboard.types containsObject: NSFilenamesPboardType]) - return (sourceDragMask & NSDragOperationGeneric); + if (@available(macOS 10.13, *)) { + if ([pasteboard.types containsObject: NSPasteboardTypeFileURL]) + return (sourceDragMask & NSDragOperationGeneric); + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if ([pasteboard.types containsObject: NSFilenamesPboardType]) + return (sourceDragMask & NSDragOperationGeneric); +#pragma clang diagnostic pop + } return NSDragOperationNone; } @@ -1588,21 +1596,37 @@ void ScintillaCocoa::DraggingExited(id <NSDraggingInfo> info) { bool ScintillaCocoa::PerformDragOperation(id <NSDraggingInfo> info) { NSPasteboard *pasteboard = [info draggingPasteboard]; - if ([pasteboard.types containsObject: NSFilenamesPboardType]) { - NSArray *files = [pasteboard propertyListForType: NSFilenamesPboardType]; - for (NSString* uri in files) - NotifyURIDropped(uri.UTF8String); + if (@available(macOS 10.13, *)) { + // NSPasteboardTypeFileURL is available for macOS 10.13+, provides NSURLs + if ([pasteboard.types containsObject: NSPasteboardTypeFileURL]) { + NSArray *files = [pasteboard readObjectsForClasses:@[NSURL.class] options:nil]; + for (NSURL *uri in files) { + NotifyURIDropped([uri path].UTF8String); + } + return true; + } } else { - SelectionText text; - GetPasteboardData(pasteboard, &text); + // Use deprecated NSFilenamesPboardType, provides NSStrings +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if ([pasteboard.types containsObject: NSFilenamesPboardType]) { + NSArray *files = [pasteboard propertyListForType: NSFilenamesPboardType]; + for (NSString *uri in files) { + NotifyURIDropped(uri.UTF8String); + } + } +#pragma clang diagnostic pop + } - if (text.Length() > 0) { - NSDragOperation operation = [info draggingSourceOperationMask]; - bool moving = (operation & NSDragOperationMove) != 0; + SelectionText text; + GetPasteboardData(pasteboard, &text); - DropAt(posDrag, text.Data(), text.Length(), moving, text.rectangular); - }; - } + if (text.Length() > 0) { + NSDragOperation operation = [info draggingSourceOperationMask]; + bool moving = (operation & NSDragOperationMove) != 0; + + DropAt(posDrag, text.Data(), text.Length(), moving, text.rectangular); + }; return true; } diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 1ca7ab8e2..ad074b496 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -235,7 +235,15 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) { trackingArea = nil; mMarkedTextRange = NSMakeRange(NSNotFound, 0); - [self registerForDraggedTypes: @[NSPasteboardTypeString, ScintillaRecPboardType, NSFilenamesPboardType]]; + if (@available(macOS 10.13, *)) { + [self registerForDraggedTypes: @[NSPasteboardTypeString, ScintillaRecPboardType, NSPasteboardTypeFileURL]]; + } else { + // Use old deprecated type +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [self registerForDraggedTypes: @[NSPasteboardTypeString, ScintillaRecPboardType, NSFilenamesPboardType]]; +#pragma clang diagnostic pop + } // Set up accessibility in the text role if ([self respondsToSelector: @selector(setAccessibilityElement:)]) { |