Re: NSUndoManager implementing Redo
Re: NSUndoManager implementing Redo
- Subject: Re: NSUndoManager implementing Redo
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 12 Jul 2002 06:29:06 -0400
on 02-07-11 7:41 PM, Greg Hulands at email@hidden wrote:
>
I am trying to add Undo and Redo in an application and am having trouble
>
trying to implement redo. I have a mutable array that holds a data object.
>
When I register for the undo I give it a selector of undoAddData: which is
>
fine. The undo gets called but when I try redo neither the original method
>
that was called where the undo was registered, nor the undoAddData: method
>
are called.
>
>
Which method should get called when performing a redo? Can I give the undo
>
manager a different method?
Yes, you can specify different methods for undo and redo. In an object
deletion scenario, you petty much have to do it this way. For example, to
add an object to a table view, I use three methods:
1. The addObject method instantiates a new row object and records the
deleteObject method as its undo action.
2. The deleteObject method deletes the object and records the undeleteObject
method as its undo action.
3. The undeleteObject method restores the object and records the
deleteObject as its undo action.
So, the initial addObject method performs the instantiation task, sets up
the undo action, and then drops out of the picture permanently. Undo and
Redo then cycle back and forth between the deleteObject and undeleteObject
methods. In this scenario, deleteObject acts as an Undo action and
undeleteObject acts as a Redo action.
An alternative execution path is that an existing object in the table view
may be deleted by a button that calls the deleteObject method. In this
scenario, undeleteObject acts as the Undo action and deleteObject acts as
the Redo action, using the same code as in the first scenario.
Each of the two methods "stores" the object on the undo or redo stack, so it
always remains available for restoration, until you clear all undo actions
(for example, when you save or close the document). This way, you don't have
to go to the trouble of setting up your own cache of deleted objects waiting
for possible restoration.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
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.