Lars C.Hassing
Lars C.Hassing

Reputation: 35

Cocoa menubar programmatically with NSMenu, how to get standard items "Services", "Hide App", "Hide Others", "Show All" etc

In decarbonizing I have now come to creating a menubar programmatically using NSMenu.

Carbon seems to be so nice to add standard items to the application menu: Services, Hide app, Hide Others, Show All, Quit app, and they are even added using the user’s Preferred Language setting in System Preferences’s Language & Region, so in German Hide Others is added as Andere ausblenden.

I only had to add the About and Preferences items.

However, it seems that in Cocoa I have to add these standard items myself, but how can I find out what Hide Others is called in the user’s Preferred Language ?

And what is the Cocoa equivalent of CreateStandardWindowMenu ?

Upvotes: 0

Views: 1028

Answers (1)

JWWalker
JWWalker

Reputation: 22707

If you have Xcode create a new Cocoa application project, it will make a MainMenu.xib that you can examine. It looks like "Hide Others", "Quit" etc. are just menu items with particular actions assigned, but "Services" seems to have some special magic. Even if you don't want to present a whole menu bar from a nib, you could load it from a nib and then pick out certain menu items and move them to another menu, rename them or whatever. Though I'm not sure I understand what you're trying to accomplish. Even if you don't want to localize, you can use a nib.

To address the last part of your revised question, the NSApplication object has a windowsMenu property, i.e., you could create a menu and say [NSApp setWindowsMenu: myMenu]. But I don't know if that adds items like Bring All to Front or if you must create those yourself.

Upvotes: 1

Related Questions