Package groovy.console.ui.text
Class TextUndoManager
java.lang.Object
javax.swing.undo.AbstractUndoableEdit
javax.swing.undo.CompoundEdit
javax.swing.undo.UndoManager
groovy.console.ui.text.TextUndoManager
- All Implemented Interfaces:
Serializable,EventListener,UndoableEditListener,UndoableEdit
To use this, simply drop this as an UndoableEditListener into your document,
and then create actions to call undo/redo as needed (checking can undo/redo
first, of course).
- See Also:
-
Field Summary
Fields inherited from class javax.swing.undo.CompoundEdit
editsFields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a listener for undo/redo state changes.voiddie()voidprotected voidfirePropertyChangeEvent(String name, boolean oldValue, boolean newValue) Fires an undo-state property change event.booleanIndicates whether the document differs from the last reset point.voidredo()protected voidredoTo(UndoableEdit edit) voidRemoves a listener for undo/redo state changes.voidreset()Marks the current undo position as the unmodified state.voidsetRecording(boolean recording) Toggle recording of undoable edits.protected voidtrimEdits(int from, int to) voidundo()voidMethods inherited from class javax.swing.undo.UndoManager
addEdit, canRedo, canUndo, canUndoOrRedo, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, setLimit, toString, trimForLimit, undoOrRedo, undoToMethods inherited from class javax.swing.undo.CompoundEdit
getPresentationName, isInProgress, isSignificant, lastEditMethods inherited from class javax.swing.undo.AbstractUndoableEdit
replaceEdit
-
Constructor Details
-
TextUndoManager
public TextUndoManager()Creates a new instance of TextUndoManager.
-
-
Method Details
-
setRecording
public void setRecording(boolean recording) Toggle recording of undoable edits. Used to suppress capture of programmatic style changes (e.g. a theme switch re-parsing the document) that shouldn't be reachable via user-initiated Undo.- Since:
- 6.0.0
-
addPropertyChangeListener
Registers a listener for undo/redo state changes.- Parameters:
pcl- the listener to add
-
die
public void die()- Specified by:
diein interfaceUndoableEdit- Overrides:
diein classCompoundEdit
-
discardAllEdits
public void discardAllEdits()- Overrides:
discardAllEditsin classUndoManager
-
firePropertyChangeEvent
Fires an undo-state property change event.- Parameters:
name- the property nameoldValue- the previous valuenewValue- the new value
-
hasChanged
public boolean hasChanged()Indicates whether the document differs from the last reset point.- Returns:
trueif undo history contains unreset edits
-
redo
- Specified by:
redoin interfaceUndoableEdit- Overrides:
redoin classUndoManager- Throws:
CannotRedoException
-
redoTo
- Overrides:
redoToin classUndoManager
-
removePropertyChangeListener
Removes a listener for undo/redo state changes.- Parameters:
pcl- the listener to remove
-
reset
public void reset()Marks the current undo position as the unmodified state. -
trimEdits
protected void trimEdits(int from, int to) - Overrides:
trimEditsin classUndoManager
-
undo
- Specified by:
undoin interfaceUndoableEdit- Overrides:
undoin classUndoManager- Throws:
CannotUndoException
-
undoableEditHappened
- Specified by:
undoableEditHappenedin interfaceUndoableEditListener- Overrides:
undoableEditHappenedin classUndoManager
-