如何阻止 WebView 禁用编辑菜单项而不是将它们传递到我的窗口控制器?

发布于 2024-11-19 09:04:50 字数 299 浏览 6 评论 0原文

在我的基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你是孤单的心事 2024-11-26 09:04:50

WebView 可以对菜单项执行其喜欢的操作,没有任何契约规定它必须将验证责任传递到响应者链上。事实上,这很可能会破坏许多实现 NSWindowControllerNSDocument 中的 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, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文