Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable (grey out) main menu when displaying modal window?

I load a custom file import window in my Cocoa app using:

[NSApp runModalForWindow:window];

The window displays just fine, and is modal.

However, the application main menu is still active (e.g. File menu and items), which is making the modal display redundant.

I've googled this, searched stackoverflow and cocoa-dev, and searched the Apple docs, but can't find a way to turn the menu off, or at least selected menu items.

Someone suggested using this:

NSModalSession session = [NSApp beginModalSessionForWindow:window];
[NSApp runModalSession];

but that doesn't seem to work either. Again, the window displays modally but the main menu is still active.

Can anyone suggest how I turn the main menu off (grey out menu items) when displaying a modal window please?

Is there a way to do this in one go at the menu-level, or do I need to turn off each individual menu item?

I must be missing the point somewhere, as this sort of menu behaviour is common in Cocoa apps.

Thanks

Darren.

like image 739
Darren Wheatley Avatar asked Sep 07 '25 18:09

Darren Wheatley


1 Answers

I needed to implement (in the AppDelegate) the following method:

- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem

Returning NO disables the referenced menu item.

All works fine now.

like image 101
Darren Wheatley Avatar answered Sep 09 '25 08:09

Darren Wheatley