PERGOLA LOGO

pergola.Undo

pergola.Undo is not subclassed to pergola.Class.

An object needing undo/redo monitoring must first define a pergola.Undo instance and register it, for example:

 myObject.undoManager = new pergola.Undo().register();
You will then be able to add mementos (before) any actions to be recorded.

Pergola windows automatically assign an Undo instance to the instance property undoManager. The feature is registered for the topmost window, and disabled for the others. The system manages these states.

Note: you can use method chaining with register() and add() only.

pergola.Undo([n])

Constructor. If n number is specified it represents the level of undos, and it's assigned to this max, otherwise the default number applies, as set in the config file.

class

None

prototype

canUndo()

Returns true if this buffer is not empty.

canRedo()

Returns true if this buffer length is greater than this index.

add(array)

Call this method to record an action. array contains one or more elements. Each element is a memento object defining the required obj (typically this), and undo and redo callback functions. The memento may define any other properties necessary to the correct restoration of the previous state for undo, and of the current state for redo. Adding a memento can look like this:

 pergola.Window.active().undoManager.add([
    this.memento({
      undo : this.undo.remove,
      redo : this.redo.restore,
      snappers : this.storeSnaps()
    })
  ]);

Note: memento is a helper method of the the pergola.Class (superclass) prototype. It adds the required obj property.

update()

Shifts the buffer if it has reached the maximum length and invokes this destroy. You don't normally need to invoke this method explicitly.

cancel()

Remove the latest entry in the buffer. This method is not invoked by any other method. If needed, use with caution. You don't normally need to invoke this method explicitly.

destroy(elements)

For each element in elements it invokes element.destroy() if element has a pendingDelete property set, and a destroy method. You don't normally need to invoke this method explicitly.

flush()

Reinitializes the buffer. This method is not invoked by any other method. If needed, use with caution.

undo()

Invokes the undo callback for each object in buffer element at pre-decremented index, if this canUndo. You don't normally need to invoke this method explicitly.

redo()

Invokes the redo callback for each object in buffer element at index post-incremented, if this canRedo. You don't normally need to invoke this method explicitly.

handleEvent(evt)

Forks to this undo (CTRL + z), or this redo (SHIFT + CTRL + z).

register()

Adds keydown event listener to document.documentElement with this handler.

disable()

Removes keydown event listener to document.documentElement with this handler.

instance

max

Number; level of undos (set in the config file). To override, pass the new number to the constructor when creating an instance.

buffer

Array; its elements are arrays containing one or more object elements. The maximum buffer length (level of undos) is set in the config file.

index

Number; index for this buffer.