Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Class: UndoManager

require(["esri/undoManager"], function(UndoManager) { /* code goes here */ });

Description

(Added at v2.2)
The UndoManager is a utility object that allows you to easily build applications with undo/redo functionality. Use the UndoManager to add operations (edits, navigation changes, graphics drawing) to the stack. The API includes a set of edit operations (add, delete, update, cut and union), created by inheriting from the OperationBase class. You can inherit from the OperationBase class to create custom operations that take advantage of undo/redo.

Samples

Search for samples that use this class.

Constructors

NameSummary
new UndoManager(options?)Creates a new UndoManager object.

Properties

NameTypeSummary
canRedoBooleanWhen true, there are redo operations available on the stack.
canUndoBooleanWhen true, there are undo operations available on the stack.
lengthNumberThe number of operations stored in the history stack.
positionNumberThe current operation position.

Methods

NameReturn typeSummary
add(operation)NoneAdds an undo operation to the stack and clears the redo stack.
clearRedo()NoneClear the redo stack.
clearUndo()NoneClear the undo stack.
destroy()NoneDestroy the operation manager.
get(operationId)OperationBaseGet the specified operation from the stack.
peekRedo()OperationBaseGet the next redo operation from the stack.
peekUndo()OperationBaseGet the next undo operation from the stack.
redo()NoneMoves the current position to the next redo operation and calls the operation's performRedo() method.
remove(operationId)OperationBaseRemove the specified operation from the stack.
undo()NoneMoves the current position to the next undo operation and calls the operation's performUndo method.

Events

[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.

Events

NameEvent ObjectSummary
addFires when the add method is called to add an operation is added to the stack.
changeFires when the undo/redo stack changes.
redoFires when the redo method is called.
undoFires when the undo method is called.
Constructor Details

new UndoManager(options?)

Creates a new UndoManager object.
Parameters:
<Object> options Optional See options list for parameters.
options properties:
<Number> maxOperations Optional The maximum number of operations the UndoManager can perform. If a number less than or equal to zero is provided the number of operations is unlimited. The default value is 10.
Sample:
require([
  "esri/undoManager", ... 
], function(UndoManager, ... ) {
  var undoManager = new UndoManager({maxOperations:8});
  ...
});
Property Details

<Boolean> canRedo

When true, there are redo operations available on the stack.
Known values: true | false
Sample:
require([
  "esri/undoManager", "dijit/registry", ... 
], function(UndoManager, registry, ... ) {
  var undoManager = new UndoManager( ... );
  if (undoManager.canRedo) {
    registry.byId("redo").set("disabled", false);
  } else {
    registry.byId("redo").set("disabled", true);
  }
  ...
});

<Boolean> canUndo

When true, there are undo operations available on the stack.
Known values: true | false
Sample:
require([
  "esri/undoManager", "dijit/registry", ... 
], function(UndoManager, registry, ... ) {
  var undoManager = new UndoManager( ... );
  if (undoManager.canUndo) {
    registry.byId("undo").set("disabled", false);
  } else {
    registry.byId("undo").set("disabled", true);
  };
  ...
});

<Number> length

The number of operations stored in the history stack.

<Number> position

The current operation position. A position value of 0 means that no operations are available on the stack. When an undo operation is performed the position decreases by 1. When a redo occurs the position is incremented by 1.
Sample:
require([
  "esri/undoManager", ... 
], function(UndoManager, ... ) {
  var undoManager = new UndoManager( ... );
  console.log('The current position is: " + undoManager.position);
  ...
});
Method Details

add(operation)

Adds an undo operation to the stack and clears the redo stack.
Parameters:
<OperationBase> operation Required An operation to add to the stack.
Sample:
require([
  "esri/undoManager", "esri/dijit/editing/Delete", ... 
], function(UndoManager, Delete, ... ) {
  var undoManager = new UndoManager();

  var operation = new Delete({
    featureLayer: layer,
    deletedGraphics: [feature]
  });
  
  undoManager.add(operation);
  ...
});

clearRedo()

Clear the redo stack

clearUndo()

Clear the undo stack.

destroy()

Destroy the operation manager. Sets the history stack to null and cleans up all references.

get(operationId)

Get the specified operation from the stack.
Return type: OperationBase
Parameters:
<Number> operationId Required The operation id.
Sample:
var lastOperation = undoManager.get(2);

peekRedo()

Get the next redo operation from the stack
Return type: OperationBase
Sample:
var nextOperation = undoManager.peekRedo(); 

peekUndo()

Get the next undo operation from the stack.
Return type: OperationBase
Sample:
var nextOperation = undoManager.peekUndo(); 

redo()

Moves the current position to the next redo operation and calls the operation's performRedo() method.
Sample:
<button onclick="undoManager.redo();" data-dojo-type="dijit.form.Button">Redo</button>

remove(operationId)

Remove the specified operation from the stack.
Return type: OperationBase
Parameters:
<Number> operationId Required The operation id.
Sample:
var operation = undoManager.remove(2);

undo()

Moves the current position to the next undo operation and calls the operation's performUndo method.
Sample:

undoManager.undo();

Event Details
[ On Style Events | Connect Style Event ]

add

Fires when the add method is called to add an operation is added to the stack. Should be used in favor of onAdd. (Added at v3.5)

change

Fires when the undo/redo stack changes. Should be used in favor of onChange. (Added at v3.5)

redo

Fires when the redo method is called. Should be used in favor of onRedo. (Added at v3.5)

undo

Fires when the undo method is called. Should be used in favor of onUndo. (Added at v3.5)