GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • @maxgraph/core

This view

  • Original page
  • New address

GeezerVison is showing maxgraph.github.io — UndoManager | @maxgraph/core

  • UndoManager

Class UndoManager

Implements a command history. When changing the graph model, an UndoableEdit 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 UndoableEdit 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 (e.g. RootChange, ChildChange, TerminalChange, etc.) which contains the complete undo information. The UndoManager also listens to the GraphView and stores its 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.

Example

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.

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

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

Event: InternalEvent.CLEAR

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

Event: InternalEvent.UNDO

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

Event: InternalEvent.REDO

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

Event: InternalEvent.ADD

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

Hierarchy (View Summary)

  • EventSource
    • UndoManager
  • Defined in view/undoable-change/UndoManager.ts:84
Index

Constructors

constructor

Properties

eventListeners eventsEnabled eventSource history indexOfNextAdd size

Methods

addListener canRedo canUndo clear destroy fireEvent getEventSource isEmpty isEventsEnabled redo removeListener setEventsEnabled setEventSource trim undo undoableEditHappened

Constructors

constructor

  • new UndoManager(size?: number): UndoManager

    Parameters

    • size: number = 100

    Returns UndoManager

    Overrides EventSource.constructor

    • Defined in view/undoable-change/UndoManager.ts:85

Properties

eventListeners

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.

Inherited from EventSource.eventListeners

  • Defined in view/event/EventSource.ts:58

eventsEnabled

eventsEnabled: boolean = true

Specifies if events can be fired. Default is true.

Inherited from EventSource.eventsEnabled

  • Defined in view/event/EventSource.ts:63

eventSource

eventSource: EventTarget | null = null

Optional source for events.

Default

null

Inherited from EventSource.eventSource

  • Defined in view/event/EventSource.ts:69

history

history: UndoableEdit[] = []

Array that contains the steps of the command history.

  • Defined in view/undoable-change/UndoManager.ts:101

indexOfNextAdd

indexOfNextAdd: number = 0

Index of the element to be added next.

  • Defined in view/undoable-change/UndoManager.ts:106

size

size: number = 100

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

Default

100
  • Defined in view/undoable-change/UndoManager.ts:96

Methods

addListener

  • addListener(name: string, funct: Function): void

    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

    Inherited from EventSource.addListener

    • Defined in view/event/EventSource.ts:105

canRedo

  • canRedo(): boolean

    Returns true if a redo is possible.

    Returns boolean

    • Defined in view/undoable-change/UndoManager.ts:149

canUndo

  • canUndo(): boolean

    Returns true if an undo is possible.

    Returns boolean

    • Defined in view/undoable-change/UndoManager.ts:127

clear

  • clear(): void

    Clears the command history.

    Returns void

    • Defined in view/undoable-change/UndoManager.ts:118

destroy

  • destroy(): void

    Clears all registered event listeners.

    Subclasses with a destroy method should call super.destroy() at the end of their own cleanup to ensure no stale listeners remain.

    Returns void

    Inherited from EventSource.destroy

    • Defined in view/event/EventSource.ts:166

fireEvent

  • fireEvent(evt: EventObject, sender?: EventTarget | null): 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.

    Example:

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

    Parameters

    • evt: EventObject

      EventObject that represents the event.

    • sender: EventTarget | null = null

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

    Returns void

    Inherited from EventSource.fireEvent

    • Defined in view/event/EventSource.ts:139

getEventSource

  • getEventSource(): EventTarget | null

    Returns eventSource.

    Returns EventTarget | null

    Inherited from EventSource.getEventSource

    • Defined in view/event/EventSource.ts:88

isEmpty

  • isEmpty(): boolean

    Returns true if the history is empty.

    Returns boolean

    • Defined in view/undoable-change/UndoManager.ts:111

isEventsEnabled

  • isEventsEnabled(): boolean

    Returns eventsEnabled.

    Returns boolean

    Inherited from EventSource.isEventsEnabled

    • Defined in view/event/EventSource.ts:74

redo

  • redo(): void

    Redoes the last change.

    Returns void

    • Defined in view/undoable-change/UndoManager.ts:156

removeListener

  • removeListener(funct: Function): void

    Removes all occurrences of the given listener from eventListeners.

    Parameters

    • funct: Function

    Returns void

    Inherited from EventSource.removeListener

    • Defined in view/event/EventSource.ts:112

setEventsEnabled

  • setEventsEnabled(value: boolean): void

    Sets eventsEnabled.

    Parameters

    • value: boolean

    Returns void

    Inherited from EventSource.setEventsEnabled

    • Defined in view/event/EventSource.ts:81

setEventSource

  • setEventSource(value: EventTarget | null): void

    Sets eventSource.

    Parameters

    • value: EventTarget | null

    Returns void

    Inherited from EventSource.setEventSource

    • Defined in view/event/EventSource.ts:95

trim

  • trim(): void

    Removes all pending steps after from the history, invoking die on each edit. This is called from .

    Returns void

    • Defined in view/undoable-change/UndoManager.ts:189

undo

  • undo(): void

    Undoes the last change.

    Returns void

    • Defined in view/undoable-change/UndoManager.ts:134

undoableEditHappened

  • undoableEditHappened(undoableEdit: UndoableEdit): void

    Method to be called to add new undoable edits to the .

    Parameters

    • undoableEdit: UndoableEdit

    Returns void

    • Defined in view/undoable-change/UndoManager.ts:173

Settings

Member Visibility
  • Protected
  • Inherited
Theme

On This Page

ExampleEvent: InternalEvent.CLEAREvent: InternalEvent.UNDOEvent: InternalEvent.REDOEvent: InternalEvent.ADD
Constructors
constructor
Properties
eventListenerseventsEnabledeventSourcehistoryindexOfNextAddsize
Methods
addListenercanRedocanUndocleardestroyfireEventgetEventSourceisEmptyisEventsEnabledredoremoveListenersetEventsEnabledsetEventSourcetrimundoundoableEditHappened
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.