/** * Creates an undo manager for use in this text area. * * @return The undo manager. */ protected RUndoManager createUndoManager() { return new RUndoManager(this); }
if (canUndo()) { a.setEnabled(true); text = getUndoPresentationName(); a.putValue(Action.NAME, text); a.putValue(Action.SHORT_DESCRIPTION, text); if (canRedo()) { a.setEnabled(true); text = getRedoPresentationName(); a.putValue(Action.NAME, text); a.putValue(Action.SHORT_DESCRIPTION, text);
/** * Removes all undoable edits from this document's undo manager. This * method also makes the undo/redo actions disabled. */ /* * NOTE: For some reason, it appears I have to create an entirely new * <code>undoManager</code> for undo/redo to continue functioning * properly; if I don't, it only ever lets you do one undo. Not * too sure why this is... */ public void discardAllEdits() { undoManager.discardAllEdits(); getDocument().removeUndoableEditListener(undoManager); undoManager = createUndoManager(); getDocument().addUndoableEditListener(undoManager); undoManager.updateActions(); }
/** * Ends an "atomic" edit. * * @see #beginInternalAtomicEdit() */ public void endInternalAtomicEdit() { if (internalAtomicEditDepth>0 && --internalAtomicEditDepth==0) { addEdit(compoundEdit); compoundEdit.end(); compoundEdit = null; updateActions(); // Needed to show the new display name. } }
/** * Removes all undoable edits from this document's undo manager. This * method also makes the undo/redo actions disabled. */ /* * NOTE: For some reason, it appears I have to create an entirely new * <code>undoManager</code> for undo/redo to continue functioning * properly; if I don't, it only ever lets you do one undo. Not * too sure why this is... */ public void discardAllEdits() { undoManager.discardAllEdits(); getDocument().removeUndoableEditListener(undoManager); undoManager = new RUndoManager(this); getDocument().addUndoableEditListener(undoManager); undoManager.updateActions(); }
/** * "Plays back" the last recorded macro in this text area. */ public synchronized void playbackLastMacro() { if (currentMacro!=null) { List<MacroRecord> macroRecords = currentMacro.getMacroRecords(); if (!macroRecords.isEmpty()) { Action[] actions = getActions(); undoManager.beginInternalAtomicEdit(); try { for (MacroRecord record : macroRecords) { for (int i=0; i<actions.length; i++) { if ((actions[i] instanceof RecordableTextAction) && record.id.equals( ((RecordableTextAction)actions[i]).getMacroID())) { actions[i].actionPerformed( new ActionEvent(this, ActionEvent.ACTION_PERFORMED, record.actionCommand)); break; } } } } finally { undoManager.endInternalAtomicEdit(); } } } }
compoundEdit = startCompoundEdit(e.getEdit()); updateActions(); return; compoundEdit = startCompoundEdit(e.getEdit());
/** * {@inheritDoc} */ @Override public void redo() { super.redo(); updateActions(); }
/** * Returns whether a redo is possible. * * @see #canUndo() * @see #redoLastAction() */ public boolean canRedo() { return undoManager.canRedo(); }
/** * Returns whether an undo is possible. * * @see #canRedo() * @see #undoLastAction() */ public boolean canUndo() { return undoManager.canUndo(); }
private RCompoundEdit startCompoundEdit(UndoableEdit edit) { lastOffset = textArea.getCaretPosition(); compoundEdit = new RCompoundEdit(); compoundEdit.addEdit(edit); addEdit(compoundEdit); return compoundEdit; }
/** * Completes an "atomic" edit. * * @see #beginAtomicEdit() */ public void endAtomicEdit() { undoManager.endInternalAtomicEdit(); }
/** * Begins an "atomic edit." All text editing operations between this call * and the next call to <tt>endAtomicEdit()</tt> will be treated as a * single operation by the undo manager.<p> * * Using this method should be done with great care. You should probably * wrap the call to <tt>endAtomicEdit()</tt> in a <tt>finally</tt> block: * * <pre> * textArea.beginAtomicEdit(); * try { * // Do editing * } finally { * textArea.endAtomicEdit(); * } * </pre> * * @see #endAtomicEdit() */ public void beginAtomicEdit() { undoManager.beginInternalAtomicEdit(); }
@Override public void loadContent(@Nullable final File file) throws IOException { this.ignoreChange = true; try { if (file != null) { this.editor.setText(FileUtils.readFileToString(file, "UTF-8")); //NOI18N this.editor.setCaretPosition(0); } } finally { this.ignoreChange = false; } this.undoManager.discardAllEdits(); this.title.setChanged(false); this.mainPanel.revalidate(); this.mainPanel.repaint(); }
/** * Removes all undoable edits from this document's undo manager. This * method also makes the undo/redo actions disabled. */ /* * NOTE: For some reason, it appears I have to create an entirely new * <code>undoManager</code> for undo/redo to continue functioning * properly; if I don't, it only ever lets you do one undo. Not * too sure why this is... */ public void discardAllEdits() { undoManager.discardAllEdits(); getDocument().removeUndoableEditListener(undoManager); undoManager = new RUndoManager(this); getDocument().addUndoableEditListener(undoManager); undoManager.updateActions(); }
undoManager.beginInternalAtomicEdit(); ((AbstractDocument)doc).replace(start, end - start, str, null); throw new IllegalArgumentException(e.getMessage()); } finally { undoManager.endInternalAtomicEdit();