@Override public void connect(ITextViewer textViewer) { if (!isConnected() && textViewer != null) { fTextViewer= textViewer; fTextBuffer= new StringBuffer(); fPreservedTextBuffer= new StringBuffer(); if (fUndoContext == null) fUndoContext= new ObjectUndoContext(this); fHistory.setLimit(fUndoContext, fUndoLevel); initializeCommandStack(); // open up the current command fCurrent= new TextCommand(fUndoContext); fPreviousDelete= new TextCommand(fUndoContext); addListeners(); } }
if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; fTextBuffer.append(insertedText); fCurrent.fRedoModificationStamp= afterChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= afterChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; fPreviousDelete.set(modelStart, modelEnd); if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp;
/** * Returns the redo modification stamp. * * @return the redo modification stamp * @since 3.1 */ @Override protected long getRedoModificationStamp() { if (fStart > -1) return super.getRedoModificationStamp(); else if (fCommands.size() > 0) return fCommands.get(fCommands.size()-1).getRedoModificationStamp(); return fRedoModificationStamp; } }
if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; fTextBuffer.append(insertedText); fCurrent.fRedoModificationStamp= afterChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= afterChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; fPreviousDelete.set(modelStart, modelEnd); if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp;
@Override public boolean canUndo() { if (isConnected() && isValid()) { IDocument doc= fTextViewer.getDocument(); if (doc instanceof IDocumentExtension4) { docStamp == getRedoModificationStamp(); 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) { docStamp == getRedoModificationStamp(); 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; }
/** * 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; }
/** * 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; }
@Override protected void updateCommand() { // first gather the data from the buffers super.updateCommand(); // the result of the command update is stored as a child command TextCommand c= new TextCommand(fUndoContext); c.fStart= fStart; c.fEnd= fEnd; c.fText= fText; c.fPreservedText= fPreservedText; c.fUndoModificationStamp= fUndoModificationStamp; c.fRedoModificationStamp= fRedoModificationStamp; add(c); // clear out all indexes now that the child is added reinitialize(); }
/** * Commits the current change into this command. */ protected void commit() { if (fStart < 0) { if (fFoldingIntoCompoundChange) { fCurrent= createCurrent(); } else { reinitialize(); } } else { updateCommand(); fCurrent= createCurrent(); } resetProcessChangeSate(); }
/** * Commits the current change into this command. */ protected void commit() { if (fStart < 0) { if (fFoldingIntoCompoundChange) { fCurrent= createCurrent(); } else { reinitialize(); } } else { updateCommand(); fCurrent= createCurrent(); } resetProcessChangeSate(); }
/** * 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; }
@Override public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) { resetProcessChangeSate(); int size= fCommands.size(); if (size > 0) { TextCommand c; for (int i= 0; i < size -1; ++i) { c= fCommands.get(i); c.redoTextChange(); } c= fCommands.get(size -1); c.redo(monitor, uiInfo); } return Status.OK_STATUS; }
@Override public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) { resetProcessChangeSate(); int size= fCommands.size(); if (size > 0) { TextCommand c; for (int i= 0; i < size -1; ++i) { c= fCommands.get(i); c.redoTextChange(); } c= fCommands.get(size -1); c.redo(monitor, uiInfo); } return Status.OK_STATUS; }
/** * Returns the redo modification stamp. * * @return the redo modification stamp * @since 3.1 */ @Override protected long getRedoModificationStamp() { if (fStart > -1) return super.getRedoModificationStamp(); else if (fCommands.size() > 0) return fCommands.get(fCommands.size()-1).getRedoModificationStamp(); return fRedoModificationStamp; } }
@Override protected void updateCommand() { // first gather the data from the buffers super.updateCommand(); // the result of the command update is stored as a child command TextCommand c= new TextCommand(fUndoContext); c.fStart= fStart; c.fEnd= fEnd; c.fText= fText; c.fPreservedText= fPreservedText; c.fUndoModificationStamp= fUndoModificationStamp; c.fRedoModificationStamp= fRedoModificationStamp; add(c); // clear out all indexes now that the child is added reinitialize(); }