cocoa document based app with shared windows?

Discussion in 'Mac Programming' started by Dr144, Oct 31, 2010.

  1. Dr144 macrumors newbie


    Oct 6, 2010
    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)?

  2. ritsard macrumors regular


    Jun 18, 2009
    SF Bay Area, CA
    can you elaborate what you mean on shared views?
  3. robbieduncan Moderator emeritus


    Jul 24, 2002
    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).
  4. Comrade Yeti macrumors newbie

    Nov 3, 2010
    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]'
  5. Sydde macrumors 68020


    Aug 17, 2009
    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.

Share This Page