On 20/02/2009, at 6:34 AM, Randall Meadows wrote:

when changing a yellow object blue, you pass the Undo manager the object, the -setColor: method, and the current color, so that upon invoking Undo the color is changed back to what it was. Nice and symmetrical.

However, I have a case where symmetry is not involved.


Undo isn't *required* to be symmetrical. It just happens to be when setting a single property like your -setColor: example.

Another very common situation is like this:

- (void)        addObject:(id) obj
{
        [[undoManager prepareWithInvocationTarget:self] removeObject:obj];
        [array addObject:obj];
}


- (void)        removeObject:(id) obj
{
        [[undoManager prepareWithInvocationTarget:self] addObject:obj];
        [array removeObject:obj];
}


This code will undo and redo adding and removing objects all day long. Each undo is complementary to the other, but it's not identical.

Seems to me this is the sort of design you want.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to