Remove tab-related functions from Window menu?

183 views Asked by At

I'm customizing the menus in my Mac Catalyst app. I've added two items, as you can see in the following screen shot ("Set Window Size" and "Open Separate Document Viewer"). But I want to get rid of the default menu items that appear between these two items (the four tab-related functions).

screen shot of my Window menu

In buildMenuWithBuilder, I can remove some items (child menus) like this:

[builder removeMenuForIdentifier:UIMenuMinimizeAndZoom];

But there is no defined identifier for the child menu containing the tab functions. More significantly, it doesn't yet exist when buildMenuWithBuilder runs. If I put this code at the end of that method...

UIMenu *test = [builder menuForIdentifier:UIMenuWindow];
NSArray *test2 = [test children];

...then test2 contains only two default menus, UIMenuMinimizeAndZoom and UIMenuBringAllToFront, plus my custom menus. So even if I had its identifier, I suspect removing it here would have no effect.

More oddly, it appears between my two custom menus, even though I'm adding those one after the other with insertChildMenu:atStartOfMenuForIdentifier:.

Finally, I noticed that when I open a second scene (in a new Mac window), these tab options disappear from the Window menu and don't come back. It seems that macOS is initially deciding these functions could be relevant to my app, but then when I open a scene, it decides they're not relevant and removes them. So I'm wondering if there is a way to tell macOS from the start not to include these menu items?

I thought this might be related to the NSWindow property tabbingMode, but setting my main window to NSWindowTabbingModeDisallowed makes no difference. My only Mac development experience is through Mac Catalyst, so I don't know what else to try.

1

There are 1 answers

1
Adam On BEST ANSWER

I think if you disable tabs completely, they’ll go away. This is a bit of a hack because you need to call AppKit code, but an Apple engineer gave it to me:

Class _nswindow = NSClassFromString(@"NSWindow"); [_nswindow setAllowsAutomaticWindowTabbing:NO];