I've been looking for a nice way to implement the undo redo functionality. To do a simple undo redo you need to use the command pattern. We already have this defined in the interface. See Command pattern and ICommand interface.
To give users more room for mistakes you will want to use at least a buffered or multilevel undo-redo functionality. Therefor we also will use the memento pattern. See pattern and examples .

I also found a nice example of a tree based undo-redo functionality in the editor e. This is the windows version of textmate. See also attached screenshot.

  • No labels

2 Comments

  1. Unknown User (don)

    Yeah, Memento should be used as well in order to save state changed by one command. Command can use Memento to maintain the state required for an undo operation.
    Here is a Java example where they are mixed.

    We should check how this behaviour is implemented in:

    • Monodevelop - they also use attributes to define commands, interesting
    • Netron Graph - has some undo functionality for shapes (move vertices, shape)
    • Paint.NET - looks very nice, has some photoshop-like history control.

    All are OSS projects so sources can be found.

    Idea of branched changes / versioning can be also interesting for our data objects, but we should not make things too complicated for user.

  2. Unknown User (berg_p)

    There is an article at CodeProject that proposes a .NET implementation of undo/redo, also interesting to look at the comments.

    http://www.codeproject.com/KB/cs/AutomatingUndoRedo.aspx http://www.codeplex.com/dejavu/