什么是从共享实用程序窗口和最前面的文档窗口绑定的好方法? [英] What's a good way to bind from a shared utility window and the frontmost document window?

查看:129
本文介绍了什么是从共享实用程序窗口和最前面的文档窗口绑定的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序允许打开多个NSDocuments。在这个应用程序是一个单一的实用程序窗口,其中包含一些功能,我想应用于最前面的文档。

I have an application which allows for multiple NSDocuments to be open. In this application is a single utility window that contains some functionality that I want to apply to the frontmost document.

我试图在这里使用绑定,所以诀窍是如何以将实用程序窗口的用户界面干净地绑定到最前面的文档。目标是,然后切换最前面的文档窗口将更新实用程序窗口中的视图;绑定到最前面的文档模型的属性的控件将在文档模型中的状态更改时适当更新。

I am trying to use bindings here, so the trick is how to cleanly bind the user interface of the utility window to the frontmost document. The goal is that then switching the frontmost document window will update the view in the utility window; controls that are bound to properties of the frontmost document's model would be updated appropriately when state changes in the document's model, etc.

对于从这样的窗口发送操作,只使用第一反应者;文档对象可以通过响应者链拦截动作。但我想要的不止这些,当然你不能绑定到第一个响应者。

For sending actions from such a window, it's easy to just use first responder; the document object can intercept actions via the responder chain. But I want more than this, and of course you can't bind to the first responder.

我有几个想法:


  • 在我的nib中为共享窗口放置一个对象控制器。当文档窗口更改最前面状态时,请更改该绑定的内容。这样做的一个缺点是,如果我有另一种实用程序窗口,我必须记住从文档窗口绑定到该实用程序窗口!

  • Make应用程序委托中的访问器,通过遍历窗口列表获取最前面的文档窗口。我的实用程序窗口只会通过应用程序委托的方法绑定。这里的一个缺点是它不符合KVO标准

  • 在应用程序委托中有一个getter和setter来确定(并且可能设置为KVO兼容? 。也许使用窗口通知设置一个ivar到适当的值,当窗口失去主要状态。 更新:我现在使用这个,它实际上看起来很干净。我从我的文档窗口的 windowDidBecomeMain 通知中设置值,并在 windowWillClose 中清除它(如果它是当前值)。除非有任何重大的反对,这可能是我将使用的方法。

  • 一个想法是绑定到mainWindow.windowController.document ...这接近,除了当我的共享窗口变为主,然后这个绑定消失。因此,我需要找到最前面的文档窗口的控制器(和正确的类)。

  • put an object controller in my nib for the shared window. When a document window changes frontmost status, change the content of that binding. A disadvantage of this is that if I were to have another kind of utility window, I'd have to remember to hook up the bindings from the document window to that utility window too!
  • Make an accessor in the application delegate that gets the frontmost document window by traversing the window list. My utility window would just bind through the application delegate's method. A disadvantage here is that it's not KVO compliant
  • Have a getter and setter in the application delegate to determine (and perhaps set to be KVO-compliant? would that make sense?) the frontmost document. Perhaps use window notifications set an ivar to the appropriate value when a window loses main status. Update: I'm using this for now, and it actually seems pretty clean. I set the value from the windowDidBecomeMain notification of my doc window and clear it (if it's the current value) in windowWillClose. Unless there is any major objection, this is probably the approach I'll use.
  • One idea was to bind to mainWindow.windowController.document ... this comes close, except that when my shared window becomes main, then this binding goes away. So really I need to find the frontmost document window's controller (and of the right class).

无的这些似乎是对的。有没有更好的方法来做到这一点,我错过了?

None of these seem quite right. Is there a better way to do this that I'm missing?

推荐答案

我一直绑定通过共享应用程序, mainWindow.document ,这工作正常。如果你有windows w / o文档,你可能想添加一个 mainYourKindOfWindow 键,通过观察 mainWindow 根据一些过滤条件更新该值。

I’ve always bound through Shared Application, mainWindow.document, which works fine. if you have windows w/o documents, you may want to add a mainYourKindOfWindow key that is implemented by watching mainWindow and updating the value based on some filter criteria.

这篇关于什么是从共享实用程序窗口和最前面的文档窗口绑定的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆