|
13 | 13 | *******************************************************************************/ |
14 | 14 | package org.eclipse.ui.internal.findandreplace.overlay; |
15 | 15 |
|
16 | | -import java.lang.reflect.Method; |
17 | 16 | import java.util.ArrayList; |
18 | | -import java.util.HashMap; |
19 | 17 | import java.util.List; |
20 | | -import java.util.Map; |
21 | 18 | import java.util.concurrent.atomic.AtomicReference; |
22 | 19 |
|
23 | 20 | import org.osgi.framework.FrameworkUtil; |
|
47 | 44 | import org.eclipse.swt.widgets.ToolItem; |
48 | 45 | import org.eclipse.swt.widgets.Widget; |
49 | 46 |
|
50 | | -import org.eclipse.core.runtime.ILog; |
51 | | - |
52 | | -import org.eclipse.jface.action.IAction; |
53 | 47 | import org.eclipse.jface.bindings.keys.KeyStroke; |
54 | 48 | import org.eclipse.jface.dialogs.Dialog; |
55 | 49 | import org.eclipse.jface.dialogs.IDialogSettings; |
|
64 | 58 | import org.eclipse.jface.text.IFindReplaceTarget; |
65 | 59 | import org.eclipse.jface.text.ITextViewer; |
66 | 60 |
|
67 | | -import org.eclipse.ui.IActionBars; |
68 | 61 | import org.eclipse.ui.IWorkbenchPart; |
69 | 62 | import org.eclipse.ui.PlatformUI; |
70 | 63 | import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; |
|
74 | 67 | import org.eclipse.ui.internal.findandreplace.HistoryStore; |
75 | 68 | import org.eclipse.ui.internal.findandreplace.IFindReplaceLogic; |
76 | 69 | import org.eclipse.ui.internal.findandreplace.SearchOptions; |
77 | | -import org.eclipse.ui.part.MultiPageEditorSite; |
78 | 70 |
|
79 | | -import org.eclipse.ui.texteditor.AbstractTextEditor; |
80 | 71 | import org.eclipse.ui.texteditor.FindReplaceAction; |
81 | 72 | import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds; |
82 | | -import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
83 | 73 | import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
84 | 74 | import org.eclipse.ui.texteditor.StatusTextEditor; |
85 | 75 |
|
@@ -159,69 +149,18 @@ private static final class KeyboardShortcuts { |
159 | 149 | private ControlDecoration searchBarDecoration; |
160 | 150 | private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField; |
161 | 151 |
|
162 | | - private final FocusListener targetActionActivationHandling = new FocusListener() { |
163 | | - private DeactivateGlobalActionHandlers globalActionHandlerDeaction; |
| 152 | + private FindReplaceOverlayCommandSupport commandSupport; |
164 | 153 |
|
| 154 | + private final FocusListener targetActionActivationHandling = new FocusListener() { |
165 | 155 | @Override |
166 | 156 | public void focusGained(FocusEvent e) { |
167 | | - setTextEditorActionsActivated(false); |
| 157 | + commandSupport.overlayActivated(); |
168 | 158 | } |
169 | 159 |
|
170 | 160 | @Override |
171 | 161 | public void focusLost(FocusEvent e) { |
172 | | - setTextEditorActionsActivated(true); |
173 | | - } |
174 | | - |
175 | | - /* |
176 | | - * Adapted from |
177 | | - * org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated( |
178 | | - * boolean) |
179 | | - */ |
180 | | - private void setTextEditorActionsActivated(boolean state) { |
181 | | - if (!(targetPart instanceof AbstractTextEditor) || targetPart.getSite().getWorkbenchWindow().isClosing()) { |
182 | | - return; |
183 | | - } |
184 | | - if (targetPart.getSite() instanceof MultiPageEditorSite multiEditorSite) { |
185 | | - if (!state && globalActionHandlerDeaction == null) { |
186 | | - globalActionHandlerDeaction = new DeactivateGlobalActionHandlers(multiEditorSite.getActionBars()); |
187 | | - } else if (state && globalActionHandlerDeaction != null) { |
188 | | - globalActionHandlerDeaction.reactivate(); |
189 | | - globalActionHandlerDeaction = null; |
190 | | - } |
191 | | - } |
192 | | - try { |
193 | | - Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$ |
194 | | - method.setAccessible(true); |
195 | | - method.invoke(targetPart, Boolean.valueOf(state)); |
196 | | - } catch (IllegalArgumentException | ReflectiveOperationException ex) { |
197 | | - ILog.of(FindReplaceOverlay.class).error("cannot (de-)activate actions for text editor", ex); //$NON-NLS-1$ |
198 | | - } |
| 162 | + commandSupport.overlayDeactivated(); |
199 | 163 | } |
200 | | - |
201 | | - static final class DeactivateGlobalActionHandlers { |
202 | | - private final static List<String> ACTIONS = List.of(ITextEditorActionConstants.CUT, |
203 | | - ITextEditorActionConstants.COPY, ITextEditorActionConstants.PASTE, |
204 | | - ITextEditorActionConstants.DELETE, ITextEditorActionConstants.SELECT_ALL, |
205 | | - ITextEditorActionConstants.FIND); |
206 | | - |
207 | | - private final Map<String, IAction> deactivatedActions = new HashMap<>(); |
208 | | - private final IActionBars actionBars; |
209 | | - |
210 | | - public DeactivateGlobalActionHandlers(IActionBars actionBars) { |
211 | | - this.actionBars = actionBars; |
212 | | - for (String actionID : ACTIONS) { |
213 | | - deactivatedActions.putIfAbsent(actionID, actionBars.getGlobalActionHandler(actionID)); |
214 | | - actionBars.setGlobalActionHandler(actionID, null); |
215 | | - } |
216 | | - } |
217 | | - |
218 | | - public void reactivate() { |
219 | | - for (String actionID : deactivatedActions.keySet()) { |
220 | | - actionBars.setGlobalActionHandler(actionID, deactivatedActions.get(actionID)); |
221 | | - } |
222 | | - } |
223 | | - } |
224 | | - |
225 | 164 | }; |
226 | 165 |
|
227 | 166 | private final CustomFocusOrder customFocusOrder = new CustomFocusOrder(); |
@@ -301,6 +240,7 @@ void dispose() { |
301 | 240 |
|
302 | 241 | public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) { |
303 | 242 | targetPart = part; |
| 243 | + commandSupport = new FindReplaceOverlayCommandSupport(targetPart); |
304 | 244 | targetControl = getTargetControl(parent, part); |
305 | 245 | findReplaceLogic = createFindReplaceLogic(target); |
306 | 246 | createContainerAndSearchControls(targetControl); |
|
0 commit comments