Class UndoManager

UndoManager

Implements a command history. When changing the graph model, an mxUndoableChange object is created at the start of the transaction (when model.beginUpdate is called). All atomic changes are then added to this object until the last model.endUpdate call, at which point the mxUndoableEdit is dispatched in an event, and added to the history inside UndoManager. This is done by an event listener in Editor.installUndoHandler.

Each atomic change of the model is represented by an object (eg. mxRootChange, mxChildChange, mxTerminalChange etc) which contains the complete undo information. The UndoManager also listens to the mxGraphView and stores it's changes to the current root as insignificant undoable changes, so that drilling (step into, step up) is undone.

This means when you execute an atomic change on the model, then change the current root on the view and click undo, the change of the root will be undone together with the change of the model so that the display represents the state at which the model was changed. However, these changes are not transmitted for sharing as they do not represent a state change.

When adding an undo manager to a graph, make sure to add it to the model and the view as well to maintain a consistent display across multiple undo/redo steps.

var undoManager = new UndoManager();
var listener(sender, evt)
{
undoManager.undoableEditHappened(evt.getProperty('edit'));
};
graph.getDataModel().addListener(mxEvent.UNDO, listener);
graph.getView().addListener(mxEvent.UNDO, listener);

The code creates a function that informs the undoManager of an undoable edit and binds it to the undo event of mxGraphModel and mxGraphView using EventSource.addListener.

Fires after clear was invoked. This event has no properties.

Fires afer a significant edit was undone in undo. The edit property contains the mxUndoableEdit that was undone.

Fires afer a significant edit was redone in redo. The edit property contains the mxUndoableEdit that was redone.

Fires after an undoable edit was added to the history. The edit property contains the mxUndoableEdit that was added.

Hierarchy (view full)

Constructors

Properties

eventListeners: EventListenerObject[] = []

Holds the event names and associated listeners in an array. The array contains the event name followed by the respective listener for each registered listener.

eventsEnabled: boolean = true

Specifies if events can be fired. Default is true.

eventSource: null | EventTarget = null

Optional source for events. Default is null.

history: UndoableEdit[] = []

Array that contains the steps of the command history.

indexOfNextAdd: number = 0

Index of the element to be added next.

size: number = 100

Maximum command history size. 0 means unlimited history. Default is 100.

100

Methods

  • Binds the specified function to the given event name. If no event name is given, then the listener is registered for all events.

    The parameters of the listener are the sender and an EventObject.

    Parameters

    • name: string
    • funct: Function

    Returns void

  • Dispatches the given event to the listeners which are registered for the event. The sender argument is optional. The current execution scope ("this") is used for the listener invocation (see Utils#bind).

    Example:

    fireEvent(new mxEventObject("eventName", key1, val1, .., keyN, valN))
    

    Parameters

    • evt: EventObject

      EventObject that represents the event.

    • sender: null | EventTarget = null

      Optional sender to be passed to the listener. Default value is the return value of .

    Returns void