I am trying to create a Mac Application that has an NSStatusItem icon in the Status Bar. The status bar icon should support file drag and drop and must also show a menu when clicked.
The problem is that I have managed to achieve both functionalities separately and am having a hard time merging them together.
I was able to create a Status Bar Application using this link :
http://cocoatutorial.grapewave.com/2010/01/creating-a-status-bar-application/
And then I was able to achieve drag and drop functionality on the status bar icon using the following link
Drag and Drop with NSStatusItem
The problem that I am facing is as follows, in order to get drag and drop, I have to create another view and then assign that view to the NSStatusItem as shown below :
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
ViewWithDragFunctionality* viewWithDrag = [[ViewWithDragFunctionality alloc] initWithFrame:NSMakeRect(0, 0, 24, 24)];
[statusItem.view addSubview:viewWithDrag];
Since this is just a view, it does not, obviously, behave as the NSStatusItem's default view and does not support mouse interactions or anything else. I managed to find a way around that by adding the following function to ViewWithDragFunctionality.m
- (void)mouseDown:(NSEvent *)theEvent {
NSLog(@"Status Bar Icon Clicked");
}
The function is called whenever the status bar icon is clicked and file drag and drop is also being detected.
But now I am stuck with figuring out how to get the menu to display when clicking the status bar icon.
Any help will be much appreciated. I am working on a solution for this and will post it here if I find something first :)
Regards
Shumais