/** * Re-applies the change described by this command that previously been * rolled back. Also selects and reveals the change. * * @param monitor the progress monitor to use if necessary * @param uiInfo an adaptable that can provide UI info if needed * @return the status */ @Override public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) { if (isValid()) { redoTextChange(); resetProcessChangeSate(); selectAndReveal(fStart, fText == null ? 0 : fText.length()); return Status.OK_STATUS; } return IOperationHistory.OPERATION_INVALID_STATUS; }
/** * Undo the change described by this command. Also selects and * reveals the change. * * @param monitor the progress monitor to use if necessary * @param uiInfo an adaptable that can provide UI info if needed * @return the status */ @Override public IStatus undo(IProgressMonitor monitor, IAdaptable uiInfo) { if (isValid()) { undoTextChange(); selectAndReveal(fStart, fPreservedText == null ? 0 : fPreservedText.length()); resetProcessChangeSate(); return Status.OK_STATUS; } return IOperationHistory.OPERATION_INVALID_STATUS; }
/** * Re-applies the change described by this command that previously been * rolled back. Also selects and reveals the change. * * @param monitor the progress monitor to use if necessary * @param uiInfo an adaptable that can provide UI info if needed * @return the status */ @Override public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) { if (isValid()) { redoTextChange(); resetProcessChangeSate(); selectAndReveal(fStart, fText == null ? 0 : fText.length()); return Status.OK_STATUS; } return IOperationHistory.OPERATION_INVALID_STATUS; }
@Override public boolean canUndo() { if (isConnected() && isValid()) { IDocument doc= fTextViewer.getDocument(); if (doc instanceof IDocumentExtension4) { this == fHistory.getUndoOperation(fUndoContext) && // this is the latest operation this != fCurrent && // there is a more current operation not on the stack !fCurrent.isValid() && // the current operation is not a valid document modification
@Override public boolean canUndo() { if (isConnected() && isValid()) { IDocument doc= fTextViewer.getDocument(); if (doc instanceof IDocumentExtension4) { this == fHistory.getUndoOperation(fUndoContext) && // this is the latest operation this != fCurrent && // there is a more current operation not on the stack !fCurrent.isValid() && // the current operation is not a valid document modification
@Override public void documentChanged(DocumentEvent event) { fPreservedRedoModificationStamp= event.getModificationStamp(); // record the current valid state for the top operation in case it remains the // top operation but changes state. IUndoableOperation op= fHistory.getUndoOperation(fUndoContext); boolean wasValid= false; if (op != null) wasValid= op.canUndo(); // Process the change, providing the before and after timestamps processChange(event.getOffset(), event.getOffset() + event.getLength(), event.getText(), fReplacedText, fPreservedUndoModificationStamp, fPreservedRedoModificationStamp); // now update fCurrent with the latest buffers from the document change. fCurrent.pretendCommit(); if (op == fCurrent) { // if the document change did not cause a new fCurrent to be created, then we should // notify the history that the current operation changed if its validity has changed. if (wasValid != fCurrent.isValid()) fHistory.operationChanged(op); } else { // if the change created a new fCurrent that we did not yet add to the // stack, do so if it's valid and we are not in the middle of a compound change. if (fCurrent != fLastAddedCommand && fCurrent.isValid()) { addToCommandStack(fCurrent); } } } }
@Override public void documentChanged(DocumentEvent event) { fPreservedRedoModificationStamp= event.getModificationStamp(); // record the current valid state for the top operation in case it remains the // top operation but changes state. IUndoableOperation op= fHistory.getUndoOperation(fUndoContext); boolean wasValid= false; if (op != null) wasValid= op.canUndo(); // Process the change, providing the before and after timestamps processChange(event.getOffset(), event.getOffset() + event.getLength(), event.getText(), fReplacedText, fPreservedUndoModificationStamp, fPreservedRedoModificationStamp); // now update fCurrent with the latest buffers from the document change. fCurrent.pretendCommit(); if (op == fCurrent) { // if the document change did not cause a new fCurrent to be created, then we should // notify the history that the current operation changed if its validity has changed. if (wasValid != fCurrent.isValid()) fHistory.operationChanged(op); } else { // if the change created a new fCurrent that we did not yet add to the // stack, do so if it's valid and we are not in the middle of a compound change. if (fCurrent != fLastAddedCommand && fCurrent.isValid()) { addToCommandStack(fCurrent); } } } }
/** * Undo the change described by this command. Also selects and * reveals the change. * * @param monitor the progress monitor to use if necessary * @param uiInfo an adaptable that can provide UI info if needed * @return the status */ @Override public IStatus undo(IProgressMonitor monitor, IAdaptable uiInfo) { if (isValid()) { undoTextChange(); selectAndReveal(fStart, fPreservedText == null ? 0 : fPreservedText.length()); resetProcessChangeSate(); return Status.OK_STATUS; } return IOperationHistory.OPERATION_INVALID_STATUS; }
/** * Attempt a commit of this command and answer true if a new * fCurrent was created as a result of the commit. * * @return true if the command was committed and created a * new fCurrent, false if not. * @since 3.1 */ protected boolean attemptCommit() { pretendCommit(); if (isValid()) { DefaultUndoManager.this.commit(); return true; } return false; }
/** * Closes the current editing command and opens a new one. */ private void commit() { // if fCurrent has never been placed on the command stack, do so now. // this can happen when there are multiple programmatically commits in a single // document change. if (fLastAddedCommand != fCurrent) { fCurrent.pretendCommit(); if (fCurrent.isValid()) addToCommandStack(fCurrent); } fCurrent.commit(); }
@Override public boolean canRedo() { if (isConnected() && isValid()) { IDocument doc= fTextViewer.getDocument(); if (doc instanceof IDocumentExtension4) { long docStamp= ((IDocumentExtension4)doc).getModificationStamp(); return docStamp == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || docStamp == getUndoModificationStamp(); } // if there is no timestamp to check, simply return true per the 3.0.1 behavior return true; } return false; }
/** * Closes the current editing command and opens a new one. */ private void commit() { // if fCurrent has never been placed on the command stack, do so now. // this can happen when there are multiple programmatically commits in a single // document change. if (fLastAddedCommand != fCurrent) { fCurrent.pretendCommit(); if (fCurrent.isValid()) addToCommandStack(fCurrent); } fCurrent.commit(); }
@Override public boolean canRedo() { if (isConnected() && isValid()) { IDocument doc= fTextViewer.getDocument(); if (doc instanceof IDocumentExtension4) { long docStamp= ((IDocumentExtension4)doc).getModificationStamp(); return docStamp == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || docStamp == getUndoModificationStamp(); } // if there is no timestamp to check, simply return true per the 3.0.1 behavior return true; } return false; }
/** * Attempt a commit of this command and answer true if a new * fCurrent was created as a result of the commit. * * @return true if the command was committed and created a * new fCurrent, false if not. * @since 3.1 */ protected boolean attemptCommit() { pretendCommit(); if (isValid()) { DefaultUndoManager.this.commit(); return true; } return false; }