views:

29

answers:

1

Hello all!

I have a multidocument application.

I want to pull data from each of those documents and mirror a subset of the data into a global 'management' HUD window that can sit on another screen.

Do I need a global object of my HudController in each document instance or is there a way I can delegate all the info from the various documents to the HudController as its own instance?

thanks for any help!

+1  A: 

is there a way I can delegate all the info from the various documents to the HudController as its own instance?

This is one case where a singleton is appropriate. There are a few other examples of similar panels; the Font Panel and Color Panel both work in a similar way. So, make your HudController a singleton (I have suggestions on how best to do that).

Then, have the HudController monitor the documents for changes. Details will vary, but you'll probably want to give the document class(es) public properties through which to access the model, then have the HudController watch for document windows being opened and closed; when one of those happens, have the HudController begin or end observing those properties of each window's matching document.

As long as you change the values of the properties in a KVO-compatible way, the change will cause a notification to the HudController automatically, whereupon you'll respond to the change by updating what you display in the HUD window.

Peter Hosey
thanks! also found this-> http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html
theprojectabot