Re: cocoa-dev digest, Vol 2 #482 - 11 msgs
Re: cocoa-dev digest, Vol 2 #482 - 11 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #482 - 11 msgs
- From: "Erik J. Barzeski" <email@hidden>
- Date: Thu, 11 Apr 2002 23:51:13 -0400
Hi,
Answer below...
On 4/11/02 7:57pm, "email@hidden"
<email@hidden> wrote:
>
From: Bill Cheeseman <email@hidden>
>
Date: Thu, 11 Apr 2002 17:44:13 -0400
>
To: Cocoa-Dev Mail <email@hidden>
>
Subject: Undo in tables
>
>
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.
Writing this code in Entourage, so it may be a tad buggy... But the gist of
it is here...
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex
{
Thing *savedThing = [[[dataArray objectAtIndex:rowIndex] copy]
autorelease];
Thing *editedThing = [dataArray objectAtIndex:rowIndex];
NSDictionary *swapThese = [NSDictionary
dictionaryWithObjectsAndKeys:savedThing,@"savedThing",editedThing,@"editedTh
ing",nil];
[self deselectRecipientColumnsExcept:nil];
[[self undoManager] registerUndoWithTarget:self
selector:@selector(undoSetObjectValue:) object:swapThese];
[[self undoManager] setActionName:NSLocalizedString(@"Changes to Thing",
@"Undo Thing Changes undo item")];
[editedThing takeValue:object forKey:[tableColumn identifier]];
}
- (void)undoSetObjectValue:(NSDictionary *)swapThingies
{
// must replace editedThing with savedThing
Thing *savedThing = [swapThingies objectForKey:@"savedThing"];
Thing *editedThing = [swapThingies objectForKey:@"editedThing"];
NSDictionary *swapThingiesAgain = [NSDictionary
dictionaryWithObjectsAndKeys:editedThing,@"savedThing",savedThing,@"editedTh
ing",nil];
NSLog(@"\nsaved: %@\nedited: %@\n\n", [savedThing description],
[editedThing description]);
[tabView selectTabViewItemAtIndex:2];
[dataArray replaceObjectAtIndex:[dataArray
indexOfObjectIdenticalTo:[swapThingies objectForKey:@"editedThing"]]
withObject:savedThing];
[[self undoManager] registerUndoWithTarget:self
selector:@selector(undoSetObjectValue:) object:swapThingiesAgain];
[[self undoManager] setActionName:NSLocalizedString(@"Changes to Thing",
@"Undo Thing Changes undo item")];
[dataArrayTableView reloadData];
}
--
Kindest regards,
Erik J. Barzeski
I live in a small house, but my window
looks out on a large world - Confucius
*******************************************************************
Email: erik@(anything below)
AIM: iacas ICQ: 8186546
http://barzeski.com/ http://weims.net/
http://techstra.net/ http://cocoadevcentral.com/
http://soundsetcentral.com/ http://applescriptcentral.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.