From 0f8558a72379338d615b9526b57e5185e6ed0665 Mon Sep 17 00:00:00 2001 From: Nyx0uf Date: Thu, 9 Jan 2014 14:42:43 +0100 Subject: cocoa: allow to drag and drop URLs This commit also improves the visual feedback to the user by showing a plus icon in the mouse cursor when dragging supported types. Fixes #469 --- video/out/cocoa/view.m | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/video/out/cocoa/view.m b/video/out/cocoa/view.m index 9fc7506fc6..f5b69a7fbc 100644 --- a/video/out/cocoa/view.m +++ b/video/out/cocoa/view.m @@ -33,7 +33,8 @@ - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { - [self registerForDraggedTypes:@[NSFilenamesPboardType]]; + [self registerForDraggedTypes:@[NSFilenamesPboardType, + NSURLPboardType]]; } return self; } @@ -234,14 +235,27 @@ - (NSDragOperation)draggingEntered:(id )sender { - return NSDragOperationEvery; + NSPasteboard *pboard = [sender draggingPasteboard]; + NSArray *types = [pboard types]; + if ([types containsObject:NSFilenamesPboardType] || + [types containsObject:NSURLPboardType]) + return NSDragOperationCopy; + else + return NSDragOperationNone; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *pboard = [sender draggingPasteboard]; - NSArray *pbitems = [pboard propertyListForType:NSFilenamesPboardType]; - [self.adapter handleFilesArray:pbitems]; - return YES; + if ([[pboard types] containsObject:NSURLPboardType]) { + NSURL *file_url = [NSURL URLFromPasteboard:pboard]; + [self.adapter handleFilesArray:@[[file_url absoluteString]]]; + return YES; + } else if ([[pboard types] containsObject:NSFilenamesPboardType]) { + NSArray *pbitems = [pboard propertyListForType:NSFilenamesPboardType]; + [self.adapter handleFilesArray:pbitems]; + return YES; + } + return NO; } @end -- cgit v1.2.3