Class DocumentUndoManager

java.lang.Object
org.eclipse.text.undo.DocumentUndoManager
All Implemented Interfaces:
IDocumentUndoManager

public class DocumentUndoManager extends Object implements IDocumentUndoManager
A standard implementation of a document-based undo manager that creates an undo history based on changes to its document.

Based on the 3.1 implementation of DefaultUndoManager, it was implemented using the document-related manipulations defined in the original DefaultUndoManager, by separating the document manipulations from the viewer-specific processing.

The classes representing individual text edits (formerly text commands) were promoted from inner types to their own classes in order to support reassignment to a different undo manager.

This class is not intended to be subclassed.

Since:
3.2
See Also:
Restriction:
This class is not intended to be subclassed by clients.
  • Constructor Details

    • DocumentUndoManager

      public DocumentUndoManager(IDocument document)
      Create a DocumentUndoManager for the given document.
      Parameters:
      document - the document whose undo history is being managed.
  • Method Details

    • addDocumentUndoListener

      public void addDocumentUndoListener(IDocumentUndoListener listener)
      Description copied from interface: IDocumentUndoManager
      Adds the specified listener to the list of document undo listeners that are notified before and after changes are undone or redone in the document. This method has no effect if the instance being added is already in the list.

      Notifications will not be received if there are no clients connected to the receiver. Registering a document undo listener does not implicitly connect the listener to the receiver.

      Document undo listeners must be prepared to receive notifications from a background thread. Any UI access occurring inside the implementation must be properly synchronized using the techniques specified by the client's widget library.

      Specified by:
      addDocumentUndoListener in interface IDocumentUndoManager
      Parameters:
      listener - the document undo listener to be added as a listener
    • removeDocumentUndoListener

      public void removeDocumentUndoListener(IDocumentUndoListener listener)
      Description copied from interface: IDocumentUndoManager
      Removes the specified listener from the list of document undo listeners.

      Removing a listener which is not registered has no effect

      Specified by:
      removeDocumentUndoListener in interface IDocumentUndoManager
      Parameters:
      listener - the document undo listener to be removed
    • getUndoContext

      public IUndoContext getUndoContext()
      Description copied from interface: IDocumentUndoManager
      Returns the undo context registered for this document
      Specified by:
      getUndoContext in interface IDocumentUndoManager
      Returns:
      the undo context registered for this document
    • commit

      public void commit()
      Description copied from interface: IDocumentUndoManager
      Closes the currently open text edit and open a new one.
      Specified by:
      commit in interface IDocumentUndoManager
    • reset

      public void reset()
      Description copied from interface: IDocumentUndoManager
      Resets the history of the undo manager. After that call, there aren't any undo-able or redo-able text changes.
      Specified by:
      reset in interface IDocumentUndoManager
    • redoable

      public boolean redoable()
      Description copied from interface: IDocumentUndoManager
      Returns whether at least one text change can be repeated. A text change can be repeated only if it was executed and rolled back.
      Specified by:
      redoable in interface IDocumentUndoManager
      Returns:
      true if at least on text change can be repeated
    • undoable

      public boolean undoable()
      Description copied from interface: IDocumentUndoManager
      Returns whether at least one text change can be rolled back.
      Specified by:
      undoable in interface IDocumentUndoManager
      Returns:
      true if at least one text change can be rolled back
    • redo

      public void redo() throws ExecutionException
      Description copied from interface: IDocumentUndoManager
      Repeats the most recently rolled back text change.
      Specified by:
      redo in interface IDocumentUndoManager
      Throws:
      ExecutionException - if an exception occurred during redo
    • undo

      public void undo() throws ExecutionException
      Description copied from interface: IDocumentUndoManager
      Rolls back the most recently executed text change.
      Specified by:
      undo in interface IDocumentUndoManager
      Throws:
      ExecutionException - if an exception occurred during undo
    • connect

      public void connect(Object client)
      Description copied from interface: IDocumentUndoManager
      Connects to the undo manager. Used to signify that a client is monitoring the history kept by the undo manager. This message has no effect if the client is already connected.
      Specified by:
      connect in interface IDocumentUndoManager
      Parameters:
      client - the object connecting to the undo manager
    • disconnect

      public void disconnect(Object client)
      Description copied from interface: IDocumentUndoManager
      Disconnects from the undo manager. Used to signify that a client is no longer monitoring the history kept by the undo manager. If all clients have disconnected from the undo manager, the undo history will be deleted.
      Specified by:
      disconnect in interface IDocumentUndoManager
      Parameters:
      client - the object disconnecting from the undo manager
    • beginCompoundChange

      public void beginCompoundChange()
      Description copied from interface: IDocumentUndoManager
      Signals the undo manager that all subsequent changes until endCompoundChange is called are to be undone in one piece.
      Specified by:
      beginCompoundChange in interface IDocumentUndoManager
    • endCompoundChange

      public void endCompoundChange()
      Description copied from interface: IDocumentUndoManager
      Signals the undo manager that the sequence of changes which started with beginCompoundChange has been finished. All subsequent changes are considered to be individually undo-able.
      Specified by:
      endCompoundChange in interface IDocumentUndoManager
    • setMaximalUndoLevel

      public void setMaximalUndoLevel(int undoLimit)
      Description copied from interface: IDocumentUndoManager
      Sets the limit of the undo history to the specified value. The provided limit will supersede any previously set limit.
      Specified by:
      setMaximalUndoLevel in interface IDocumentUndoManager
      Parameters:
      undoLimit - the length of this undo manager's history
    • transferUndoHistory

      public void transferUndoHistory(IDocumentUndoManager manager)
      Description copied from interface: IDocumentUndoManager
      Transfers the undo history from the specified document undo manager to this undo manager. This message should only be used when it is known that the content of the document of the original undo manager when the last undo operation was recorded is the same as this undo manager's current document content, since the undo history is based on document indexes. It is the responsibility of the caller to ensure that this call is used correctly.
      Specified by:
      transferUndoHistory in interface IDocumentUndoManager
      Parameters:
      manager - the document undo manger whose history is to be transferred to the receiver