views:

140

answers:

1

I have an NSPopUpButton providing the NSMenu for a status item with a custom view. The popup button displays a list of links. When the user selects a link from the list, the link is displayed in the user's browser (in the background).

Naturally, the menu closes every time the user selects a link.

I would like to change this: I want the menu to stay open while the user clicks on various links, all of which can be opened in the background. The menu can then go away when the user clicks elsewhere.

How can this be accomplished? Should I subclass NSMenuItem and intercept the mouse clicks somehow? Overlay a transparent NSView on the popped-up menu and, again, intercept the clicks somehow? I make these suggestions blithely, but I would have trouble implementing either of these...pointers to the right methods for override would be appreciated.

A: 

Usually you should not bend a control too far past it's original intent. Users expect pop up buttons to close after making a selection. I don't think you should, or can, force NSPopUpButtonCell to behave in this way. If you do, you'll be subclassing and modifying the control so heavily that it might change/break with a future version of Mac OS X. You'd also have to worry about the usability problem of users thinking the menu will close after making a selection.

You might consider writing you're own subclass of NSView to work like the menu button you're describing. After the user clicks on the button. You'll want to create a new NSWindow, with no border by using NSBorderlessWindowMask as the style mask. The content view of that window should be another custom view of yours that you implement the menu selection in.

Jon Hess
Thanks for the comment. I'd certainly consider writing my own subclass of NSView. It semms like a royal pain, however, to deal with all the submenus, images, on/off states, etc. that come with the NSPopUpButtonCell/NSMenu combination for free.So...I can appreciate that writing my own NSView is one way to do this, but I frankly think that if I imitate NSPopUpButton exactly but just change the behavior I want to change--then I might just as well go ahead and "bend [the] control too far past it's original intent"! I mean, the result is the same, so it seems senseless to stand on ceremony.
Dennis