Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show NSPopover from NSToolbarItem Button

I want to show an NSPopover from an NSToolbarItem button in my toolbar.
(i.e. positioned below the button).

Ideally, I want to pass the NSView of the button to the popover to position it.
My question is, how do I get the NSView of the NSToolbarItem?

[toolbarbutton view] always returns nil.

like image 470
Stuart Tevendale Avatar asked Nov 15 '11 20:11

Stuart Tevendale


2 Answers

The answer appears to be in the video for the 2011 WWDC Session 113, "Full Screen and Aqua Changes." Basically, put an NSButton inside the NSToolbaritem and use the view of that.

A blog post is here: http://www.yellowfield.co.uk/blog/?p=33, and a sample project is on github at http://github.com/tevendale/ToolbarPopover

All in the sprit of http://xkcd.com/979!

like image 183
Stuart Tevendale Avatar answered Oct 24 '22 00:10

Stuart Tevendale


You can send the action directly from the NSButton enclosed in the NSToolbarItem (which is what you should generally do anyways, consider segmented controls, where each segment has its own target/action), and that will do the trick.

like image 2
Tony Avatar answered Oct 24 '22 00:10

Tony