5

I am currently creating a macOS menubar for an app without using any interface builder (no XIB/NIB files), just pure code. However I was expecting some items to be auto-generated during the start-up of the app. Items like "Start Dictation", "Emoji & Symbols" under Edit menu were existing as well as the "Enter Full Screen" menu item under the View Menu. But when it comes to Window Menu nothing was automatically generated, only the menu items I've set in the code. Do I have to enable some flags or options when instantiating a Window NSMenu so it automatically generates those items? I am new to macOS development so I feel like I am kind of lost. Thanks in advance.

5
  • Note that the Window and Help menus are a little special in that they have their own NSApplication properties, so make sure to set them to your menus, otherwise the system won't know to treat them differently. Commented Oct 6, 2020 at 21:44
  • 1
    @red_menace, you mean this one?(developer.apple.com/documentation/appkit/nsapplication/…). Okay let me try it out. Thanks! Commented Oct 7, 2020 at 12:36
  • Yes, that's the one. If you just create a Window menu and add it to the main, all you will get is what you have provided. If you create a Window menu and also set it as NSApp's windowsMenu, in addition you will get all the windowy goodness that the OS provides. Commented Oct 7, 2020 at 12:46
  • @red_menace, so cool it works, thanks man! Here's what I did: 1. Create the normal Window NSMenu (same way as I did before) 2. Tag the Window NSMenu as the windowsMenu of the NSApp [NSApp setWindowsMenu: window]; // assuming "window" is properly instantiated 3. Populate the Window NSMenu with NSMenuItems and so on... Commented Oct 7, 2020 at 13:39
  • @red_menace Please add your comment as the answer. Had the same question and the answer is definitely not obvious though it's just a link to the right documentation. Commented Dec 30, 2022 at 14:37

1 Answer 1

1

The Window and Help menus are a little special in that they have their own NSApplication properties, so you will need to set them to your menus so that the system will know what they are.

For example, if you just create a window menu and add it to the main, all you will get are the items that you have provided. If you also set it as the application’s windowsMenu, in addition you will get all the stuff for moving, tab support, etc.

Setting NSApp’s helpMenu is similar, where a Spotlight menu item is added to the menu.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.