如何阻止 WebView 禁用编辑菜单项而不是将它们传递到我的窗口控制器?
在我的基于 NSDocument 的应用程序中,我的文档窗口仅包含一个 WebView。我在我的 NSWindowController 子类中定义了 cut: copy: Paste: 和 delete: ,否则它运行良好,但这些菜单项对我来说是禁用的,除非 WebView 需要做一些文本操作。
据我了解,这似乎违反了响应者链的规则;如果你不能用它做一些事情,你应该传递它,但似乎 WebView 只想禁用它已定义方法的项目,而不是与我的窗口控制器一起玩。当 WebView 没有更好的事情可以做时,如何让 WebView 合作并为我的控制器提供响应和 UI 验证?
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 responder 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WebView
可以对菜单项执行其喜欢的操作,没有任何契约规定它必须将验证责任传递到响应者链上。事实上,这很可能会破坏许多实现NSWindowController
或NSDocument
中的copy:
方法的应用程序。类,并且不期望必须处理来自WebView
的未处理事件。您需要子类化
WebView
并实现validateMenuItem:
。然后,您可以控制您感兴趣的方法的菜单验证,并为您不感兴趣的方法调用super
。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, thecopy:
method in theirNSWindowController
orNSDocument
classes and are not expecting to have to deal with unhandled events from aWebView
.You'll need to subclass
WebView
and implementvalidateMenuItem:
. You can then control the menu validation for the methods you're interested in and call tosuper
for those you're not.