Managing undo with NSArrayController and a table displaying its objects?
Managing undo with NSArrayController and a table displaying its objects?
- Subject: Managing undo with NSArrayController and a table displaying its objects?
- From: Mike Nowak <email@hidden>
- Date: Mon, 17 Nov 2003 17:04:46 -0500
I'm trying to understand how to handle undoing changes to the data in
my model when a table is editing it through an array controller.
Basically I have an NSArrayController (which I subclassed so I could
manage the creation of new objects) and I bound the content of the
table to the array controller using the arrangedObjects controller key.
My array controller controls an array of custom objects containing
annual data for a company's stock. I put what I think is the proper
undo code into this model object like this:
- (void)setHighPrice:(NSNumber*)newHighPrice
{
if (highPrice != newHighPrice)
{
[[[self undoManager] prepareWithInvocationTarget:self]
setHighPrice:highPrice];
[[self undoManager] setActionName:@"Change High Price"];
[self willChangeValueForKey:@"highPrice"];
[highPrice release];
highPrice = [newHighPrice retain];
[self didChangeValueForKey:@"highPrice"];
}
}
The undo part seems to work fine. The problem is that when the user is
editing that field in the table, and then they choose Undo Change High
Price, the value doesn't update until they move to another cell.
I've tried a few things:
-- adding validateMenuItem to my array controller so I could disable
the Undo item if something is being edited in the table. This method
never gets called in my array controller though. Not sure what's going
on there.
-- I tried observing the change in highPrice key from the array
controller so I could try aborting editing in the table. Although
observeValueForKeyPath:ofObject:change:context: gets called when I
change the entry in the table by typing a new value, it doesn't get
called when the value gets changed by undo.
I am sure I am missing something simple. Any pointers would be
appreciated -- thanks!
--
Mike Nowak
Work:
http://healthmedia.umich.edu/
Personal:
http://snackdog.org/
"Everybody fights. Nobody quits. Otherwise I'll shoot you myself." -
Starship Troopers
_______________________________________________
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.