For the moment of writing this topic DejaVu supports two types of data collections: list and dictionary.
They are implemented in classes DejaVu.Collections.Generic.UndoRedoList<T> and DejaVu.Collections.Generic.UndoRedoDictionary<T>.
These classes have exactly the same public interface as standard classes List<T> and Dictionary<T> correspondently but with undo/redo engine under the hood.
Declaration of list/dictionary propery is farly simple:
using Dejavu;
...
class MyClass2
{
private readonly UndoRedoList<MyClass> myclasses = new UndoRedo<MyClass>();
public UndoRedoList<MyClass> MyClasses
{
get { return myclasses ; }
set { myclasses = value; }
}
}
As you can see property returns an list of type UndoRedoList<MyClass>. You can add/remove items in this list as you did ever before but when time comes, all these changes can be undone or redone in a single bunch.
In next posts I will eventually show how you can organize your changes into commands and how to make them undo/redo.
2 comments:
Let's say I want to load an undoable dictionary by reading the contents of a file. In this case I don't want to support undo - I'm not sure how to handle this step?
Take a look at the sample at codeplex site. Basically you should use methods at UndoredoManager to suspend/resume tracking changes. They are specifically designed for the purpose you mentioned.
Post a Comment