Search
Undo and Redo

( a feature of FlowChartX Pro edition)

FlowChartX records all users' actions in a command history. Later these actions can be undone, either programmatically, using the Undo method, or by a user through the CTRL+Z keyboard combination. If an action is undone, it can later be redone by calling the Redo method or using the CTRL+Y keyboard combination.

Command history

The maximum size of the command history is controlled via the UndoDepth property. Once the maximum number of records in the history is reached, recording a new action deletes the oldest one in the queue. The undo/redo operations move a queue-pointer respectively to the beginning/end of the queue. When the pointer is placed before the beginning of the queue, that means that no more actions can be undone, or that no undo-action is recorded at all. When it points after the end of the queue, then no actions can be redone, either because the queue is empty, or because no actions are previously undone. Use UndoPossible and RedoPossible methods to check these conditions. For example you can disable the respective menu items when undo or redo is not possible. By setting UndoDepth to zero, you can disable the undo functionality.

Actions that are automatically recorded

In addition to all users' actions, some programmatic actions are also recorded in the undo/redo history. These actions include creating and deleting objects and groups through respective methods, or changing the current selection. If you want to prevent users from undoing such operations, use the ClearUndoBuffer method.

Property changes

Changes made to properties of diagram items are not recorded in the command history, unless they are enclosed in BeginUndoRecord / EndUndoRecord method calls. All actions performed on an item enclosed by these methods will be put in the history-queue as an atomic undoable operation. For example, a button might set several properties of a selected box when clicked. The following VB6 code adds all box property changes to the undo-history as a whole undoable operation:

VB  Copy Code

Private Sub Command1_Click()

    Dim abox As FLOWCHARTLibCtl.box

    If FlowChart1.ActiveItemType = aiBox Then

        Set abox = FlowChart1.ActiveBox
        abox.BeginUndoRecord False
        abox.Text = "undo me!"
        abox.FrameColor = vbRed
        abox.Style = bsRhombus
        abox.EndUndoRecord

    End If

End Sub

Composite undo records

Actions recorded for individual items can be combined in a single undoable record. For example that is useful when applying changes to all items in a selection. To create a composite record, perform all changes to items between calls of flowchart's BeginUndoRecord and EndUndoRecord methods. The respective BeginUndoRecord / EndUndoRecord methods of items must still be called. Another method to combine several records into one composite record is provided by MergeUndoRecords.

Custom undo records

To place a custom action in the FlowChartX command history, call RecordCustomAction. The action ID passed to that method is reported back by ActionUndone and ActionRedone events.

Events

Each time a new record is saved in the command history, an UndoActionRecorded event is raised. Upon undo or redo of some actions, the ActionUndone and ActionRedone events are raised.