Adding Preferences... to extraAppleMenuItems in setMacMainMenu [Solved]

image

This is the “standard” place for preferences menu item on macOS, but it seems impossible to do exactly like this.

static void MenuBarModel::setMacMainMenu(MenuBarModel* newMenuBarModel,
                                         const PopupMenu* extraAppleMenuItems = nullptr,
                                         const String& recentItemsMenuName = String())

addCommandItem is not working in this extraAppleMenuItems, only addItem which doesn’t give any options for having a key short cut. Unless I’ve missed something?

This came up 14 years ago but unsurprisingly the example linked is now dead, and been unable to find anything else on the topic in here.

It seems to work fine in my WIP App… is that (in picture below) what you are expecting?

If yes, there’s a dummy project i did (long time ago) that seems to work fine also there:

1 Like

OK, I must be doing something stupid because I tried basically to add a normal item (“About”) followed by a separator and then the command item, but only the “About” item showed up in the “Apple” menu.

Thanks for posting the dummy project, that should help me work out where I’ve gone wrong.

Edit: Fixed the issue. I’m not sure why this was a problem though:

I had a PopupMenu member in a class that I added the items to in its constructor and then had a method to get a pointer to said PopupMenu. This doesn’t work, I thought because perhaps it was an order of initialisation issue and my ApplicationCommandTarget wasn’t yet set up, but that didn’t help.
However when I use the same arrangement that you have here then it all works (which I thought surprising as I figured you can’t just create a PopupMenu on the stack to pass a pointer to MenuBarModel::setMacMainMenu for scope reasons, but seems not an issue).

Thanks again for your help!

1 Like

I figure i did that after reading someone else code.
Lot’s of trial and error also by the way! :grin:
IIRC order of some application initialisations matters.
It’s not very obvious at first view but the PopupMenu is copied.

3 Likes