NSStatusBar drag & drop with menu

2019-07-30 07:10发布

问题:

I'm familiar with the technique described here: Drag and Drop with NSStatusItem to make an NSStatusBar item that can handle file drag & drop.

What is the proper method for having a status bar item that supports both drag & drop and regular menu interactions, much like the Cloudapp icon does.

I want users to be able to left click the NSStatusItem to see the normal menu listing as well as allow for file drag and drop functionality.

It seems to me like I have to write all my own click handler code if I use a custom view on an NSStatusItem. So I'd have to detect clicks and display my menu items myself manually.

I just want to make sure there is no easier (or better) way before I start implementation.

回答1:

As far as I know you need the custom view on your NSStatusItem to handle the drag and drop. In this case it is easy, though, to add click handling to the view as well. You do not have to draw the menu yourself---if that is what you're asking---it should suffice to call - (void)popUpStatusItemMenu:(NSMenu *)menu on your NSStatusItem.