Re: Undo / Redo
Re: Undo / Redo
- Subject: Re: Undo / Redo
- From: Niko Matsakis <email@hidden>
- Date: Sat, 8 Oct 2005 10:19:06 +0200
Actually, redo usually *does* happen automatically. The way to do it
is to ensure that you do not go making changes to your model willy
nilly, but only through a constrained, specified interface. Do this
from the beginning and you will be much happier.
In any case, in each of these constrained places where the model may
be changed, always register an undo. Here is the canonical example.
I don't remember the exact syntax of the undo manager's methods, so
this is more of pseudo-code:
- (void) setColor:(NSColor*)color
{
NSColor *currentColor = _color;
NSUndoManager *undoManager = [self undoManager];
// register an undo to return to the old color. Note that the
undo goes through this
// method as well!
[[undoManager registerUndo] setColor:currentColor];
// make the change
[_color release];
_color = [currentColor retain];
}
Now when the user hits undo, setColor: is invoked. In this case the
undo which is registered goes automatically on the redo stack, since
the undo manager knows that the change was due to an undo, and if the
user hits redo it will be appropriately handled.
Niko
On Oct 6, 2005, at 9:26 PM, Jeff LaMarche wrote:
I've got a question about Undo and Redo. I just wrote a little app
to learn how to do undo. Based on stuff I read, and the input of
some people on the list, I decided to put my undo code in my
controller classes rather than in the model.
The situation I've got now, is that undo works beautifully, but
redo doesn't work at all.
Now, I think I don't understand how undo works. None of the undo
actions I register with the undo controller registers an undo,
which I'm guessing is the problem. If the system is undoing, then
undos you register go into the Redo stack? So, In addition to
resetting controls and my data model, the undo manager has to
basically register an undo when it's undoing the action in order
for Redo to work? Is that correct?
I guess I had assumed that Redo would happen automatically, which
was probably a stupid assumption, now that I think about it. =)
If anyone can help clarify this for me, I'd appreciate it, as I'm a
little confused.
Thanks much
Jeff
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Undo / Redo (From: Jeff LaMarche <email@hidden>) |