macOS main menu sub items don't show - macos

I'm using storyboard to create a macOS app.
For some reason, when running the app, the sub-menu item doesn't show up at all.
The item is enabled and hooked to the first responder just like the original demo items.

Did you drag one of the special menus by mistake? The Clear Menu item makes me wonder if the menu started life as a Recent Items menu and perhaps the change didn't take. You can tell by opening your storyboard as source code and checking for the systemMenu attribute on your Scale menu:
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="...">

Related

How to enable auto generation of Window MenuItems (e.g. Tile Window to Left/Right of Screen and Open file with checkmark) in macOS menubar

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.
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.

Adding static items to "Windows" menu in Cocoa application

I have a application with 2 windows (think like Twitter Timeline and mentions). For now I have been having the menus "Timeline ⌘1" and "Mentions ⌘2" in the "File" menu but this is kind of wrong. So I moved them to the "Windows" menu just by drag and drop.
When I open the application everything is nice, I can see both menu items unter the "Windows" menu. But then when I close for example the Mentions window the menu Item "Mentions ⌘2" disappears and I am not able to open this window anymore.
I have had a look at other applications and most of them have their Menu items to show the windows in the "Windows" menu and they don't disappear either after closing the windows. I am aware of the fact that Cocoa does soma magic with the "Window" menu item and it is quite ok in doing so (because I open some other windows which need to appear and disappear from there), but how can I make those two items kind of static so they don't disappear?
I finally found an answer, in order for them to not be handled by the Windows menu you need to call
[timelineViewWindow setExcludedFromWindowsMenu:YES];
[mentionsViewWindow setExcludedFromWindowsMenu:YES];
and after that add the Menu items to the Windows menu and they will not disappear anymore.

How can I get to the menu bar in my app in interface builder

XCode works in mysterious ways (at least to me).
I simply want to create a Preference pane in my app. When I run my app, the stock menu bar comes up (Apple, MyApp, File, Edit...) and the "Preferences" menu item is grayed out. It makes sense since I haven't started playing with it.
How on earth do I add/remove/activate/inactivate menu items? I'm not talking about adding anything new, simply using what should be there.
Thanks in advance.
NSMenu has "Auto Enable Items" enabled by default. That means if the menu item does not have it's action message hooked up, it will appear grayed out. So in your case, you would simply set the Preferences menu item's "Sent Action" to whatever action shows your preferences window. This can be hooked to some sort of showPreferencesWindow: method of your AppDelegate, or directly to the showWindow: method of a window controller.
To dynamically enable/disable menu items the best way is to implement the NSUserInterfaceItemValidation protocol which is excellently documented here
Edit: Your app's menu bar items live in the MainMenu.xib file. The menu bar appears as a "Main Menu" object on the left hand side (if you're using Xcode 4) Simply click on the items to modify them, and you can Ctrl+drag connections to and from them like any UI object.

update statusbar menu on click mac os x cocoa

I've been playing around with a statusbar menu app and what I'd like it to do is to update the content of the menu when it is clicked. I've been able to get everything working on the awakefromnib function and it works as expected. Now i just want to update the menu everytime I click on the status bar. This surely can be done, since it's done in the dropbox statusbar menu and many of the native app statusbar menus. I'm not able to associate a action directly with the click of the menu and I don't want to leave a loop running in the background cause I don't really see a need for it. Any ideas? An alternative would be to have an action associated to a menu item which does not cause the menu to get hidden again. Any help would be welcome.
Just set a delegate for your menu, and implement the -(void)menuWillOpen:(NSMenu *)menu method.

Does Apples UI define Drag&Drop in menus and/or context menus for menu items

I'm trying to update my GUI a little bit but don't want to run into porting problems later next year when a native Cocoa Port will be started.
On Windows/Linux it is common to drag items out of menus or being able to right click on a menu item and display a context menu for this menu item.
Is there anything like this on MacOSX.
Well, you can put a view into a menu item, and you can drag from a view, but I don't know whether those two will work together (i.e., whether you can drag from a view that's in a menu item).
More importantly, this isn't normal on the Mac, so you need another place to drag the item from regardless of whether you can support dragging from the menu or not.

Resources