Re: Undo in tables
Re: Undo in tables
- Subject: Re: Undo in tables
- From: Alex Rice <email@hidden>
- Date: Thu, 11 Apr 2002 20:05:01 -0600
On Thursday, April 11, 2002, at 03:44 PM, Bill Cheeseman wrote:
Is there a standard technique for implementing undo and redo of edits in
tables? I can't find any examples or documentation on this. The
techniques
used for single-item controls don't seem applicable.
My thinking is to do it with editingDidEnd delegate methods or related
notifications, and to keep an array of recently-edited records that can
be
unwound back into the table if the user chooses Undo a lot. I fear that
I'll
have to get down and dirty with the undo manager and its notifications.
I'm wondering, before I get too far down this path, if this makes sense
from
the point of view of those of you who've tackled this issue.
Here is a way that works pretty good. I don't know if it's the best way,
but it works. This is what I've used in my Slacker.app. The trickiest
part, not shown here because it would be embarrassing to post my
owncode, is figuring out how to re-sort the table- for instance, after
the user undoes a table edit.
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSString *ident = [aTableColumn identifier];
MyThing *target = [_model objectAtIndex:rowIndex];
// MyThing implements NSKeyValueCoding!
// for instance if ident = @"name" then
// [target setName:anObject] gets called and [target name] gets put
into the undomanager.
// set the name of the undo action.
// maybe use ident to build the action name from localizable.strings?
[[self undoManager] setActionName:NSLocalizedString(@"Undoable Thing
Edit", nil)];
// use key-value coding to prep the undo manager with the object's
current state
[[[self undoManager] prepareWithInvocationTarget:target]
takeValue:[target valueForKey:ident]
forKey:ident];
// and use key-value coding to set the newvalue
[target takeValue:anObject forKey:ident];
}
Alex Rice <email@hidden>
Mindlube Software
http://www.mindlube.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.