? awt/patchsrc
Index: awt/build.xml
===================================================================
RCS file: /cvs/openide/awt/build.xml,v
retrieving revision 1.7
diff -u -r1.7 build.xml
--- awt/build.xml 1 Jul 2006 09:07:24 -0000 1.7
+++ awt/build.xml 9 May 2007 05:25:26 -0000
@@ -21,5 +21,55 @@
+ * Three use cases are supported. + *
+ *If edits are already being coalesced and some have been + * accumulated, they are commited as an atomic group and a new + * group is started. + * @see #addEdit + * @see #endUndoGroup + * @see #commitUndoGroup + */ + public synchronized void beginUndoGroup() { + commitUndoGroup(); + buildUndoGroup = true; + } + + /** + * Direct this UndoGroupManager to stop coalescing edits. + * {@link #commitUndoGroup} is invoked to save accumulated edits as + * an atomic group. + * Until beginUndoGroupManager is invoked, + * received UndoableEdits are added singly. + *
+ * This has no effect if edits are not being coalesced, for example + * if beginUndoGroup has not been called. + * @see #commitUndoGroup + */ + public synchronized void endUndoGroup() { + buildUndoGroup = false; + commitUndoGroup(); + } + + /** + * Commit any accumulated UndoableEdits as an atomic + * undo/redo group. {@link CompoundEdit#end} + * is invoked on the CompoundEdit and it is added as a single + * UndoableEdit to this UndoManager. + *
+ * If edits are currently being coalesced, a new undo group is started. + * This has no effect if edits are not being coalesced, for example + * beginUndoGroup has not been called. + */ + public synchronized void commitUndoGroup() { + if(undoGroup == null) { + return; + } + // super.addEdit may end up in this.addEdit, + // so buildUndoGroup must be false + boolean restoreBuildUndoGroup = buildUndoGroup; + buildUndoGroup = false; + + undoGroup.end(); + super.addEdit(undoGroup); + undoGroup = null; + + buildUndoGroup = restoreBuildUndoGroup; + } + + + /** + * If this UndoManager is coalescing edits then add + * anEdit to the accumulating CompoundEdit. + * Otherwise, add it to this UndoManager. In either case the + * edit is saved for later undo or redo. + * @return {@inheritDoc} + * @see #beginUndoGroup + * @see #endUndoGroup + * @see #commitUndoGroup + */ + public synchronized boolean addEdit(UndoableEdit anEdit) { + if(!isInProgress()) + return false; + if(buildUndoGroup) { + if(undoGroup == null) + undoGroup = new CompoundEdit(); + return undoGroup.addEdit(anEdit); + } else { + return super.addEdit(anEdit); + } + } + + /** {@inheritDoc} */ + public synchronized void discardAllEdits() { + commitUndoGroup(); + super.discardAllEdits(); + } + + // + // TODO: limits + // + + /** {@inheritDoc} */ + public synchronized void undoOrRedo() { + commitUndoGroup(); + super.undoOrRedo(); + } + + /** {@inheritDoc} */ + public synchronized boolean canUndoOrRedo() { + if(undoGroup != null) + return true; + return super.canUndoOrRedo(); + } + + /** {@inheritDoc} */ + public synchronized void undo() { + commitUndoGroup(); + super.undo(); + } + + /** {@inheritDoc} */ + public synchronized boolean canUndo() { + if(undoGroup != null) + return true; + return super.canUndo(); + } + + /** {@inheritDoc} */ + public synchronized void redo() { + if(undoGroup != null) + throw new CannotRedoException(); + super.redo(); + } + + /** {@inheritDoc} */ + public synchronized boolean canRedo() { + if(undoGroup != null) + return false; + return super.canRedo(); + } + + /** {@inheritDoc} */ + public synchronized void end() { + commitUndoGroup(); + super.end(); + } + + /** {@inheritDoc} */ + public synchronized String getUndoOrRedoPresentationName() { + if(undoGroup != null) + return undoGroup.getUndoPresentationName(); + return super.getUndoOrRedoPresentationName(); + } + + /** {@inheritDoc} */ + public synchronized String getUndoPresentationName() { + if(undoGroup != null) + return undoGroup.getUndoPresentationName(); + return super.getUndoPresentationName(); + } + + /** {@inheritDoc} */ + public synchronized String getRedoPresentationName() { + if(undoGroup != null) + return undoGroup.getRedoPresentationName(); + return super.getRedoPresentationName(); + } + + /** {@inheritDoc} */ + public boolean isSignificant() { + if(undoGroup != null && undoGroup.isSignificant()) { + return true; + } + return super.isSignificant(); + } + + /** {@inheritDoc} */ + public synchronized void die() { + commitUndoGroup(); + super.die(); + } + + /** {@inheritDoc} */ + public String getPresentationName() { + if(undoGroup != null) + return undoGroup.getPresentationName(); + return super.getPresentationName(); + } + + // The protected methods are only accessed from + // synchronized methods that commitUndoGroup, + // they do not need to be in this class + /*protected UndoableEdit editToBeUndone() { + if(undoGroup != null) + return null; + return super.editToBeUndone(); + } + + protected UndoableEdit editToBeRedone() { + if(undoGroup != null) + return null; + return super.editToBeRedone(); + } + + protected void undoTo(UndoableEdit edit) { + if(undoGroup != null) + throw new CannotUndoException(); + super.undoTo(edit); + } + + protected void redoTo(UndoableEdit edit) { + if(undoGroup != null) + throw new CannotRedoException(); + super.redoTo(edit); + }*/ } }