MindFusion.Wpf Pack Programmer's Guide
Command History

The undo/redo history is represented by a CommandHistory instance. That instance is created by the UndoManager and can be accessed by its History property.

The undo manager adds commands to the history after executing them. If the history queue is full, the oldest command records are removed when new ones are added. Use the Capacity property of CommandHistory to specify how many action records to keep in the queue.

The history has a current-command pointer indicating which are the next commands to undo or redo. If a command is undone, the current pointer in the history queue is moved back and allows undoing even older actions. If the current pointer is not at the last record, any newer commands can be redone again. Each time an action is undone or redone, respectively an ActionUndone or ActionRedone event is fired.

To query which are the next commands to be undone or redone, use the NextUndo and NextRedo read-only properties. They return the Command instances contained in the queue which are referred by the current position pointer. If no further undo or redo is possible, the properties return null (Nothing in Visual Basic). You might use them to indicate to end-users which are the next commands to undo/redo.

C#  Copy Code

if (diagram.UndoManager.History.NextUndo == null)
{
    // Everything has been undone
    miUndo.Enabled = false;
    miUndo.Text = "Undo";
}
else
{
    if (diagram.UndoManager.History.NextUndo is AddItemCmd)
    {
        // The next action to undo is item-creation
        miUndo.Enabled = true;
        miUndo.Text = "Undo Create";
    }
}

Visual Basic  Copy Code

If Diagram.UndoManager.History.NextUndo Is Nothing Then

    ' Everything has been undone
    miUndo.Enabled = False
    miUndo.Text = "Undo"

Else

    If TypeOf Diagram.UndoManager.History.NextUndo Is AddItemCmd Then

        ' The next action to undo is item-creation
        miUndo.Enabled = True
        miUndo.Text = "Undo Create"

    End If

End If

To ban end-users from undoing last commands, clear the command history by invoking the Clear method. It is possible to filter some commands so they are not recorded in the history by handling the ActionRecording event.