Reputation: 4109
I have a cocoa application running on Mac OS 10.6.8 I am adding an entry to apple menu in the app, for quitting my application. The code is like this:
item = [menu addItemWithTitle: @"Quit Myapp" , NSLocalizedString(@"Quit", nil), applicationName] action:@selector(terminate:) keyEquivalent:@"q"];
[item setTarget:NSAPP];
Now, my problem is that when a modal dialog is opened using runModal
of NSOpenPanel
, this quit menu item is still enabled. Rest of the menu items are disabled as usual. I am not able to understand why.
If I change the above code so that menu item's target is not NSApp, but another cocoa object, then the problem disappears.
Could someone please let me know if it is a known issue. Is it wrong to set the NSApp as a menu item's target?
Upvotes: 0
Views: 763
Reputation: 90551
I agree with the others that doing this is probably a bad idea. That said, set (or leave) the target as nil
to target the responder chain. That will probably make it disable when a model window is up.
Update:
Hmm. Checking a new MainMenu NIB, I see that the Quit menu item does actually target the application object. So, that may not be the issue.
By the way, in the code snippets above, you're targeting NSAPP
, whatever that is, rather than NSApp
.
Also, the argument list to -addItemWithTitle:...
is all messed up and makes no sense. You should clean up your question to reflect actual code.
Upvotes: 0