Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-04-19 18:51:22 +0000
committerMichael Valenta2007-04-19 18:51:22 +0000
commitb1c635106dafe79c80ee913d72e020307029c362 (patch)
tree2f1b1a2485475201dd5277cf55e368722002685a /bundles/org.eclipse.compare
parent7c073e80356b2a6870937957effd5283920da447 (diff)
downloadeclipse.platform.team-b1c635106dafe79c80ee913d72e020307029c362.tar.gz
eclipse.platform.team-b1c635106dafe79c80ee913d72e020307029c362.tar.xz
eclipse.platform.team-b1c635106dafe79c80ee913d72e020307029c362.zip
Bug 182287 compare editors open separate Find/Replace dialogs and don't follow focus
Diffstat (limited to 'bundles/org.eclipse.compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java10
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java86
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java15
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java100
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java42
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java10
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java86
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java15
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java100
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java42
10 files changed, 408 insertions, 98 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index f6d54826d..78e4a876e 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -25,6 +25,7 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.*;
@@ -290,6 +291,15 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
fCompareAsText = new CompareAsText();
return fCompareAsText;
}
+ if (adapter == IFindReplaceTarget.class) {
+ if (fContentInputPane != null) {
+ Viewer v = fContentInputPane.getViewer();
+ if (v != null) {
+ return Utilities.getAdapter(v, IFindReplaceTarget.class);
+ }
+ }
+ }
+
return null;
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index c9a3b9a26..e7eb9507f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -285,6 +285,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private ShowWhitespaceAction showWhitespaceAction;
private InternalOutlineViewerCreator fOutlineViewerCreator;
private TextEditorPropertyAction toggleLineNumbersAction;
+ private IFindReplaceTarget fFindReplaceTarget;
private final class InternalOutlineViewerCreator extends OutlineViewerCreator implements ISelectionChangedListener {
public Viewer findStructureViewer(Viewer oldViewer,
@@ -1369,6 +1370,35 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
}
+
+ private class FindReplaceTarget implements IFindReplaceTarget {
+
+ public boolean canPerformFind() {
+ return fFocusPart != null;
+ }
+
+ public int findAndSelect(int widgetOffset, String findString,
+ boolean searchForward, boolean caseSensitive, boolean wholeWord) {
+ return fFocusPart.getFindReplaceTarget().findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord);
+ }
+
+ public Point getSelection() {
+ return fFocusPart.getFindReplaceTarget().getSelection();
+ }
+
+ public String getSelectionText() {
+ return fFocusPart.getFindReplaceTarget().getSelectionText();
+ }
+
+ public boolean isEditable() {
+ return fFocusPart.getFindReplaceTarget().isEditable();
+ }
+
+ public void replaceSelection(String text) {
+ fFocusPart.getFindReplaceTarget().replaceSelection(text);
+ }
+
+ }
//---- MergeTextViewer
@@ -2339,28 +2369,46 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
if (fBackground != null) // not default
te.setBackground(getColor(parent.getDisplay(), fBackground));
+ // Add the find action to the popup menu of the viewer
+ contributeFindAction(part);
+
configureTextViewer(part);
return part;
}
+
+ private void contributeFindAction(MergeSourceViewer viewer) {
+ IAction action;
+ IWorkbenchPart wp = getCompareConfiguration().getContainer().getWorkbenchPart();
+ if (wp != null)
+ action = new FindReplaceAction(getResourceBundle(), "Editor.FindReplace.", wp); //$NON-NLS-1$
+ else
+ action = new FindReplaceAction(getResourceBundle(), "Editor.FindReplace.", viewer.getControl().getShell(), getFindReplaceTarget()); //$NON-NLS-1$
+ action.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
+ viewer.addAction(MergeSourceViewer.FIND_ID, action);
+ }
- private void connectGlobalActions(MergeSourceViewer part) {
- IActionBars actionBars= getCompareConfiguration().getContainer().getActionBars();
- if (actionBars != null) {
- for (int i= 0; i < GLOBAL_ACTIONS.length; i++) {
- IAction action= null;
- if (part != null) {
- action= part.getAction(TEXT_ACTIONS[i]);
- if (action == null && TEXT_ACTIONS[i].equals(MergeSourceViewer.SAVE_ID)) {
- if (part == fLeft)
- action= fLeftSaveAction;
- else
- action= fRightSaveAction;
+ private void connectGlobalActions(final MergeSourceViewer part) {
+ if (fHandlerService != null) {
+ if (part != null)
+ part.updateActions();
+ fHandlerService.updatePaneActionHandlers(new Runnable() {
+ public void run() {
+ for (int i= 0; i < GLOBAL_ACTIONS.length; i++) {
+ IAction action= null;
+ if (part != null) {
+ action= part.getAction(TEXT_ACTIONS[i]);
+ if (action == null && TEXT_ACTIONS[i].equals(MergeSourceViewer.SAVE_ID)) {
+ if (part == fLeft)
+ action= fLeftSaveAction;
+ else
+ action= fRightSaveAction;
+ }
+ }
+ fHandlerService.setGlobalActionHandler(GLOBAL_ACTIONS[i], action);
}
}
- actionBars.setGlobalActionHandler(GLOBAL_ACTIONS[i], action);
- }
- actionBars.updateActionBars();
+ });
}
}
@@ -5316,6 +5364,8 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
return fOutlineViewerCreator;
}
+ if (adapter == IFindReplaceTarget.class)
+ return getFindReplaceTarget();
return null;
}
@@ -5411,4 +5461,10 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
return 0;
}
+
+ private IFindReplaceTarget getFindReplaceTarget() {
+ if (fFindReplaceTarget == null)
+ fFindReplaceTarget= new FindReplaceTarget();
+ return fFindReplaceTarget;
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
index b72fa2cc6..9919ff615 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
@@ -22,6 +22,7 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -34,6 +35,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.part.*;
import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -169,16 +171,15 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
- if (key == OutlineViewerCreator.class) {
+ if (key == IShowInSource.class
+ || key == OutlineViewerCreator.class
+ || key == IFindReplaceTarget.class) {
Object input = getEditorInput();
if (input != null) {
- return Utilities.getAdapter(input, OutlineViewerCreator.class);
+ return Utilities.getAdapter(input, key);
}
}
- if (key.equals(IShowInSource.class)) {
- return getEditorInput().getAdapter(key);
- }
return super.getAdapter(key);
}
@@ -360,7 +361,9 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
parent.setData(this);
fPageBook = new PageBook(parent, SWT.NONE);
createCompareControl();
- getSite().getKeyBindingService().setScopes(new String[] { "org.eclipse.compare.compareEditorScope" }); //$NON-NLS-1$
+ IContextService service = (IContextService)getSite().getService(IContextService.class);
+ if (service != null)
+ service.activateContext("org.eclipse.compare.compareEditorScope"); //$NON-NLS-1$
}
private void createCompareControl() {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
index e219d18d2..809e79d21 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
@@ -18,8 +18,7 @@ import org.eclipse.core.expressions.Expression;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.ActiveShellExpression;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.*;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.services.IServiceLocator;
@@ -27,53 +26,128 @@ import org.eclipse.ui.services.IServiceLocator;
public class CompareHandlerService {
private final List fActivations = new ArrayList();
- private IHandlerService fHandlerService;
private final Expression fExpression;
+ private ICompareContainer fContainer;
+ private boolean fDisposed;
+ private List fPaneActivations = new ArrayList();
+ private IHandlerService fHandlerService;
public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
IServiceLocator serviceLocator = container.getServiceLocator();
if (serviceLocator != null) {
IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
if (service != null)
- return new CompareHandlerService(service, null);
+ return new CompareHandlerService(container, null);
}
if (container.getWorkbenchPart() == null && shell != null) {
// We're in a dialog so we can use an active shell expression
IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
if (service != null) {
Expression e = new ActiveShellExpression(shell);
- return new CompareHandlerService(service, e);
+ return new CompareHandlerService(container, e);
}
}
return new CompareHandlerService(null, null);
}
- private CompareHandlerService(IHandlerService handlerService,
+ private CompareHandlerService(ICompareContainer container,
Expression expression) {
- fHandlerService = handlerService;
+ fContainer = container;
fExpression = expression;
+ initialize();
}
public void registerAction(IAction action, String commandId) {
- if (fHandlerService == null)
+ IHandlerService handlerService = getHandlerService();
+ if (handlerService == null)
return;
action.setActionDefinitionId(commandId);
IHandlerActivation activation;
if (fExpression == null) {
- activation = fHandlerService.activateHandler(commandId, new ActionHandler(action));
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action));
} else {
- activation = fHandlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
}
if (activation != null) {
fActivations .add(activation);
}
}
+ private IHandlerService getHandlerService() {
+ if (fDisposed)
+ return null;
+ return fHandlerService;
+ }
+
+ private void initialize() {
+ if (fHandlerService == null) {
+ IServiceLocator serviceLocator = fContainer.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null)
+ fHandlerService = service;
+ }
+ if (fHandlerService == null && fContainer.getWorkbenchPart() == null && fExpression != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+ if (service != null) {
+ fHandlerService = service;
+ }
+ }
+ }
+ }
+
+ public void setGlobalActionHandler(String actionId, IAction actionHandler) {
+ IActionBars bars = getActionBars();
+ if (bars != null) {
+ bars.setGlobalActionHandler(actionId, actionHandler);
+ return;
+ } else if (fExpression != null && actionHandler != null && actionHandler.getActionDefinitionId() != null) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ IHandlerActivation activation = service.activateHandler(actionHandler.getActionDefinitionId(), new ActionHandler(actionHandler), fExpression);
+ fPaneActivations.add(activation);
+ return;
+ }
+ }
+ // Remove the action definition id since we won't get key bindings
+ if (actionHandler != null)
+ actionHandler.setActionDefinitionId(null);
+ }
+
+ private void updateActionBars() {
+ IActionBars bars = getActionBars();
+ if (bars != null)
+ bars.updateActionBars();
+ }
+
+ private void clearPaneActionHandlers() {
+ if (!fPaneActivations.isEmpty()) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ service.deactivateHandlers(fPaneActivations);
+ fPaneActivations.clear();
+ }
+ }
+ }
+
+ private IActionBars getActionBars() {
+ return fContainer.getActionBars();
+ }
+
public void dispose() {
- if (fHandlerService == null)
+ clearPaneActionHandlers();
+ IHandlerService service = getHandlerService();
+ if (service == null)
return;
- fHandlerService.deactivateHandlers(fActivations);
+ service.deactivateHandlers(fActivations);
fActivations.clear();
- fHandlerService = null;
+ fDisposed = true;
+ }
+
+ public void updatePaneActionHandlers(Runnable runnable) {
+ clearPaneActionHandlers();
+ runnable.run();
+ updateActionBars();
}
}
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 dbb6a61cb..c3792f230 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
@@ -29,7 +29,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.texteditor.*;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.ui.texteditor.FindReplaceAction;
/**
* Extends the JFace SourceViewer with some convenience methods.
*/
@@ -357,8 +358,8 @@ public class MergeSourceViewer extends SourceViewer
addSelectionChangedListener(this);
Utilities.initAction(action, fResourceBundle, "action." + actionId + "."); //$NON-NLS-1$ //$NON-NLS-2$
- fActions.put(actionId, action);
}
+ addAction(actionId, action);
}
if (action instanceof MergeViewerAction) {
@@ -384,29 +385,30 @@ public class MergeSourceViewer extends SourceViewer
return new TextOperationAction(DELETE, "org.eclipse.ui.edit.delete", true, false, false); //$NON-NLS-1$
if (SELECT_ALL_ID.equals(actionId))
return new TextOperationAction(SELECT_ALL, "org.eclipse.ui.edit.selectAll", false, false, false); //$NON-NLS-1$
- if (FIND_ID.equals(actionId)) {
- FindReplaceAction findReplaceAction = new FindReplaceAction(fResourceBundle, "Editor.FindReplace.", getControl().getShell(), this.getFindReplaceTarget()); //$NON-NLS-1$
- findReplaceAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
- return findReplaceAction;
- }
return null;
}
public void selectionChanged(SelectionChangedEvent event) {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- if (action.isSelectionDependent())
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ if (action.isSelectionDependent())
+ action.update();
+ }
}
}
public void textChanged(TextEvent event) {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- if (action.isContentDependent())
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ if (action.isContentDependent())
+ action.update();
+ }
}
}
@@ -470,8 +472,14 @@ public class MergeSourceViewer extends SourceViewer
public void updateActions() {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ action.update();
+ } if (next instanceof FindReplaceAction) {
+ FindReplaceAction action = (FindReplaceAction) next;
+ action.update();
+ }
}
}
@@ -548,4 +556,8 @@ public class MergeSourceViewer extends SourceViewer
public void addTextAction(TextEditorPropertyAction textEditorPropertyAction) {
textActions.add(textEditorPropertyAction);
}
+
+ public void addAction(String id, IAction action) {
+ fActions.put(id, action);
+ }
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index f6d54826d..78e4a876e 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -25,6 +25,7 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.*;
@@ -290,6 +291,15 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
fCompareAsText = new CompareAsText();
return fCompareAsText;
}
+ if (adapter == IFindReplaceTarget.class) {
+ if (fContentInputPane != null) {
+ Viewer v = fContentInputPane.getViewer();
+ if (v != null) {
+ return Utilities.getAdapter(v, IFindReplaceTarget.class);
+ }
+ }
+ }
+
return null;
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index c9a3b9a26..e7eb9507f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -285,6 +285,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private ShowWhitespaceAction showWhitespaceAction;
private InternalOutlineViewerCreator fOutlineViewerCreator;
private TextEditorPropertyAction toggleLineNumbersAction;
+ private IFindReplaceTarget fFindReplaceTarget;
private final class InternalOutlineViewerCreator extends OutlineViewerCreator implements ISelectionChangedListener {
public Viewer findStructureViewer(Viewer oldViewer,
@@ -1369,6 +1370,35 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
}
+
+ private class FindReplaceTarget implements IFindReplaceTarget {
+
+ public boolean canPerformFind() {
+ return fFocusPart != null;
+ }
+
+ public int findAndSelect(int widgetOffset, String findString,
+ boolean searchForward, boolean caseSensitive, boolean wholeWord) {
+ return fFocusPart.getFindReplaceTarget().findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord);
+ }
+
+ public Point getSelection() {
+ return fFocusPart.getFindReplaceTarget().getSelection();
+ }
+
+ public String getSelectionText() {
+ return fFocusPart.getFindReplaceTarget().getSelectionText();
+ }
+
+ public boolean isEditable() {
+ return fFocusPart.getFindReplaceTarget().isEditable();
+ }
+
+ public void replaceSelection(String text) {
+ fFocusPart.getFindReplaceTarget().replaceSelection(text);
+ }
+
+ }
//---- MergeTextViewer
@@ -2339,28 +2369,46 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
if (fBackground != null) // not default
te.setBackground(getColor(parent.getDisplay(), fBackground));
+ // Add the find action to the popup menu of the viewer
+ contributeFindAction(part);
+
configureTextViewer(part);
return part;
}
+
+ private void contributeFindAction(MergeSourceViewer viewer) {
+ IAction action;
+ IWorkbenchPart wp = getCompareConfiguration().getContainer().getWorkbenchPart();
+ if (wp != null)
+ action = new FindReplaceAction(getResourceBundle(), "Editor.FindReplace.", wp); //$NON-NLS-1$
+ else
+ action = new FindReplaceAction(getResourceBundle(), "Editor.FindReplace.", viewer.getControl().getShell(), getFindReplaceTarget()); //$NON-NLS-1$
+ action.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
+ viewer.addAction(MergeSourceViewer.FIND_ID, action);
+ }
- private void connectGlobalActions(MergeSourceViewer part) {
- IActionBars actionBars= getCompareConfiguration().getContainer().getActionBars();
- if (actionBars != null) {
- for (int i= 0; i < GLOBAL_ACTIONS.length; i++) {
- IAction action= null;
- if (part != null) {
- action= part.getAction(TEXT_ACTIONS[i]);
- if (action == null && TEXT_ACTIONS[i].equals(MergeSourceViewer.SAVE_ID)) {
- if (part == fLeft)
- action= fLeftSaveAction;
- else
- action= fRightSaveAction;
+ private void connectGlobalActions(final MergeSourceViewer part) {
+ if (fHandlerService != null) {
+ if (part != null)
+ part.updateActions();
+ fHandlerService.updatePaneActionHandlers(new Runnable() {
+ public void run() {
+ for (int i= 0; i < GLOBAL_ACTIONS.length; i++) {
+ IAction action= null;
+ if (part != null) {
+ action= part.getAction(TEXT_ACTIONS[i]);
+ if (action == null && TEXT_ACTIONS[i].equals(MergeSourceViewer.SAVE_ID)) {
+ if (part == fLeft)
+ action= fLeftSaveAction;
+ else
+ action= fRightSaveAction;
+ }
+ }
+ fHandlerService.setGlobalActionHandler(GLOBAL_ACTIONS[i], action);
}
}
- actionBars.setGlobalActionHandler(GLOBAL_ACTIONS[i], action);
- }
- actionBars.updateActionBars();
+ });
}
}
@@ -5316,6 +5364,8 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
return fOutlineViewerCreator;
}
+ if (adapter == IFindReplaceTarget.class)
+ return getFindReplaceTarget();
return null;
}
@@ -5411,4 +5461,10 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
return 0;
}
+
+ private IFindReplaceTarget getFindReplaceTarget() {
+ if (fFindReplaceTarget == null)
+ fFindReplaceTarget= new FindReplaceTarget();
+ return fFindReplaceTarget;
+ }
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
index b72fa2cc6..9919ff615 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
@@ -22,6 +22,7 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -34,6 +35,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.part.*;
import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -169,16 +171,15 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
- if (key == OutlineViewerCreator.class) {
+ if (key == IShowInSource.class
+ || key == OutlineViewerCreator.class
+ || key == IFindReplaceTarget.class) {
Object input = getEditorInput();
if (input != null) {
- return Utilities.getAdapter(input, OutlineViewerCreator.class);
+ return Utilities.getAdapter(input, key);
}
}
- if (key.equals(IShowInSource.class)) {
- return getEditorInput().getAdapter(key);
- }
return super.getAdapter(key);
}
@@ -360,7 +361,9 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
parent.setData(this);
fPageBook = new PageBook(parent, SWT.NONE);
createCompareControl();
- getSite().getKeyBindingService().setScopes(new String[] { "org.eclipse.compare.compareEditorScope" }); //$NON-NLS-1$
+ IContextService service = (IContextService)getSite().getService(IContextService.class);
+ if (service != null)
+ service.activateContext("org.eclipse.compare.compareEditorScope"); //$NON-NLS-1$
}
private void createCompareControl() {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
index e219d18d2..809e79d21 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
@@ -18,8 +18,7 @@ import org.eclipse.core.expressions.Expression;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.ActiveShellExpression;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.*;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.services.IServiceLocator;
@@ -27,53 +26,128 @@ import org.eclipse.ui.services.IServiceLocator;
public class CompareHandlerService {
private final List fActivations = new ArrayList();
- private IHandlerService fHandlerService;
private final Expression fExpression;
+ private ICompareContainer fContainer;
+ private boolean fDisposed;
+ private List fPaneActivations = new ArrayList();
+ private IHandlerService fHandlerService;
public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
IServiceLocator serviceLocator = container.getServiceLocator();
if (serviceLocator != null) {
IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
if (service != null)
- return new CompareHandlerService(service, null);
+ return new CompareHandlerService(container, null);
}
if (container.getWorkbenchPart() == null && shell != null) {
// We're in a dialog so we can use an active shell expression
IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
if (service != null) {
Expression e = new ActiveShellExpression(shell);
- return new CompareHandlerService(service, e);
+ return new CompareHandlerService(container, e);
}
}
return new CompareHandlerService(null, null);
}
- private CompareHandlerService(IHandlerService handlerService,
+ private CompareHandlerService(ICompareContainer container,
Expression expression) {
- fHandlerService = handlerService;
+ fContainer = container;
fExpression = expression;
+ initialize();
}
public void registerAction(IAction action, String commandId) {
- if (fHandlerService == null)
+ IHandlerService handlerService = getHandlerService();
+ if (handlerService == null)
return;
action.setActionDefinitionId(commandId);
IHandlerActivation activation;
if (fExpression == null) {
- activation = fHandlerService.activateHandler(commandId, new ActionHandler(action));
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action));
} else {
- activation = fHandlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
}
if (activation != null) {
fActivations .add(activation);
}
}
+ private IHandlerService getHandlerService() {
+ if (fDisposed)
+ return null;
+ return fHandlerService;
+ }
+
+ private void initialize() {
+ if (fHandlerService == null) {
+ IServiceLocator serviceLocator = fContainer.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null)
+ fHandlerService = service;
+ }
+ if (fHandlerService == null && fContainer.getWorkbenchPart() == null && fExpression != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+ if (service != null) {
+ fHandlerService = service;
+ }
+ }
+ }
+ }
+
+ public void setGlobalActionHandler(String actionId, IAction actionHandler) {
+ IActionBars bars = getActionBars();
+ if (bars != null) {
+ bars.setGlobalActionHandler(actionId, actionHandler);
+ return;
+ } else if (fExpression != null && actionHandler != null && actionHandler.getActionDefinitionId() != null) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ IHandlerActivation activation = service.activateHandler(actionHandler.getActionDefinitionId(), new ActionHandler(actionHandler), fExpression);
+ fPaneActivations.add(activation);
+ return;
+ }
+ }
+ // Remove the action definition id since we won't get key bindings
+ if (actionHandler != null)
+ actionHandler.setActionDefinitionId(null);
+ }
+
+ private void updateActionBars() {
+ IActionBars bars = getActionBars();
+ if (bars != null)
+ bars.updateActionBars();
+ }
+
+ private void clearPaneActionHandlers() {
+ if (!fPaneActivations.isEmpty()) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ service.deactivateHandlers(fPaneActivations);
+ fPaneActivations.clear();
+ }
+ }
+ }
+
+ private IActionBars getActionBars() {
+ return fContainer.getActionBars();
+ }
+
public void dispose() {
- if (fHandlerService == null)
+ clearPaneActionHandlers();
+ IHandlerService service = getHandlerService();
+ if (service == null)
return;
- fHandlerService.deactivateHandlers(fActivations);
+ service.deactivateHandlers(fActivations);
fActivations.clear();
- fHandlerService = null;
+ fDisposed = true;
+ }
+
+ public void updatePaneActionHandlers(Runnable runnable) {
+ clearPaneActionHandlers();
+ runnable.run();
+ updateActionBars();
}
}
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 dbb6a61cb..c3792f230 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
@@ -29,7 +29,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.texteditor.*;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.ui.texteditor.FindReplaceAction;
/**
* Extends the JFace SourceViewer with some convenience methods.
*/
@@ -357,8 +358,8 @@ public class MergeSourceViewer extends SourceViewer
addSelectionChangedListener(this);
Utilities.initAction(action, fResourceBundle, "action." + actionId + "."); //$NON-NLS-1$ //$NON-NLS-2$
- fActions.put(actionId, action);
}
+ addAction(actionId, action);
}
if (action instanceof MergeViewerAction) {
@@ -384,29 +385,30 @@ public class MergeSourceViewer extends SourceViewer
return new TextOperationAction(DELETE, "org.eclipse.ui.edit.delete", true, false, false); //$NON-NLS-1$
if (SELECT_ALL_ID.equals(actionId))
return new TextOperationAction(SELECT_ALL, "org.eclipse.ui.edit.selectAll", false, false, false); //$NON-NLS-1$
- if (FIND_ID.equals(actionId)) {
- FindReplaceAction findReplaceAction = new FindReplaceAction(fResourceBundle, "Editor.FindReplace.", getControl().getShell(), this.getFindReplaceTarget()); //$NON-NLS-1$
- findReplaceAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
- return findReplaceAction;
- }
return null;
}
public void selectionChanged(SelectionChangedEvent event) {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- if (action.isSelectionDependent())
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ if (action.isSelectionDependent())
+ action.update();
+ }
}
}
public void textChanged(TextEvent event) {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- if (action.isContentDependent())
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ if (action.isContentDependent())
+ action.update();
+ }
}
}
@@ -470,8 +472,14 @@ public class MergeSourceViewer extends SourceViewer
public void updateActions() {
Iterator e= fActions.values().iterator();
while (e.hasNext()) {
- MergeViewerAction action= (MergeViewerAction) e.next();
- action.update();
+ Object next = e.next();
+ if (next instanceof MergeViewerAction) {
+ MergeViewerAction action = (MergeViewerAction) next;
+ action.update();
+ } if (next instanceof FindReplaceAction) {
+ FindReplaceAction action = (FindReplaceAction) next;
+ action.update();
+ }
}
}
@@ -548,4 +556,8 @@ public class MergeSourceViewer extends SourceViewer
public void addTextAction(TextEditorPropertyAction textEditorPropertyAction) {
textActions.add(textEditorPropertyAction);
}
+
+ public void addAction(String id, IAction action) {
+ fActions.put(id, action);
+ }
}

Back to the top