Search code examples
objective-cappkitnstoolbarnspopover

NSPopover with NSPopoverBehaviorSemitransient in toolbar not closing


I currently have three buttons in an NSToolbar (Mac OS X). Each of the buttons triggers a different NSPopover to appear relative to the button sending the action. That part works correctly. Two of the popovers use NSPopoverBehaviorTransient, one uses NSPopoverBehaviorSemitransient (because I specifically want it to stay open when switching between apps or moving the window).

When one of the Transient popovers is open and I click anywhere besides the popover itself, the popover closes correctly. The same goes for the Semitransient popover (aside from switching apps and moving the window) except if I click on another one of the toolbar buttons that shows another popover. In which case now both popovers are visible on the screen at the same time. (I suspect this is a bug.)

Screenshot of popovers onscreen at the same time.

I've tried investigating ways that I can initiate the closing myself if another toolbar button is pushed. The only option I've come up with is to keep track of the currently opened popover at the document level and make sure to manually close it before opening another one. I'd rather the Semitransient popover be able to close itself.

Is there something that I'm overlooking? Thanks.


Solution

  • The opaque definition of Semitransient behavior includes that Semitransient popovers will not close from an event (e.g. mouse click) that results in opening or closing another popover.

    A notable exception is that showing a Semitransient popover will cause other Semitransient popovers to close...


    So this is not a bug, just poorly defined behavior.

    Unfortunately, this means that if you want to use a mix of Semitransient & Transient popovers, you need to keep track of the shown popover at a higher level. An alternative would be to make all of the popovers Semitransient, and add in extra closing logic for specific popovers if your design requires that.

    It would be worth filing radars for (1) better, documented definitions of the Semitransient & Transient behaviors (2) deeper customization of these behaviors