@Override public void beginCompoundChange() { if (isConnected()) { fFoldingIntoCompoundChange= true; commit(); } }
@Override public void disconnect() { if (isConnected()) { removeListeners(); fCurrent= null; fTextViewer= null; disposeCommandStack(); fTextBuffer= null; fPreservedTextBuffer= null; fUndoContext= null; } }
@Override public void reset() { if (isConnected()) { initializeCommandStack(); fCurrent= new TextCommand(fUndoContext); fFoldingIntoCompoundChange= false; fInserting= false; fOverwriting= false; fTextBuffer.setLength(0); fPreservedTextBuffer.setLength(0); fPreservedUndoModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; fPreservedRedoModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; } }
@Override public void redo() { if (isConnected() && redoable()) { try { fHistory.redo(fUndoContext, null, null); } catch (ExecutionException ex) { openErrorDialog(JFaceTextMessages.getString("DefaultUndoManager.error.redoFailed.title"), ex); //$NON-NLS-1$ } } }
@Override public void undo() { if (isConnected() && undoable()) { try { fHistory.undo(fUndoContext, null, null); } catch (ExecutionException ex) { openErrorDialog(JFaceTextMessages.getString("DefaultUndoManager.error.undoFailed.title"), ex); //$NON-NLS-1$ } } }
@Override public void connect(ITextViewer textViewer) { if (!isConnected() && textViewer != null) { fTextViewer= textViewer; fTextBuffer= new StringBuilder(); fPreservedTextBuffer= new StringBuilder(); 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(); } }
@Override public void setMaximalUndoLevel(int undoLevel) { fUndoLevel= Math.max(0, undoLevel); if (isConnected()) { fHistory.setLimit(fUndoContext, fUndoLevel); } }
/** * Unregister all previously installed listeners from the text viewer. */ private void removeListeners() { StyledText text= fTextViewer.getTextWidget(); if (text != null) { if (fKeyAndMouseListener != null) { text.removeMouseListener(fKeyAndMouseListener); text.removeKeyListener(fKeyAndMouseListener); fKeyAndMouseListener= null; } if (fTextInputListener != null) { fTextViewer.removeTextInputListener(fTextInputListener); fTextInputListener= null; } listenToTextChanges(false); fHistory.removeOperationHistoryListener(fHistoryListener); } }
/** * 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 void run() { // if we are undoing/redoing a command we generated, then ignore // the document changes associated with this undo or redo. if (event.getOperation() instanceof TextCommand) { if (fTextViewer instanceof TextViewer) ((TextViewer)fTextViewer).ignoreAutoEditStrategies(true); listenToTextChanges(false); // in the undo case only, make sure compounds are closed if (type == OperationHistoryEvent.ABOUT_TO_UNDO) { if (fFoldingIntoCompoundChange) { endCompoundChange(); } } } else { // the undo or redo has our context, but it is not one of // our commands. We will listen to the changes, but will // reset the state that tracks the undo/redo history. commit(); fLastAddedCommand= null; } } });
if ((length == 1) || isWhitespaceText(insertedText)) {
@Override public void redo() { if (isConnected() && redoable()) { try { fHistory.redo(fUndoContext, null, null); } catch (ExecutionException ex) { openErrorDialog(JFaceTextMessages.getString("DefaultUndoManager.error.redoFailed.title"), ex); //$NON-NLS-1$ } } }
@Override public void undo() { if (isConnected() && undoable()) { try { fHistory.undo(fUndoContext, null, null); } catch (ExecutionException ex) { openErrorDialog(JFaceTextMessages.getString("DefaultUndoManager.error.undoFailed.title"), ex); //$NON-NLS-1$ } } }
@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(); } }
@Override public void setMaximalUndoLevel(int undoLevel) { fUndoLevel= Math.max(0, undoLevel); if (isConnected()) { fHistory.setLimit(fUndoContext, fUndoLevel); } }
/** * Unregister all previously installed listeners from the text viewer. */ private void removeListeners() { StyledText text= fTextViewer.getTextWidget(); if (text != null) { if (fKeyAndMouseListener != null) { text.removeMouseListener(fKeyAndMouseListener); text.removeKeyListener(fKeyAndMouseListener); fKeyAndMouseListener= null; } if (fTextInputListener != null) { fTextViewer.removeTextInputListener(fTextInputListener); fTextInputListener= null; } listenToTextChanges(false); fHistory.removeOperationHistoryListener(fHistoryListener); } }
/** * 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(); }
if ((length == 1) || isWhitespaceText(insertedText)) {
@Override public void disconnect() { if (isConnected()) { removeListeners(); fCurrent= null; fTextViewer= null; disposeCommandStack(); fTextBuffer= null; fPreservedTextBuffer= null; fUndoContext= null; } }