13
13
*******************************************************************************/
14
14
package org .eclipse .ui .internal .findandreplace .overlay ;
15
15
16
- import java .lang .reflect .InvocationTargetException ;
17
16
import java .lang .reflect .Method ;
17
+ import java .util .HashMap ;
18
18
import java .util .List ;
19
+ import java .util .Map ;
19
20
import java .util .concurrent .atomic .AtomicReference ;
20
21
21
22
import org .osgi .framework .FrameworkUtil ;
46
47
47
48
import org .eclipse .core .runtime .Status ;
48
49
50
+ import org .eclipse .jface .action .IAction ;
49
51
import org .eclipse .jface .bindings .keys .KeyStroke ;
50
52
import org .eclipse .jface .dialogs .Dialog ;
51
53
import org .eclipse .jface .dialogs .IDialogSettings ;
60
62
import org .eclipse .jface .text .IFindReplaceTarget ;
61
63
import org .eclipse .jface .text .ITextViewer ;
62
64
65
+ import org .eclipse .ui .IActionBars ;
63
66
import org .eclipse .ui .IWorkbenchPart ;
64
67
import org .eclipse .ui .PlatformUI ;
65
68
import org .eclipse .ui .fieldassist .ContentAssistCommandAdapter ;
70
73
import org .eclipse .ui .internal .findandreplace .SearchOptions ;
71
74
import org .eclipse .ui .internal .findandreplace .status .IFindReplaceStatus ;
72
75
import org .eclipse .ui .internal .texteditor .TextEditorPlugin ;
76
+ import org .eclipse .ui .part .MultiPageEditorSite ;
73
77
74
78
import org .eclipse .ui .texteditor .AbstractTextEditor ;
75
79
import org .eclipse .ui .texteditor .FindReplaceAction ;
76
80
import org .eclipse .ui .texteditor .IAbstractTextEditorHelpContextIds ;
81
+ import org .eclipse .ui .texteditor .ITextEditorActionConstants ;
77
82
import org .eclipse .ui .texteditor .ITextEditorActionDefinitionIds ;
78
83
import org .eclipse .ui .texteditor .StatusTextEditor ;
79
84
@@ -148,6 +153,8 @@ private final class KeyboardShortcuts {
148
153
private ContentAssistCommandAdapter contentAssistSearchField , contentAssistReplaceField ;
149
154
150
155
private FocusListener targetActionActivationHandling = new FocusListener () {
156
+ private DeactivateGlobalActionHandlers globalActionHandlerDeaction ;
157
+
151
158
@ Override
152
159
public void focusGained (FocusEvent e ) {
153
160
setTextEditorActionsActivated (false );
@@ -167,15 +174,48 @@ private void setTextEditorActionsActivated(boolean state) {
167
174
if (!(targetPart instanceof AbstractTextEditor )) {
168
175
return ;
169
176
}
177
+ if (targetPart .getSite () instanceof MultiPageEditorSite multiEditorSite ) {
178
+ if (!state && globalActionHandlerDeaction == null ) {
179
+ globalActionHandlerDeaction = new DeactivateGlobalActionHandlers (multiEditorSite .getActionBars ());
180
+ } else if (state && globalActionHandlerDeaction != null ) {
181
+ globalActionHandlerDeaction .reactivate ();
182
+ globalActionHandlerDeaction = null ;
183
+ }
184
+ }
170
185
try {
171
186
Method method = AbstractTextEditor .class .getDeclaredMethod ("setActionActivation" , boolean .class ); //$NON-NLS-1$
172
187
method .setAccessible (true );
173
188
method .invoke (targetPart , Boolean .valueOf (state ));
174
- } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex ) {
189
+ } catch (IllegalArgumentException | ReflectiveOperationException ex ) {
175
190
TextEditorPlugin .getDefault ().getLog ()
176
191
.log (Status .error ("cannot (de-)activate actions for text editor" , ex )); //$NON-NLS-1$
177
192
}
178
193
}
194
+
195
+ static final class DeactivateGlobalActionHandlers {
196
+ private final static List <String > ACTIONS = List .of (ITextEditorActionConstants .CUT ,
197
+ ITextEditorActionConstants .COPY , ITextEditorActionConstants .PASTE ,
198
+ ITextEditorActionConstants .DELETE , ITextEditorActionConstants .SELECT_ALL ,
199
+ ITextEditorActionConstants .FIND );
200
+
201
+ private final Map <String , IAction > deactivatedActions = new HashMap <>();
202
+ private final IActionBars actionBars ;
203
+
204
+ public DeactivateGlobalActionHandlers (IActionBars actionBars ) {
205
+ this .actionBars = actionBars ;
206
+ for (String actionID : ACTIONS ) {
207
+ deactivatedActions .putIfAbsent (actionID , actionBars .getGlobalActionHandler (actionID ));
208
+ actionBars .setGlobalActionHandler (actionID , null );
209
+ }
210
+ }
211
+
212
+ public void reactivate () {
213
+ for (String actionID : deactivatedActions .keySet ()) {
214
+ actionBars .setGlobalActionHandler (actionID , deactivatedActions .get (actionID ));
215
+ }
216
+ }
217
+ }
218
+
179
219
};
180
220
181
221
public FindReplaceOverlay (Shell parent , IWorkbenchPart part , IFindReplaceTarget target ) {
0 commit comments