diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index 235b584a566..4c16a831bcd 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -15,7 +15,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import org.osgi.framework.FrameworkUtil; @@ -46,6 +48,7 @@ import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; @@ -60,6 +63,7 @@ import org.eclipse.jface.text.IFindReplaceTarget; import org.eclipse.jface.text.ITextViewer; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; @@ -70,10 +74,12 @@ import org.eclipse.ui.internal.findandreplace.SearchOptions; import org.eclipse.ui.internal.findandreplace.status.IFindReplaceStatus; import org.eclipse.ui.internal.texteditor.TextEditorPlugin; +import org.eclipse.ui.part.MultiPageEditorSite; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.FindReplaceAction; import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.StatusTextEditor; @@ -148,6 +154,8 @@ private final class KeyboardShortcuts { private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField; private FocusListener targetActionActivationHandling = new FocusListener() { + private DeactivateGlobalActionHandlers globalActionHandlerDeaction; + @Override public void focusGained(FocusEvent e) { setTextEditorActionsActivated(false); @@ -167,15 +175,48 @@ private void setTextEditorActionsActivated(boolean state) { if (!(targetPart instanceof AbstractTextEditor)) { return; } + if (targetPart.getSite() instanceof MultiPageEditorSite multiEditorSite) { + if (!state && globalActionHandlerDeaction == null) { + globalActionHandlerDeaction = new DeactivateGlobalActionHandlers(multiEditorSite.getActionBars()); + } else if (state && globalActionHandlerDeaction != null) { + globalActionHandlerDeaction.reactivate(); + globalActionHandlerDeaction = null; + } + } try { Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$ method.setAccessible(true); method.invoke(targetPart, Boolean.valueOf(state)); - } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) { + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException + | NoSuchMethodException ex) { TextEditorPlugin.getDefault().getLog() .log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$ } } + + static final class DeactivateGlobalActionHandlers { + private final static String[] ACTIONS = { ITextEditorActionConstants.CUT, ITextEditorActionConstants.COPY, + ITextEditorActionConstants.PASTE, ITextEditorActionConstants.DELETE, + ITextEditorActionConstants.SELECT_ALL, ITextEditorActionConstants.FIND }; + + private final Map deactivatedActions = new HashMap<>(); + private final IActionBars actionBars; + + public DeactivateGlobalActionHandlers(IActionBars actionBars) { + this.actionBars = actionBars; + for (String actionID : ACTIONS) { + deactivatedActions.putIfAbsent(actionID, actionBars.getGlobalActionHandler(actionID)); + actionBars.setGlobalActionHandler(actionID, null); + } + } + + public void reactivate() { + for (String actionID : deactivatedActions.keySet()) { + actionBars.setGlobalActionHandler(actionID, deactivatedActions.get(actionID)); + } + } + } + }; public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) {