24
24
import java .util .HashMap ;
25
25
import java .util .List ;
26
26
import java .util .Map ;
27
+ import org .eclipse .core .commands .Command ;
27
28
import org .eclipse .core .commands .ExecutionException ;
29
+ import org .eclipse .core .commands .INamedHandler ;
28
30
import org .eclipse .core .commands .IStateListener ;
29
31
import org .eclipse .core .commands .ParameterizedCommand ;
30
32
import org .eclipse .core .commands .State ;
@@ -122,11 +124,10 @@ public void setModel(MItem item) {
122
124
}
123
125
124
126
/**
125
- * This method seems to be necessary for calls via reflection when called
126
- * with MHandledItem parameter.
127
+ * This method seems to be necessary for calls via reflection when called with
128
+ * MHandledItem parameter.
127
129
*
128
- * @param item
129
- * The model item
130
+ * @param item The model item
130
131
*/
131
132
public void setModel (MHandledItem item ) {
132
133
setModel ((MItem ) item );
@@ -153,10 +154,8 @@ private void generateCommand() {
153
154
WorkbenchSWTActivator .trace (Policy .DEBUG_MENUS_FLAG , "command: " + parmCmd , null ); //$NON-NLS-1$
154
155
}
155
156
if (parmCmd == null ) {
156
- logger .error (
157
- "Unable to generate the parameterized " + "command with the id \" " + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
158
- + parameters
159
- + " parameter(s). Model details: " + getModel ());//$NON-NLS-1$
157
+ logger .error ("Unable to generate the parameterized " + "command with the id \" " + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
158
+ + parameters + " parameter(s). Model details: " + getModel ());//$NON-NLS-1$
160
159
return ;
161
160
}
162
161
@@ -174,6 +173,12 @@ private void generateCommand() {
174
173
} else if (radioState != null ) {
175
174
radioState .addListener (stateListener );
176
175
}
176
+
177
+ parmCmd .getCommand ().addCommandListener (event -> {
178
+ if (event .isHandledChanged ()) {
179
+ update ();
180
+ }
181
+ });
177
182
}
178
183
}
179
184
@@ -268,8 +273,7 @@ protected void updateMenuItem() {
268
273
if (mnemonics != null && !mnemonics .isEmpty ()) {
269
274
int idx = text .indexOf (mnemonics );
270
275
if (idx != -1 ) {
271
- text = text .substring (0 , idx ) + '&'
272
- + text .substring (idx );
276
+ text = text .substring (0 , idx ) + '&' + text .substring (idx );
273
277
}
274
278
}
275
279
}
@@ -311,6 +315,7 @@ protected void updateToolItem() {
311
315
item .setToolTipText (tooltip );
312
316
item .setSelection (getModel ().isSelected ());
313
317
item .setEnabled (getModel ().isEnabled ());
318
+
314
319
}
315
320
316
321
private String getToolTipText (boolean attachKeybinding ) {
@@ -321,6 +326,8 @@ private String getToolTipText(boolean attachKeybinding) {
321
326
parmCmd = getModel ().getWbCommand ();
322
327
}
323
328
329
+ text = legacyActionLabelSupport (text , parmCmd );
330
+
324
331
if (parmCmd != null && text == null ) {
325
332
try {
326
333
text = parmCmd .getName ();
@@ -336,6 +343,14 @@ private String getToolTipText(boolean attachKeybinding) {
336
343
return text ;
337
344
}
338
345
346
+ private String legacyActionLabelSupport (String text , ParameterizedCommand command ) {
347
+
348
+ return java .util .Optional .of (command ).map (ParameterizedCommand ::getCommand ).map (Command ::getHandler )
349
+ .filter (INamedHandler .class ::isInstance ).map (INamedHandler .class ::cast )
350
+ .map (INamedHandler ::getHandlerName ).orElse (text );
351
+
352
+ }
353
+
339
354
@ Override
340
355
protected void handleWidgetDispose (Event event ) {
341
356
if (event .widget == widget ) {
@@ -394,7 +409,7 @@ public void dispose() {
394
409
@ Override
395
410
@ SuppressWarnings ("restriction" )
396
411
protected void handleHelpRequest () {
397
- if (helpService == null )
412
+ if (helpService == null )
398
413
return ;
399
414
String helpContextId = getModel ().getPersistedState ().get (EHelpService .HELP_CONTEXT_ID );
400
415
if (helpContextId != null ) {
0 commit comments