Hi all-

I'm just starting my first real document-based Cocoa app. My other app was non-document based and the undo system was quite different (plus I know I did some things wrong MVC-wise in that app).

The documentation I have read tells me that I should implement undo in the Setter methods of my model objects' properties. And I have done so for some of my objects (so far).

My question is, what is the best way to make all my model objects be able to find their document's undo manager?

Here is an early shot of part of my interface:

<<inline: pastedGraphic.png>>





To get the document to where these Entrances can see it, I had to subclass NSArrayController, add an IBOutlet for "myWindowController" (which in turn of course knows the document) and wire it to File's Owner in its NIB.

I have the New Entrance button bound to the add: method of my EntranceArrayController (which I overrode as below):

-(void)add:(id)sender;
{
        SLEntrance * newSLEntrance = [[SLEntrance alloc] init];
        newSLEntrance.myDocument = myWindowController.document;         
        //I need to let this new entrance know its document
        
        //now add this new entrance to the entrance array
        [self addObject:newSLEntrance]; 
                
        //generate invocation to tell the Undo system we have something to undo
[[[myWindowController.document undoManager] prepareWithInvocationTarget:self] removeObject:newSLEntrance]; [[myWindowController.document undoManager] setActionName:@"create new Entrance"];
}

In summary, it seemed like a Long Way to Go just to let my new Entrance objects know who their document is. In my future is the fact that Entrances will have FrameModules, which may contain a Door, which will contain an array of Cutouts and so I am looking at 3-4 more generations of Model object types, each of which must a similar way to get to the Document's Undo Manager.

Is this the right way?

Thank you
_______________________________________________

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

Reply via email to