Re: How to make Redo work with a custom group
Re: How to make Redo work with a custom group
- Subject: Re: How to make Redo work with a custom group
- From: David Spooner <email@hidden>
- Date: Mon, 29 Oct 2007 09:12:47 -0600
Paul,
I find it generally useful to parameterize the operations (and their
inverses) with an undo manager. This avoids reliance on the undo
manager of a specific view and allows the operations to exist cleanly
at the model level. I would go further and say that in any model for
which you want undo support, your 'primitive' mutation methods should
have an undo parameter. I say this based on experience adding undo
support to a mesh editing program: there the operations were quite
complex and after much difficulty trying to synchronize the effects
of undo and redo I ended up restructuring to code to use the undo
manager at the lowest level.
dave
On 29-Oct-07, at 8:11 AM, Paul Bruneau wrote:
Hi-
I understand how Redo works as described on page 145 of Hillegass.
He makes his insertObject: and removeObject: methods the inverse of
each other so that when you do one, it puts the other one on the
undo stack.
But in my situation, I don't seem to be able to implement it that way.
I want to undo a drag that occurs in a custom view.
I put this into my -mouseDown: method:
//start custom undo grouping
[[appController myUndo] setGroupsByEvent:NO];
[[appController myUndo] beginUndoGrouping];
then I put this into my -mouseDragged: method:
[[[appController myUndo] prepareWithInvocationTarget:selectedOS]
setStartTime:[selectedOS startTime]];
This gets called every time the mouse moves of course.
Finally, in my -mouseUp: method I close it up:
//end custom undo grouping
[[appController myUndo] setActionName:[NSString
stringWithFormat:@"Move order step"]];
[[appController myUndo] endUndoGrouping];
[[appController myUndo] setGroupsByEvent:YES];
So Undo works great, but I when I try Redo (which does show OK in
the menu), nothing happens. This is I think because there is no
undo code in the setStartTime: call that I wrap into the
prepareWithInvocationTarget:
But how do I go about it? Do I make a second -setStartTime method
called something like -setStartTimeWithUndo that puts its inverse
on the undo stack?
Thank you for any insight
_______________________________________________
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