tray: Support file-drop from OS X Dock

A long-standing Apple bug does not call `prepareForDragOperation:sender`
for file drag-and-drop operations from the Dock. So we manually
call our custom `handleDrop:sender` for all drag-and-drop cases (that
is, from the Dock and from Finder).

References to the bug in question:
- http://stackoverflow.com/q/9534543/3309046
- http://openradar.appspot.com/radar?id=1745403

However, we still need to return YES from `prepareForDragOperation:sender`,
otherwise the "drag failed" animation occurs. For the same reason, we also
return YES from `performDragOperation:sender`.
This commit is contained in:
Nishanth Shanmugham 2015-12-29 03:25:21 -06:00
parent 5f3c6107d5
commit 2bbf86c524

View file

@ -281,14 +281,14 @@ const CGFloat kVerticalTitleMargin = 2;
- (void)draggingEnded:(id <NSDraggingInfo>)sender {
trayIcon_->NotifyDragEnded();
if (NSPointInRect([sender draggingLocation], self.frame)) {
trayIcon_->NotifyDrop();
[self handleDrop:sender];
}
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
trayIcon_->NotifyDrop();
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
- (BOOL)handleDrop:(id <NSDraggingInfo>)sender {
NSPasteboard* pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
@ -302,6 +302,14 @@ const CGFloat kVerticalTitleMargin = 2;
return NO;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
return YES;
}
- (BOOL)shouldHighlight {
if (isHighlightEnable_ && forceHighlight_)
return true;