Our app has requirement to support undo/redo functionality the way Word and Excel do it. As I understand, with CSLA is not available out of box. Older version of our app implements undo/redo using stack of commands against Model.
Since CSLA supports undo I am considering building on top of CSLA functionality. Have anybody tried to implement Excel style undo/redo functionality by modifying behavior of BeginEdit (), CancelEdit (), AcceptChanges ()?
Thanks,
Oleg
I'm currently reading the C# 2005 version of the CSLA.NET book, and I just started Chapter 4 about the Data Portal. So I am quite new to CSLA.NET.
The question of n-level Redo did pop up for me too, though. My (perhaps naive) assumption is that is should be enough to do this: Whenever an operation is undone, do not discard the undone state but store it in a Queue. When actions need to be redone, you can load the state that is at the front of the queue.
Is there anything blatantly wrong with this approach?
Dirk
We've implemented this by maintaining dual Stacks. One for undo and the other for redo. The key here is to distinguish between the two snapshots:
When BeginEdit is called, you want to take a snapshot of the object before any changes are made so that it can be restored to that point. Likewise with UndoEdit except that the state you will want to restore when Redo is clicked is the state the object is in at the time Undo is clicked - with all of the changes made.
The process works as follows:
Not sure if this is the best way to do this from a memory consumption point-of-view, but it works and behaves just like Excel. Trick is when you call BeginEdit to take snapshots that can be undone/redone (character-by-character like in Word, for instance). The rest is...automatic.
What we haven't been able to implement yet is a way to limit the size of the stacks from within the objects themselves so only 'x' number of changes can be undone. It would be nice to be able to remove the "oldest" item from the stack when attempting to add a new one if the size reached a certain limit. If anyone knows a structure that supports this or a way to do so, I'd appreciate the heads up.
Hope that helps.
SonOfPirate:What we haven't been able to implement yet is a way to limit the size of the stacks from within the objects themselves so only 'x' number of changes can be undone. It would be nice to be able to remove the "oldest" item from the stack when attempting to add a new one if the size reached a certain limit. If anyone knows a structure that supports this or a way to do so, I'd appreciate the heads up.
That's not a bad idea. I'd actually use the System.Collections.ObjectModel.Collection<T> for the inner list, just cuz I think it's more lightweight than List<T> and we would want to implement using generics. And, I think implementing an IsFixedSize property (along with the initialCapacity parameter to the constructor), like IList, would provide a consistent way to set this up. Then, if IsFixedSize = false, it would behave like a normal Stack<T>; if true, we could implement our "drop off" at the end once capacity is reached.
Great idea! Thanks!
From: Dirk.Rombauts [mailto:cslanet@lhotka.net]
Sent: Saturday, August 12, 2006 4:32 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Excel style undo/redoI'm currently reading the C# 2005 version of the CSLA.NET book, and I just started Chapter 4 about the Data Portal. So I am quite new to CSLA.NET.
The question of n-level Redo did pop up for me too, though. My (perhaps naive) assumption is that is should be enough to do this: Whenever an operation is undone, do not discard the undone state but store it in a Queue. When actions need to be redone, you can load the state that is at the front of the queue.
Is there anything blatantly wrong with this approach?
Dirk
Copyright (c) Marimer LLC