I'm trying to build an application that allows users to drag files from Finder to the menubar icon for processing. I've made progress in my journey, but I can't seem to summit this hill. I tried subclassing NSView and implementing the drag messages.
@interface CMDroppableView : NSView <NSMenuDelegate>
I wanted to not only accept drag operations, but to provide a NSMenu when the user clicks the icon. I've managed to get the NSMenu to display properly, but the drag functionality remains elusive.
It's my understanding that I needed to register the accepted drag types which I have done here:
-(void)awakeFromNib{
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
}
Drag messages:
-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
NSLog(@"Drag Enter");
return NSDragOperationCopy;
}
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender{
return NSDragOperationCopy;
}
-(void)draggingExited:(id <NSDraggingInfo>)sender{
NSLog(@"Drag Exit");
}
-(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender{
return YES;
}
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender{
return YES;
}
Here is the code where the custom view is set:
statusItemView = [[CMDroppableView alloc] init];
[statusItemView retain];
[statusItemView setMenu: statusMenu];
[statusItem setView: statusItemView];
Still nothing. So where have I gone wrong?
Thanks!