public boolean addEdit(UndoableEdit edit) { boolean result = super.addEdit(edit); if (result && editedTime == 0) { editedTime = System.currentTimeMillis(); } return result; }
@Override public void undo() { if (compoundEdit!=null) { compoundEdit.end(); } super.undo(); compoundEdit = null; }
private void startNewEdit (JTextComponent component, UndoableEdit atomicEdit) { if (edit != null) { // finish the last edit edit.end(); } edit = new MyCompoundEdit(); edit.addEdit(atomicEdit); super.undoableEditHappened(new UndoableEditEvent(component, edit)); lastOffset = component.getCaretPosition(); lastLength = component.getDocument().getLength(); }
synchronized( pendingEdits ) { if( pendingEditCount > 0 ) { pendingEdits.end(); super.addEdit( pendingEdits ); pendingEdits = new CompoundEdit(); pendingEditCount = 0; synchronized( pendingEdits ) { pendingEditCount++; return pendingEdits.addEdit( anEdit );
private void endCurrentCompoundEdit() { if (currentCompoundEdit != null) { currentCompoundEdit.end(); currentCompoundEdit = null; } }
private void undoPending() { synchronized( pendingEdits ) { if( pendingEditCount > 0 ) { pendingEdits.end(); pendingEdits.undo(); pendingEdits = new CompoundEdit(); pendingEditCount = 0; } } }
@Override public synchronized boolean addEdit(UndoableEdit anEdit) { if (_cache == null) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Create cache: " + anEdit); } _cache = new CompoundEdit(); boolean ret = _cache.addEdit(anEdit); if (ret) { _timer = new Timer(_delay, new ActionListener() { public void actionPerformed(ActionEvent e) { commitCache(); } }); _timer.setRepeats(false); _timer.start(); } return ret; } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Add to cache: " + anEdit); } if (_timer != null) { _timer.restart(); } return _cache.addEdit(anEdit); } }
TextArea.undo.setLimit(500); TextArea.compoundEdit = new CompoundEdit(); TextArea.undo.addEdit(TextArea.compoundEdit); if (! TextArea.highlight) { if (TextArea.newedit) { if (TextArea.compoundEdit.isInProgress()) TextArea.compoundEdit.end(); TextArea.compoundEdit = new CompoundEdit(); TextArea.undo.addEdit(TextArea.compoundEdit); } else if (! TextArea.compoundEdit.isInProgress()) { TextArea.compoundEdit = new CompoundEdit(); TextArea.undo.addEdit(TextArea.compoundEdit); TextArea.compoundEdit.addEdit(e.getEdit()); TextArea.newedit = false; TextArea.compoundEdit.end(); if (TextArea.undo.canUndo()) { try { TextArea.compoundEdit.end(); if (TextArea.undo.canRedo()) { try {
public void undoableEditHappened(UndoableEditEvent e) { if (compoundEdit == null || !compoundEdit.canUndo()) { compoundEdit = startCompoundEdit(e.getEdit()); lastLength = editor.getDocument().getLength(); return; } // See AbstractDocument.DefaultDocumentEvent.getPresentationName() method if("AbstractDocument.styleChangeText".equals(e.getEdit().getPresentationName())) { compoundEdit.addEdit(e.getEdit()); return; } int offsetChange = editor.getCaretPosition() - lastOffset; int lengthChange = editor.getDocument().getLength() - lastLength; if (Math.abs(offsetChange) == 1 && Math.abs(lengthChange) == 1) { compoundEdit.addEdit(e.getEdit()); lastOffset = editor.getCaretPosition(); lastLength = editor.getDocument().getLength(); return; } compoundEdit.end(); compoundEdit = startCompoundEdit(e.getEdit()); }
/** * Cancels the compound edit and undos all sub edits * made so far. */ public void cancel() { if( collToPerform != null ) { for( int i = 0; i < collToPerform.size(); i++ ) { ((PerformableEdit) collToPerform.get( i )).die(); } collToPerform = null; } end(); super.undo(); super.die(); cancelDone(); }
private void redoSaveActions() { if (onSaveTasksEdit != null) { checkLogOp(" saveActionsEdit.redo()", onSaveTasksEdit); // NOI18N onSaveTasksEdit.redo(); } }
/** * Used for ReplaceAll. * This merges all text changes made between the beginCompoundEdit() * and the endCompoundEdit() calls into only one undo event. */ public void beginCompoundEdit() { if (compoundEdit == null) compoundEdit = new CompoundEdit(); }
? undoGroup.getRedoPresentationName() : UndoRedoManager.super.getRedoPresentationName(); break; ? undoGroup.getUndoPresentationName() : UndoRedoManager.super.getUndoPresentationName(); break;
/** * Purge the undo history and * update the undo / redo actions enabled / disabled state. * * @see de.sciss.app.Document#setDirty( boolean ) */ public void discardAllEdits() { synchronized( pendingEdits ) { pendingEdits.die(); pendingEdits = new CompoundEdit(); pendingEditCount = 0; } super.discardAllEdits(); updateStates(); }
public String getRedoPresentationName() { if( presentationName != null ) { return( getResourceString( "menuRedo" ) + " " + presentationName ); } else { return super.getRedoPresentationName(); } }
@Override public void undoableEditHappened(UndoableEditEvent e) { // Start a new compound edit if (compoundEdit == null) { compoundEdit = startCompoundEdit(e.getEdit()); lastLength = editor.getDocument().getLength(); return; } // Check for an attribute change AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit(); if (event.getType().equals(DocumentEvent.EventType.CHANGE)) { compoundEdit.addEdit(e.getEdit()); return; } // Check for an incremental edit or backspace. // The change in Caret position and Document length should be either // 1 or -1 . int offsetChange = editor.getCaretPosition() - lastOffset; int lengthChange = editor.getDocument().getLength() - lastLength; if (Math.abs(offsetChange) == 1 && Math.abs(lengthChange) == 1) { compoundEdit.addEdit(e.getEdit()); lastOffset = editor.getCaretPosition(); lastLength = editor.getDocument().getLength(); return; } // Not incremental edit, end previous edit and start a new one compoundEdit.end(); compoundEdit = startCompoundEdit(e.getEdit()); }
super.fireUndoableEditUpdate(e); } else { compoundEdit.addEdit(e.getEdit()); } else { System.out.println("replace"); compoundEdit = new CompoundEdit(); super.fireUndoableEditUpdate(new UndoableEditEvent(this, compoundEdit)); super.replace(offset, length, text, attrs); compoundEdit.end(); compoundEdit = null;