1

When you let the application open a window (NSWindow), a command after the name of that window appears under the Window menu as shown below where one of the commands points to the main application window and the other points to the opened window.

enter image description here

Provided that I know the name of the window the user is going to show, how do I enable and disable that command? I suppose the following is not going to work.

- (void)closeGenericWindow {
    NSString *windowName = NSLocalizedString(@"controlListWindow",@"");
    NSMenuItem *windowMenuItem = [[NSMenuItem alloc] initWithTitle:windowName action:nil keyEquivalent:@""];
    [windowMenuItem setEnabled:NO];
}

I've run a search for '[objective-c] [cocoa] disable window.' I don't find anything relevant except this topic, which suggests that I create an IBOutlet in the header. But the command itself doesn't exist until the user actually chooses to open the window in question.

Muchos thankos

1 Answer 1

1

There are probably a couple of approaches to this:

  • First, you can set the window's excludedFromWindowsMenu property to YES to simply exclude the window from the menu.
  • Similarly, windows with no title do not appear in that menu.
  • Finally, you can override -canBecomeKeyWindow to return NO and that should disable that menu, I think. You may need to override -canBecomeMainWindow instead or in addition.
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, the excludedFromWindowsMenu property works. Muchos thankos.

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.