• 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
Undo in an old school data model
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Undo in an old school data model


  • Subject: Undo in an old school data model
  • From: Jeff LaMarche <email@hidden>
  • Date: Tue, 4 Oct 2005 13:18:15 -0400

If I want to put undo in my data model (not using Core Data), rather than in the controller class, what's the best way to do it. My first hack at it had an obvious problem - the mutator registered itself as the undo action, which means when the undo happens, the undo is going to get registered as an action to be undone. Is there an accepted way of handling this, like a private counterpart method that does the actual setting of the instance variable, sort of like (usual disclaimers - this code was typed in mail):

- (void)setColorRaw:(NSColor *)newColor
{
     [newColor retain];
     [color release];
     color = newColor;
}
- (void)setColor:(NSColor *)newColor
{
     NSUndoManager *um =
        [[NSApp keyWindow] undoManager];
       [um registerUndoWithTarger:self
           selector:@selector(setColorRaw:)
            object:color];
     [um setActionName:@"Color Change"];
    [self setColorRaw:newColor]
 }

I know some people will say "put it in the controller layer", but I'm trying to specifically write example code to add undo support to the model, so that won't work for me. The example above would work, but I'm just not sure it's the best approach. Any thoughts or comments?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: Excel style spreadsheet read from xml
  • Next by Date: Re: Debugging Stdout
  • Previous by thread: Re: Obtaining information about the System's current cursor
  • Next by thread: Re: Undo in an old school data model
  • Index(es):
    • Date
    • Thread