Re: NSUndoManager - clearing a single 'redo'
Re: NSUndoManager - clearing a single 'redo'
- Subject: Re: NSUndoManager - clearing a single 'redo'
- From: Bill Cheeseman <email@hidden>
- Date: Mon, 09 Dec 2002 06:02:34 -0500
on 02-12-08 8:59 PM, Bruce Veazie at email@hidden wrote:
>
Is there a way to prevent an 'undo' from being transferred to the
>
'redo' stack or to clear just the last redo?
>
>
I'm developing a document-based OpenGL modelling app. When an object is
>
loaded from a file I register an 'undo load object' which deletes the
>
object - to permit the user to delete an object just loaded if it's the
>
wrong file, etc. When Cmd-z is used to undo the load, i.e., delete the
>
erroneously loaded object, a 'Redo load object' gets stacked. I'd
>
prefer not to have that 'redo' on the stack.
>
>
Anyone know of a way to clear that single 'redo load' when the 'undo
>
load' is invoked?
I do something very like this to implement "live" undo and redo of text
field editing in Recipe 7 of my new book "Cocoa Recipes for Mac OS X: The
Vermont Recipes" (Peachpit Press). I need to clear the redo stack when the
user stops editing the field.
It involves subclassing the textfield, observing 3 Undo Manager
notifications, sending "fake" undo calls to move unwanted undo items to the
redo stack, then registering a new action on the undo stack for the same
text field in order to clear the redo stack. In the case of text fields
there is the additional complication of creating a separate field editor,
but you wouldn't have to worry about that. The rest of the technique might
work for you.
The trick lies in registering a new undo action for the same control. That
has the side effect, you might say, of clearing the redo stack. At this
time, as far as I know, it is the only relatively easy way to clear the redo
stack.
You could look at the private variables in the Cocoa headers and get at the
redo stack that way, using a category to add a method to the undo manager --
say, clearRedoStack. I played around with that approach just long enough to
be able to read the redo stack. But you would have to spend a lot of time
experimenting to make sure this didn't screw up a lot of internal counters
and so on, and I'm not sure it's feasible.
--
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.