What's a good way to bind from a shared utility window and the frontmost document window?

眉间皱痕 提交于 2019-12-04 00:37:31

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.

Leopard's TextEdit does this for its inspector. Check it out in file:///Developer/Examples/AppKit/TextEdit.

  • put an object controller in my nib for the shared window. When a document window changes frontmost status, change the content of that binding.

That makes the most sense to me. You'd change the content to the document instance ([NSDocumentController currentDocument]).

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!

Huh? I don't understand this.

Leopard's TextEdit does this for its inspector. Check it out in >file:///Developer/Examples/AppKit/TextEdit.

In TextEdit, inspector values are bound via an intermediate object controller. The controller content object is bound to the shared application mainWindow.

You may bind the content to mainWindow.firstResponder and uncheck "Raises for not applicable keys".

Use the key window, not the main window. KVO might not be supported for NSApplication's keyWindow property, but you can still use NSNotifications if it doesn't work. The reason for this is that NSDocumentController's currentDocument uses the keyWindow, so it better represents the built in functionality. Also, panels can be set to avoid becoming key window.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!