Class: UndoAction

PD. UndoAction

Defines the basic interface for all undo/redo action items.

To create a custom undo action, simply subclass PD.UndoAction and implement a constructor as well as the undo() and redo() methods, as shown below.


new UndoAction(description)

Creates a new action item.

Parameters:
Name Type Description
description string

A human-readable description of this item.

Author:
  • drajmarsh
Example
class MyPropertyUndoItem extends PD.UndoAction {

     constructor(host_object, oldValue, newValue) {

         const description = 'My property changed from \'' + oldValue.toString() + '\' to \'' + newValue.toString() + '\'';
         super(description);

         this.hostObject = host_object;
         this.oldValue = oldValue;
         this.newValue = newValue;

     };

     undo(undoManager) {
         if (this.hostObject) {
             this.hostObject.setMyProperty(this.oldValue);
             undoManager.rebuildModel();
         }
     };

     redo(undoManager) {
         if (this.hostObject) {
             this.hostObject.setMyProperty(this.newValue);
             undoManager.rebuildModel();
         }
     };

};

Methods


elapsedTime()

Retrieves the elapsed time since value was last updated, in milliseconds.

Returns:

Returns the elapsed time in milliseconds.

Type
number

redo(undoManager)

Redo the action defined by this action item.

Parameters:
Name Type Description
undoManager UndoManager

The undo manager that invoked this action.


undo(undoManager)

Undo the action defined by this action item.

Parameters:
Name Type Description
undoManager UndoManager

The undo manager that invoked this action.