Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2006-01-24 06:24:35 -0500
committerDani Megert2006-01-24 06:24:35 -0500
commit6844a9f9b075253dc468a6328a62848d6c68c6d9 (patch)
tree110f885f1576a170adcf4d37027d1911e8c118a2 /org.eclipse.text/src/org/eclipse/text/undo
parent9e0a0e4bf90c5b897ff8ec6f3cdcd98287308bc7 (diff)
downloadeclipse.platform.text-6844a9f9b075253dc468a6328a62848d6c68c6d9.tar.gz
eclipse.platform.text-6844a9f9b075253dc468a6328a62848d6c68c6d9.tar.xz
eclipse.platform.text-6844a9f9b075253dc468a6328a62848d6c68c6d9.zip
First cut of fix for bug 89599: [api][typing] Text Editor Undo stack (context) should be keyed of common document
Diffstat (limited to 'org.eclipse.text/src/org/eclipse/text/undo')
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoEvent.java22
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java8
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/UndoableCompoundTextChange.java34
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/UndoableTextChange.java21
4 files changed, 34 insertions, 51 deletions
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoEvent.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoEvent.java
index 3b13af2a7..0474e1813 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoEvent.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoEvent.java
@@ -11,8 +11,6 @@
package org.eclipse.text.undo;
-import org.eclipse.core.runtime.IAdaptable;
-
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.IDocument;
@@ -74,8 +72,8 @@ public class DocumentUndoEvent {
/** Bit mask of event types describing the event */
private int fEventType;
- /** The adaptable describing UI context of the triggering undo. */
- private IAdaptable fInfoAdapter;
+ /** The the source that triggered this event or <code>null</code> if unknown. */
+ private Object fSource;
/**
* Creates a new document event.
@@ -85,9 +83,9 @@ public class DocumentUndoEvent {
* @param text the substitution text
* @param preservedText the replaced text
* @param eventType a bit mask describing the type(s) of event
- * @param uiInfo an adapter providing information about the triggering undo or redo or <code>null</code>
+ * @param source the source that triggered this event or <code>null</code> if unknown
*/
- DocumentUndoEvent(IDocument doc, int offset, String text, String preservedText, int eventType, IAdaptable uiInfo) {
+ DocumentUndoEvent(IDocument doc, int offset, String text, String preservedText, int eventType, Object source) {
Assert.isNotNull(doc);
Assert.isTrue(offset >= 0);
@@ -97,7 +95,7 @@ public class DocumentUndoEvent {
fText= text;
fPreservedText= preservedText;
fEventType= eventType;
- fInfoAdapter= uiInfo;
+ fSource= source;
}
/**
@@ -146,14 +144,12 @@ public class DocumentUndoEvent {
}
/**
- * Returns the adapter providing additional undo or redo information.
+ * Returns the source that triggered this event.
*
- * @return the adapter providing adapters for additional contextual
- * information about the triggering undo or redo. This adapter
- * may be <code>null</code>.
+ * @return the source that triggered this event.
*/
- public IAdaptable getInfoAdapter() {
- return fInfoAdapter;
+ public Object getSource() {
+ return fSource;
}
/**
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
index c94c7df7c..009e01b9d 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
@@ -22,7 +22,6 @@ import org.eclipse.core.commands.operations.ObjectUndoContext;
import org.eclipse.core.commands.operations.OperationHistoryEvent;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.text.Assert;
@@ -362,19 +361,18 @@ public class DocumentUndoManager implements IDocumentUndoManager {
* @param offset the document offset
* @param text the text that was inserted
* @param preservedText the text being replaced
- * @param uiInfo an adapter that may provide additional UI info about the triggering action
+ * @param source the source which triggered the event
* @param eventType the type of event causing the change
* @param isCompound a flag indicating whether the change is a compound change
* @see IDocumentUndoListener
*/
- void fireDocumentUndo(int offset, String text, String preservedText, IAdaptable uiInfo, int eventType, boolean isCompound) {
+ void fireDocumentUndo(int offset, String text, String preservedText, Object source, int eventType, boolean isCompound) {
eventType= isCompound ? eventType | DocumentUndoEvent.COMPOUND : eventType;
- DocumentUndoEvent event= new DocumentUndoEvent(fDocument, offset, text, preservedText, eventType, uiInfo);
+ DocumentUndoEvent event= new DocumentUndoEvent(fDocument, offset, text, preservedText, eventType, source);
Object[] listeners= fDocumentUndoListeners.getListeners();
for (int i= 0; i < listeners.length; i++) {
((IDocumentUndoListener)listeners[i]).documentUndoNotification(event);
}
-
}
/**
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/UndoableCompoundTextChange.java b/org.eclipse.text/src/org/eclipse/text/undo/UndoableCompoundTextChange.java
index 65449e0f1..d7ed61d2a 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/UndoableCompoundTextChange.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/UndoableCompoundTextChange.java
@@ -51,7 +51,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
}
/*
- * @see org.eclipse.jface.text.UndoableTextChange#undo()
+ * @see org.eclipse.text.undo.UndoableTextChange#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
*/
public IStatus undo(IProgressMonitor monitor, IAdaptable uiInfo) {
@@ -60,8 +60,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
UndoableTextChange c;
c= (UndoableTextChange) fChanges.get(0);
- manager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo,
- DocumentUndoEvent.ABOUT_TO_UNDO, true);
+ manager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, true);
for (int i= size - 1; i >= 0; --i) {
c= (UndoableTextChange) fChanges.get(i);
@@ -74,7 +73,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
}
/*
- * @see org.eclipse.jface.text.UndoableTextChange#redo()
+ * @see org.eclipse.text.undo.UndoableTextChange#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
*/
public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) {
@@ -83,8 +82,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
UndoableTextChange c;
c= (UndoableTextChange) fChanges.get(size - 1);
- manager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo,
- DocumentUndoEvent.ABOUT_TO_REDO, true);
+ manager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, true);
for (int i= 0; i <= size - 1; ++i) {
c= (UndoableTextChange) fChanges.get(i);
@@ -98,7 +96,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
}
/*
- * @see UndoableTextChange#updateUndoableTextChange
+ * @see org.eclipse.text.undo.UndoableTextChange#updateTextChange()
*/
protected void updateTextChange() {
// first gather the data from the buffers
@@ -119,7 +117,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
}
/*
- * @see UndoableTextChange#createCurrent
+ * @see org.eclipse.text.undo.UndoableTextChange#createCurrent()
*/
protected UndoableTextChange createCurrent() {
@@ -131,7 +129,7 @@ class UndoableCompoundTextChange extends UndoableTextChange {
}
/*
- * @see org.eclipse.jface.text.UndoableTextChange#commit()
+ * @see org.eclipse.text.undo.UndoableTextChange#commit()
*/
protected void commit() {
// if there is pending data, update the text change
@@ -140,19 +138,15 @@ class UndoableCompoundTextChange extends UndoableTextChange {
manager.fCurrent= createCurrent();
}
- /**
- * Checks whether the text change is valid for undo or redo.
- *
- * @return true if the text change is valid
+ /*
+ * @see org.eclipse.text.undo.UndoableTextChange#isValid()
*/
protected boolean isValid() {
return fStart > -1 || fChanges.size() > 0;
}
- /**
- * Returns the undo modification stamp.
- *
- * @return the undo modification stamp
+ /*
+ * @see org.eclipse.text.undo.UndoableTextChange#getUndoModificationStamp()
*/
protected long getUndoModificationStamp() {
if (fStart > -1)
@@ -164,10 +158,8 @@ class UndoableCompoundTextChange extends UndoableTextChange {
return fUndoModificationStamp;
}
- /**
- * Returns the redo modification stamp.
- *
- * @return the redo modification stamp
+ /*
+ * @see org.eclipse.text.undo.UndoableTextChange#getRedoModificationStamp()
*/
protected long getRedoModificationStamp() {
if (fStart > -1)
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/UndoableTextChange.java b/org.eclipse.text/src/org/eclipse/text/undo/UndoableTextChange.java
index e5ddbf409..21574aa1c 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/UndoableTextChange.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/UndoableTextChange.java
@@ -12,6 +12,7 @@ package org.eclipse.text.undo;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.commands.operations.IOperationHistory;
+
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -204,8 +205,7 @@ class UndoableTextChange extends AbstractOperation {
}
/*
- * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
+ * @see org.eclipse.core.commands.operations.IUndoableOperation.IUndoableOperation#execute(IProgressMonitor, IAdaptable)
*/
public IStatus execute(IProgressMonitor monitor, IAdaptable uiInfo) {
// Text changes execute as they are typed, so executing one has no
@@ -233,8 +233,7 @@ class UndoableTextChange extends AbstractOperation {
protected void redoTextChange() {
try {
if (manager.fDocument instanceof IDocumentExtension4)
- ((IDocumentExtension4) manager.fDocument).replace(fStart, fEnd
- - fStart, fText, fRedoModificationStamp);
+ ((IDocumentExtension4) manager.fDocument).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp);
else
manager.fDocument.replace(fStart, fEnd - fStart, fText);
} catch (BadLocationException x) {
@@ -251,11 +250,9 @@ class UndoableTextChange extends AbstractOperation {
*/
public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) {
if (isValid()) {
- manager.fireDocumentUndo(fStart, fText, fPreservedText, uiInfo,
- DocumentUndoEvent.ABOUT_TO_REDO, false);
+ manager.fireDocumentUndo(fStart, fText, fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, false);
redoTextChange();
- manager.fireDocumentUndo(fStart, fText, fPreservedText, uiInfo,
- DocumentUndoEvent.REDONE, false);
+ manager.fireDocumentUndo(fStart, fText, fPreservedText, uiInfo, DocumentUndoEvent.REDONE, false);
return Status.OK_STATUS;
}
return IOperationHistory.OPERATION_INVALID_STATUS;
@@ -279,15 +276,15 @@ class UndoableTextChange extends AbstractOperation {
* @return a new, uncommitted text change or a compound text change
*/
protected UndoableTextChange createCurrent() {
- return manager.fFoldingIntoCompoundChange ? new UndoableCompoundTextChange(
- manager) : new UndoableTextChange(manager);
+ if (manager.fFoldingIntoCompoundChange)
+ return new UndoableCompoundTextChange(manager);
+ return new UndoableTextChange(manager);
}
/**
* Commits the current change into this one.
*/
protected void commit() {
-
if (fStart < 0) {
if (manager.fFoldingIntoCompoundChange) {
manager.fCurrent= createCurrent();
@@ -316,7 +313,7 @@ class UndoableTextChange extends AbstractOperation {
* created as a result of the commit.
*
* @return <code>true</code> if the change was committed and created
- * a new fCurrent, <code>false</code> if not
+ * a new <code>fCurrent</code>, <code>false</code> if not
*/
protected boolean attemptCommit() {
pretendCommit();

Back to the top