Another Undo Question - Individual property undos.

Another Undo Question - Individual property undos.

Old forum URL: forums.lhotka.net/forums/t/548.aspx


slipmat posted on Wednesday, July 05, 2006

Hi all,
I am fairly new to CSLA (reading book currently).
Rocky has put a lot of effort into the n-level undo functionality, but it seems only to be used to take one snapshot of an object before the user makes changes to the object as a whole. I would like to be able to undo individual property sets (Nested Undos?). Has anyone implemented the undo operations this way with CSLA?
My apologies if I'm missing something obvious, but it seems to achieve this I need to catch events on editing controls (e.g. Textbox) or bindings and call BeginEdit, which is fine. But then after (n) number of BeginEdits I also have to call ApplyEdit the same number of times before I can save (otherwise the object cannot be saved because it is being edited), which seems messy. And what if the user wants to undo a change after they have saved? Correct me if I'm wrong, but hasn't the undo stack been cleared by calling ApplyEdit n times?

Again, I'm sorry if I've missed something obvious, as the framework is a lot to take in at first.
So basically, if I'm wrong, could someone please point in the right direction, otherwise
make some suggestions as to a clever way to implement nested undos. Cheers.

Full credit Rocky and everyone involved, the framework is is incredible!

Thanks
Matt

ajj3085 replied on Thursday, July 06, 2006

Matt,

You can certainly add this functionality yourself, perhaps by creating a BeginEdit( string propertyName ) method (and corrisponding Cancel and Accept).  This would likely be quite a bit of overheard (as each property needs to store a stack of changes).

Calling ApplyEdit a number of time equal to Begin edit really isn't that big a deal.  You are right, once Accept is called, those changes can no longer be undone.  But that is the purpose of Accepting changes; the user has decided that they want to keep those changes.

Also, once you accept changes, it doesn't make sense to allow any more undos; otherwise, why did the user accept the changes to begin with?  I suppose if you really wanted to you could reload the object instead of saving it and thus 'undo' back to the state of the database.

HTH
Andy

hurcane replied on Thursday, July 06, 2006

slipmat:
Hi all,
So basically, if I'm wrong, could someone please point in the right direction, otherwise
make some suggestions as to a clever way to implement nested undos. Cheers.


I don't think anybody has come up with a clever way to handle undo/redo of property-level changes. It's practically impossible to implement an undo/redo with a generic algorithm. It is not uncommon for a property Set to have side-effects, such as filling other fields with default values. Are these side effects reversed individually, or are they reversed as a group?

Most Undo patterns involve the use of command objects. The command objects have an Execute and Undo method, which invokes the necessary logic for the particular action. The command object needs to keep state, and the business object would have to provide methods for undoing the action.

For more information, you might want to check this page.

Jojo33333 replied on Tuesday, October 12, 2010

Times change.  UndoEngine at www.undomadeeasy.com has a generic algorithm that I have found really easy to use

All the best

JoJo33333

slipmat replied on Sunday, July 09, 2006

Thanks for your input.
I'm glad I haven't missed some aspect of the framework.

Cheers
Matt

Copyright (c) Marimer LLC