CoreData and NSUndoManager/Undo Grouping...
CoreData and NSUndoManager/Undo Grouping...
- Subject: CoreData and NSUndoManager/Undo Grouping...
- From: Jean-Nicolas Jolivet <email@hidden>
- Date: Wed, 04 Mar 2009 01:41:30 -0500
I'm trying to set up undo grouping properly for my editing dialog
(i.e. when a user edits a ManagedObject, the whole editing process can
be undo...)
I've read a couple of articles/tutorials about using undo grouping for
Core Data but they all involved 2 things: An editing window/sheet and
a non-document based app...
In my case, I'm using a Document-based Core Data application and the
editing is done in an NSView, not a window/sheet...
What I tried to do was the following: My view (let's call it EditView)
has a controller (EditViewController)... in the EditViewController,
when I'm showing the view (i.e. the editing process begins..) I'm
doing this:
//Prepare undo manager
[[[myDoc managedObjectContext] undoManager] beginUndoGrouping];
where myDoc is an outlet to MyDocument...
I also have two actions in my editController; one for the save button
and one for the cancel button:
- (IBAction)saveChanges:(id)sender
{
[[[myDoc managedObjectContext] undoManager] endUndoGrouping];
[[[myDoc managedObjectContext] undoManager] setActionName:@"Item
Editing"];
[self hideView:sender];
}
- (IBAction)cancelChanges:(id)sender
{
[self hideView:sender];
[[[myDoc managedObjectContext] undoManager] endUndoGrouping];
[[[myDoc managedObjectContext] undoManager] undo];
}
Now, the cancel button is working nicely... if I click on it, the view
is hidden and the changes are undo... the problem is when I save the
changes... in that case, the view does disappear and the action gets
added and named correctly ("Undo Item Editing") but if I undo it (by
selecting it from the "Edit" menu, or pressing Cmd+Z), nothing
happens...
I'm not sure what's happening... could it be that a different
NSUndoManager is used? Because basically both the save and cancel
buttons are using the same code, the only thing that cancel does is to
actually call the undo method directly on the undo manager... so the
only thing I could see is that the "Undo" from the Edit menu is
calling a different Undo Manager but I'm not sure why this would
happen since my EditView/EditViewController doesn't have one
(well...not that I know off anyway??)
It's also possible that I'm completely missing the point with
NSUndoManagers/NSManageObjectContext etc...
Any help/suggestion would be appreciated...
Jean-Nicolas Jolivet
email@hidden
http://www.silverscripting.com
_______________________________________________
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