1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

cocoa document based app with shared windows?

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

  1. macrumors newbie

    Dr144

    #1
    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!
     
  2. macrumors member

    ritsard

    #2
    can you elaborate what you mean on shared views?
     
  3. Moderator

    robbieduncan

    Staff Member

    #3
    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. macrumors newbie

    #4
    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. macrumors 68000

    Sydde

    #5
    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