开发者

Why cannot I open the Preferences from each windows?

开发者 https://www.devze.com 2023-01-23 16:50 出处:网络
I have come across this Cocoa application (source code) that shows a main Window. As long as this window is key it is possible to open the Preferences window from the Main menu as well as by hitting

I have come across this Cocoa application (source code) that shows a main Window.

As long as this window is key it is possible to open the Preferences window from the Main menu as well as by hitting Command-, but when the main window is n开发者_Python百科ot key and another window from the same app is, the NSMenuItem is grayed out and the keyboard shortcut does not respond.

I've inspected the xib file associated to the Main Menu and that NSMenuItem is sending a openPreferences:(id)sender IBAction to the FirstResponder which sould be the NSApplication.

What am I missing (I am still a newbie at mac cocoa programming)? How can I fix it so that the preferences are reachable from each application window?


Probably the original author implemented - (BOOL)validateMenuItem:(NSMenuItem *)menuItem and returns NO under some circumstances.

NSMenuValidationProtocol documentation.

Update: Another quick guess: Maybe the object that handles the IBAction for the menu item is not in the responder chain anymore after you open the second window. NSMenuItems are only enabled if the action selector can be found in the responder chain.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号