Snow Leopard 上的窗口关闭按钮劫持
我正在开发一个基于 NSDocument 的应用程序,每个窗口(选项卡)有多个文档。这意味着我需要自己处理窗口的关闭,以便我可以在窗口关闭之前查看属于该窗口的文档。为了做到这一点,我使用 standardWindowButton:NSWindowCloseButton
访问 NSWindow 的关闭按钮,并将该按钮的目标/操作设置为我的方法,而不是标准(和私有)_close:方法。
这在 Lion 上效果很好,但在 Snow Leopard 上却会引起问题。每当显示模式对话框时,关闭按钮就会按预期禁用。但是,当模式对话框被关闭时,在 Snow Leopard 上,关闭按钮永远不会重新启用。我尝试使用 [closeButton setEnabled:YES]
等以编程方式重新启用它,但它似乎没有任何效果。我已经确认,只有当我更改关闭按钮的目标/操作时才会发生这种情况。
关于如何避免 Snow Leopard 上的这种行为的任何想法,或者劫持关闭按钮的替代方法?控制工具栏按钮的启用状态的是什么?也许我可以覆盖那里的东西?
I'm working on an NSDocument-based app with multiple documents per window (tabs). This means I need to handle closing of windows myself so that I can review the documents belonging to the window before it's closed. In order to do this, I've accessed the NSWindow's close button using standardWindowButton:NSWindowCloseButton
and set the target/action of this button to my method instead of the standard (and private) _close:
method.
This works great on Lion, but on Snow Leopard it causes issues. Whenever a modal dialog is displayed, the close button gets disabled as expected. But when the modal dialog is dismissed, on Snow Leopard the close button never gets reenabled. I've tried reenabling it programmatically afterwards using [closeButton setEnabled:YES]
etc, but it doesn't seem to have any effect. I've confirmed that this only happens when I've changed the target/action of the close button.
Any ideas on how to avoid this behavior on Snow Leopard, or maybe an alternative way of hijacking the close button? What is it that controls the enabled state of the toolbar buttons? Maybe I could override something there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本以为你可以使用 windowShouldClose: 委托方法
将 windows 委托设置为 AppDelegate。在 AppDelegate 中,使用 windowShouldClose: 委托方法来调用 close 方法,并通过返回 NO 来停止窗口关闭。
在您的方法中进行所有检查,然后执行Close:窗口。看我的例子
I would have thought you could use windowShouldClose: delegate method
Set the windows delegate to the AppDelegate. And in the AppDelegate use the windowShouldClose: delegate method to call your close method and to stop the window closing by returning NO.
In your method do all your checking and then performClose: the window. See my example