Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-05-07 18:04:53 +0000
committerMichael Valenta2007-05-07 18:04:53 +0000
commit4d4859e8aa2214da10c7dd88299c26fda7f6792b (patch)
tree3f095719a253d008579455334338963c2729e1e6 /bundles/org.eclipse.compare
parent219662caa577affdf5a27e5375df3ae25737846f (diff)
downloadeclipse.platform.team-4d4859e8aa2214da10c7dd88299c26fda7f6792b.tar.gz
eclipse.platform.team-4d4859e8aa2214da10c7dd88299c26fda7f6792b.tar.xz
eclipse.platform.team-4d4859e8aa2214da10c7dd88299c26fda7f6792b.zip
Bug 182819 [Edit] Undo not enabled on the first Paste
Diffstat (limited to 'bundles/org.eclipse.compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java44
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java44
2 files changed, 86 insertions, 2 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index db73d3291..4c73b176f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -15,6 +15,7 @@ package org.eclipse.compare.internal;
import java.util.*;
import org.eclipse.compare.ICompareContainer;
+import org.eclipse.core.commands.operations.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.*;
@@ -28,6 +29,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.FindReplaceAction;
@@ -35,7 +37,7 @@ import org.eclipse.ui.texteditor.FindReplaceAction;
* Extends the JFace SourceViewer with some convenience methods.
*/
public class MergeSourceViewer extends SourceViewer
- implements ISelectionChangedListener, ITextListener, IMenuListener {
+ implements ISelectionChangedListener, ITextListener, IMenuListener, IOperationHistoryListener {
public static final String UNDO_ID= "undo"; //$NON-NLS-1$
public static final String REDO_ID= "redo"; //$NON-NLS-1$
@@ -116,6 +118,10 @@ public class MergeSourceViewer extends SourceViewer
if(fShowLineNumber){
updateLineNumberRuler();
}
+
+ IOperationHistory history = getHistory();
+ if (history != null)
+ history.addOperationHistoryListener(this);
}
public void rememberDocument(IDocument doc) {
@@ -401,6 +407,10 @@ public class MergeSourceViewer extends SourceViewer
}
public void textChanged(TextEvent event) {
+ updateContentDependantActions();
+ }
+
+ void updateContentDependantActions() {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
Object next = e.next();
@@ -463,6 +473,10 @@ public class MergeSourceViewer extends SourceViewer
removeSelectionChangedListener(this);
EditorsUI.getPreferenceStore().removePropertyChangeListener(fPreferenceChangeListener);
+ IOperationHistory history = getHistory();
+ if (history != null)
+ history.removeOperationHistoryListener(this);
+
super.handleDispose();
}
@@ -561,4 +575,32 @@ public class MergeSourceViewer extends SourceViewer
public void addAction(String id, IAction action) {
fActions.put(id, action);
}
+
+ private IOperationHistory getHistory() {
+ if (PlatformUI.getWorkbench() == null) {
+ return null;
+ }
+ return PlatformUI.getWorkbench().getOperationSupport()
+ .getOperationHistory();
+ }
+
+ public void historyNotification(OperationHistoryEvent event) {
+ // This method updates the enablement of all content operations
+ // when the undo history changes. It could be localized to UNDO and REDO.
+ IUndoContext context = getUndoContext();
+ if (context != null && event.getOperation().hasContext(context)) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ updateContentDependantActions();
+ }
+ });
+ }
+ }
+
+ private IUndoContext getUndoContext() {
+ IUndoManager undoManager = getUndoManager();
+ if (undoManager instanceof IUndoManagerExtension)
+ return ((IUndoManagerExtension)undoManager).getUndoContext();
+ return null;
+ }
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index db73d3291..4c73b176f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -15,6 +15,7 @@ package org.eclipse.compare.internal;
import java.util.*;
import org.eclipse.compare.ICompareContainer;
+import org.eclipse.core.commands.operations.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.*;
@@ -28,6 +29,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.FindReplaceAction;
@@ -35,7 +37,7 @@ import org.eclipse.ui.texteditor.FindReplaceAction;
* Extends the JFace SourceViewer with some convenience methods.
*/
public class MergeSourceViewer extends SourceViewer
- implements ISelectionChangedListener, ITextListener, IMenuListener {
+ implements ISelectionChangedListener, ITextListener, IMenuListener, IOperationHistoryListener {
public static final String UNDO_ID= "undo"; //$NON-NLS-1$
public static final String REDO_ID= "redo"; //$NON-NLS-1$
@@ -116,6 +118,10 @@ public class MergeSourceViewer extends SourceViewer
if(fShowLineNumber){
updateLineNumberRuler();
}
+
+ IOperationHistory history = getHistory();
+ if (history != null)
+ history.addOperationHistoryListener(this);
}
public void rememberDocument(IDocument doc) {
@@ -401,6 +407,10 @@ public class MergeSourceViewer extends SourceViewer
}
public void textChanged(TextEvent event) {
+ updateContentDependantActions();
+ }
+
+ void updateContentDependantActions() {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
Object next = e.next();
@@ -463,6 +473,10 @@ public class MergeSourceViewer extends SourceViewer
removeSelectionChangedListener(this);
EditorsUI.getPreferenceStore().removePropertyChangeListener(fPreferenceChangeListener);
+ IOperationHistory history = getHistory();
+ if (history != null)
+ history.removeOperationHistoryListener(this);
+
super.handleDispose();
}
@@ -561,4 +575,32 @@ public class MergeSourceViewer extends SourceViewer
public void addAction(String id, IAction action) {
fActions.put(id, action);
}
+
+ private IOperationHistory getHistory() {
+ if (PlatformUI.getWorkbench() == null) {
+ return null;
+ }
+ return PlatformUI.getWorkbench().getOperationSupport()
+ .getOperationHistory();
+ }
+
+ public void historyNotification(OperationHistoryEvent event) {
+ // This method updates the enablement of all content operations
+ // when the undo history changes. It could be localized to UNDO and REDO.
+ IUndoContext context = getUndoContext();
+ if (context != null && event.getOperation().hasContext(context)) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ updateContentDependantActions();
+ }
+ });
+ }
+ }
+
+ private IUndoContext getUndoContext() {
+ IUndoManager undoManager = getUndoManager();
+ if (undoManager instanceof IUndoManagerExtension)
+ return ((IUndoManagerExtension)undoManager).getUndoContext();
+ return null;
+ }
}

Back to the top