Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Graham Cox
While sometimes you simply have no choice but to loop through your  
windows, it isn't the first approach that comes to mind for this.


In the MVC design, you have separate views (one in each document) and  
separate controllers (each one referenced from each document 1:1) but  
what you do need is a single common data model that all of these  
controllers are referencing. Since this is common to all, it is a good  
choice for a singleton.


Then, when any view, via the controller, updates the model, all the  
other controllers get informed about the change (via KVO, bindings,  
notifications, whatever) and update their views accordingly. You  
should not need to loop through your windows and try and force an  
update, that's just trying to work around the MVC design instead of  
making proper use of it.


The singleton will have to be external to the nib since there is not  
one instance per doc, but one instance per app, and you'll have to  
make that connection as each nib is loaded. From then on, however the  
updates notifications are actually implemented, it will work correctly  
without further intervention on your part. If you find yourself  
thinking you need to manage collections of things yourself just to  
handle this sort of update notifications, chances are you've  
overlooked something obvious, since there are numerous built-in  
mechanisms available for handling just this, and very elegantly too.


--Graham



On 28/09/2009, at 4:19 AM, jon wrote:

ok,  after thinking and analyzing what was going on,  everytime i  
make a new document in the running app,   it created a new instance  
of the window and all related stuff in the window including  
myOutlineView.  and then my dataSource in code remained the same  
that fills out these outline views...   (atleast this is my current  
understanding).


so my question now morphs into:

  as Jens says below,  he in some cases is looping through the apps  
window list...


in my case,   in my main document xib,  i have an "outline  
Controller" which is type NStreeController...  and i have this  
defined..


IBOutlet NSTreeController *treeController  which is the thing that  
is controlling the outline view,  and appears to be the thing i want  
to update...


the question it appears to me is:  that this "treeController" also  
is made into multiple instances with each new Document,   is there  
an already defined "loop" of these?  (a list of the open document's  
NSTreeController *treeController;)


or do i need to make an NSMutableArray,  and keep track of these  
myself?   and then update these instances myself by looping through  
them?




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 11:19 AM, jon wrote:

the question it appears to me is:  that this "treeController" also  
is made into multiple instances with each new Document,   is there  
an already defined "loop" of these?  (a list of the open document's  
NSTreeController *treeController;)


No. I think you're confused about now nibs work. In your example,  
'treeController' is an instance variable (or field) of your document  
class. That means every instance of the class has one.


What happen when creating a document is that the NSDocumentController  
creates a new instance of your document subclass, then loads a new  
copy of the nib with your document object as its 'owner'. This creates  
a new instance of every object contained in the nib; and the instance  
variables of the owner object (your document) get connected to those  
new objects as you specified. So in  your new document object, the  
treeController instance variable will point to the new tree controller.


So every open document has one tree controller. If you want to find  
the list of open documents, ask the NSDocumentController.


—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread jon
ok,  after thinking and analyzing what was going on,  everytime i make  
a new document in the running app,   it created a new instance of the  
window and all related stuff in the window including myOutlineView.   
and then my dataSource in code remained the same that fills out these  
outline views...   (atleast this is my current understanding).


so my question now morphs into:

  as Jens says below,  he in some cases is looping through the apps  
window list...


in my case,   in my main document xib,  i have an "outline Controller"  
which is type NStreeController...  and i have this defined..


IBOutlet NSTreeController *treeController  which is the thing that is  
controlling the outline view,  and appears to be the thing i want to  
update...


the question it appears to me is:  that this "treeController" also is  
made into multiple instances with each new Document,   is there an  
already defined "loop" of these?  (a list of the open document's  
NSTreeController *treeController;)


or do i need to make an NSMutableArray,  and keep track of these  
myself?   and then update these instances myself by looping through  
them?


thanks,
Jon.

On Sep 27, 2009, at 9:54 AM, Jens Alfke wrote:


 The way I do this is to loop through the application's window list,


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 7:04 AM, jon wrote:

so far i can find the chain of windows,  like this,  but i can't  
figure out how to go deeper into them to be able to udpate the  
custom view down deep   maybe i'm approaching it wrong too...


The best way to do this is to use NSNotification. Post a notification  
when the outline content changes, and have each object that manages  
one of the outline views (probably the NSDocument or  
NSWindowController subclass) observe that notification and update its  
outline view when it's received.


There are some times when you do need to tell every one of your  
windows something. The way I do this is to loop through the  
application's window list, then look at each visible window's delegate  
and check whether it's an instance of my window controller subclass;  
if so, I cast the pointer to that subclass and call a method on it.  
(Since you're using NSDocument, you could probably get the same effect  
by getting the list of open documents from the document-controller  
object.)


—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread jon
I am probably not describing it accurately,I'll try to understand  
and describe what is going on more accurately in a bit,   more likely,  
i have one set of data,   and each time a new window is open,  it is  
creating another instance of the outline view,   i have not found away  
to get at the old instances of this view...


thanks,
Jon.


On Sep 27, 2009, at 8:31 AM, Graham Cox wrote:


 so I'm skeptical that your description is really accurate.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Graham Cox


On 28/09/2009, at 12:04 AM, jon wrote:

i have one instance of Outline View  called myOutlineView,   so no  
matter how many documents are displayed on the screen,   there is  
only one myOutlineView instance,



I'm pretty sure that is never going to work. If I read you correctly,  
you have a single view instance that is simultaneously a subview of  
any number of documents? If so, that's just not a valid setup. A view  
must have a distinct unique parent view and window, not multiple  
parent views. However, I'm not sure how you could even set this up, so  
I'm skeptical that your description is really accurate.


What you need here is a separate view instance in each document but  
possibly sharing the same data source or controller such that they all  
show the same data, or sanest of all, separate data sources/ 
controllers that all reference a common shared data model - that is  
after all what you've described as your needs. This last will "just  
work" as long as you strictly follow MVC and use a standard recognised  
method for notifying views, like KVO or bindings.


--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com