Best practice for multiple NSWindowControllers on a document?

  • Hi All

    I was wondering about the recommended way to notify multiple window
    controllers of a change to a document.  Bindings are not being used.
    Neither is the undo manager.  The changes can occur from any of the
    window controllers, or programmatically.  Thanks in advance for any
    advice offered.

    Regards,

    David
  • Well, I have this type of architecture, but my documents are immutable.

    That said, it would appear to me that since you **know** all the
    controllers, you could send each a message saying the document
    changed, and let them deal with it, e.g. documentUpdated.

    Since they are in an array you can use one of those
    makeObjectsPerformSelector methods of NSArray to efficiently send
    this to each window controller. (You can also roll your own
    specialized versions of makeObjectsPerformSelector and add them as a
    category - several examples of this on the web).

    You could get more detailed with different messages conveying
    different change notifications, ie
    setDocumentTextUpdatedInRange:SomeRange, etc.

    My suggestion is to avoid bindings and notifications, since the
    target of the messages, that is the array of windowControllers, is
    always known and in fact a property of your NSDocument subclass.

    Just my $0.02.

    David
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today