Native Mac menu bar doesn't dismiss Juce PopupMenus

It seems to me that using the native Mac menu should kill any current Juce PopupMenus. Currently you can open a PopupMenu, then move to the Mac Menu Bar, and open a menu there too. You now have two menus open.

Yes, it should, but I’m pretty sure that when I looked at this, I couldn’t find any way to actually get an event when the user opens the main menu… If anyone can suggest a way to get some kind of callback for that, I’ll certainly use it!

I think NSMenuDidBeginTrackingNotification is what you would need. According to the docs, it wasn’t publicly declared until OSX 10.5, so maybe it wasn’t there yet when you looked.

Here’s my code – I just figured out how to get it to work, and it was pretty easy. I put it in, but it can pretty much go in any .mm file, since it doesn’t actually need any local variables.

[code]@interface JuceMenuCallback

  • (void) menuNeedsUpdate: (NSMenu*) menu;
  • (void) trackingBegan: (NSNotification*) notification;
- (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trackingBegan:) name: NSMenuDidBeginTrackingNotification object:nil];

- (void) trackingBegan:(NSNotification *)notification { PopupMenu::dismissAllActiveMenus(); }

Aha, thanks! Well, that’s easy enough, I’ll check something in very soon…