First this is not a tutorial for NSPopover . Just fix for an issue.
Apple introduced NSPopover in OS X v10.7
NSPopover class provides a means to display additional content related to existing content on the screen. The popover is positioned relative to the existing content.
An anchor is used to express the relation between these two units of content. A popover has an appearance that specifies its visual characteristics, as well as a behavior that determines which user interactions will cause the popover to close. …….
But it seems Apple never intended for the NSPopover to be used in a NSStatusBar menu item. Those are the little menu icons in you menu bar that when you click show you info or perform an action. This is probably why Apple has not fixed the bugs when using a popover in this way.
The main problem I was having was my popover was not closing when I clicked else where if I had not clicked on the popover first. I.e click the menu status item. The popover pops out. click somewhere else ( another app, finder). The popover stays open. If I then click the popover and then elsewhere it would close ok. Because it had picked up in becoming the key window after the second click.
This behaviour I discovered from a post on blog.brokenrobotllc.com was partly due to me subclassing NSWindow so the popover could become key and allow the content to become first responder. i.e the textfield. But when the popover closes we want it to revert back to it’s original behaviour. This subclass was done because in my popover is a text field. Which if the NSWindow does not become key, you will not be able to interact with it. Thats one of the other problems.
As alway these things happen while in the shower and this was no exception !
The simple thought was this: ” well clearly I have to click on the popover to activate it so it can become key again ”
When put like that the fix becomes simple. I need to put in some code that when I click the menu status item. The App (popover) is activated.
I first used an NSApplescript. But then remembered I could simply use:
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
[iframe /blogR/activateApp.html 700 400]
And it works.. well for me at least.