How do I stop a WebView from disabling edit menu items instead of passing them on to my Window Controller?
In my NSDocument-based
application, my document's window just contains a WebView. I have defined cut: copy: paste: and delete: in my NSWindowController
subclass, which is otherwise functioning nicely, but those menu items are disabled for me unless there's something texty for WebView to do.
It seems like a violation of the rules of the resp开发者_JAVA技巧onder chain as I understand them; if you can't do something with it you should pass it along, but it seems the WebView wants to just disable the items for which it has defined methods and not play ball with my window controller. How do I get WebView to co-operate and yield respondership and UI validation to my controller when it doesn't have anything better to do with it?
The WebView
is allowed to do what it likes with the menu items, there's no contract that states it must pass the validation responsibility up the responder chain. In fact, it's quite possible that this would break a lot of apps that implement, for example, the copy:
method in their NSWindowController
or NSDocument
classes and are not expecting to have to deal with unhandled events from a WebView
.
You'll need to subclass WebView
and implement validateMenuItem:
. You can then control the menu validation for the methods you're interested in and call to super
for those you're not.
精彩评论