An action that can be undone and redone. For example, editing a shape (see the EditController's EditShape event).

You usually create undoables in response to an event from the API, and then add them to an UndoManager.

This example shows how to create Undoables in LuciadRIA:

/**
* Adds sample undo/redo support to an EditController.
* @param editController The EditController to add sample undo/redo support to
* @param undoManager The UndoManager to add the undoable to
*/
export const addEditUndoSupport = (editController: EditController, undoManager: UndoManager = SAMPLE_UNDO_MANAGER): Handle => {
let lastShape = editController.feature.shape ? editController.feature.shape.copy() : null;
const editHandle = editController.on("EditShape", ({shape, status}) => {
if (status === EditShapeStatus.FINISHED) {
const label = `edit ${shapeToString(shape)}`;
const newShape = shape ? shape.copy() : null;
addChangeShapeUndoable(editController.map!, editController.layer, editController.feature, lastShape, newShape, label, undoManager);
lastShape = newShape ? newShape.copy() : null;
}
});
const restartHandle = editController.on("Restarted", () => {
lastShape = editController.feature.shape ? editController.feature.shape.copy() : null;
});
const deactivateHandle = editController.on("Deactivated", () => {
restartHandle.remove();
editHandle.remove();
deactivateHandle.remove();
});
return {
remove: () => {
restartHandle.remove();
editHandle.remove();
deactivateHandle.remove();
}
}
}

You can find the full source, and more examples in samples/common/core/util/SampleUndoSupport.ts.

Common events are:

See

UndoManager

Since

2022.1

Hierarchy

  • Undoable

Constructors

Accessors

Methods

Constructors

  • Creates a new Undoable

    Parameters

    • id: string

      An id for the Undoable. This id is not used by the UndoManager, but it can be useful for differentiating between undoables in your application.

    • label: string

      A label for the Undoable. This can be a string you display directly in the UI, or a translation key.

    Returns Undoable

Accessors

  • get id(): string
  • An id for the Undoable. This id is not used by the UndoManager, but it can be useful for differentiating between undoables in your application.

    Returns string

  • get label(): string
  • A label for the Undoable. This can be a string you display directly in the UI, or a translation key.

    Returns string

Methods

  • Redoes the operation represented by this Undoable

    Returns void

  • Undoes the operation represented by this Undoable

    Returns void