• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Model objects to NSUndoManager--am I doing it right?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Model objects to NSUndoManager--am I doing it right?


  • Subject: Model objects to NSUndoManager--am I doing it right?
  • From: Paul Bruneau <email@hidden>
  • Date: Wed, 19 Aug 2009 15:17:37 -0400

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:

PNG image





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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Model objects to NSUndoManager--am I doing it right?
      • From: Graham Cox <email@hidden>
  • Prev by Date: NSWindow and Spaces
  • Next by Date: contextual menu plugin example in cocoa
  • Previous by thread: Re: NSWindow and Spaces
  • Next by thread: Re: Model objects to NSUndoManager--am I doing it right?
  • Index(es):
    • Date
    • Thread