Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Dr144

macrumors newbie
Original poster
Oct 6, 2010
13
0
Hi All,

I'm developing a document based app. Each document has three windows (and hence three window controllers). I'd like to set it up so that two of the three windows are shared between different open documents (swapping views as needed). Is this possible? Can anyone point me in the right direction (documentation or examples)?

Thanks!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
When I've wanted to do this in the past (for an inspector say) I create a singleton class that controls the inspector panel. This ensures you only ever get one. That class registers for notifications that will be posted when the active window changes. When it receives one of them it updates with the values from the correct document (you can work that out fairly easily).
 

Comrade Yeti

macrumors newbie
Nov 3, 2010
26
0
Take the 2 'shared' views out of the document and make them singletons. Those two views can talk back and forth with the active document with bindings and notifications.

Look at the Sketch+Accessiblity sample from Apple, the main toolbar controller (SKTToolPaletteController) shows this singleton pattern with notifications when the tool is changed.

To bind to the current active document use 'Application.mainWindow.document.[property]'
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
Of course, you could subclass NSDocumentController, which is a singleton class, with ivars for the shared windows in it. Then, whatever is the delegate for a document window (probably the NSDocument subclass) will have a -windowDidBecomeMain: method in which it either gets the windows from the document controller subclass to change their source values, or the controller subclass itself can handle a change message from the document.

To create a subclass of NSDocumentController at the proper time, either instantiate the subclass in MainMenu.nib, or create it in the -applicationWillFinishLaunching: delegate method. The subclass will replace the NSDocumentController class because it directly inherits the +sharedDocumentController method and returns itself.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.