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,19 +124,15 @@ 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 );
133
134
}
134
135
135
- /**
136
- *
137
- */
138
136
private void generateCommand () {
139
137
if (getModel ().getCommand () != null && getModel ().getWbCommand () == null ) {
140
138
String cmdId = getModel ().getCommand ().getElementId ();
@@ -153,10 +151,8 @@ private void generateCommand() {
153
151
WorkbenchSWTActivator .trace (Policy .DEBUG_MENUS_FLAG , "command: " + parmCmd , null ); //$NON-NLS-1$
154
152
}
155
153
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$
154
+ logger .error ("Unable to generate the parameterized " + "command with the id \" " + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
155
+ + parameters + " parameter(s). Model details: " + getModel ());//$NON-NLS-1$
160
156
return ;
161
157
}
162
158
@@ -174,6 +170,8 @@ private void generateCommand() {
174
170
} else if (radioState != null ) {
175
171
radioState .addListener (stateListener );
176
172
}
173
+
174
+ parmCmd .getCommand ().addCommandListener (event -> update ());
177
175
}
178
176
}
179
177
@@ -268,8 +266,7 @@ protected void updateMenuItem() {
268
266
if (mnemonics != null && !mnemonics .isEmpty ()) {
269
267
int idx = text .indexOf (mnemonics );
270
268
if (idx != -1 ) {
271
- text = text .substring (0 , idx ) + '&'
272
- + text .substring (idx );
269
+ text = text .substring (0 , idx ) + '&' + text .substring (idx );
273
270
}
274
271
}
275
272
}
@@ -311,6 +308,7 @@ protected void updateToolItem() {
311
308
item .setToolTipText (tooltip );
312
309
item .setSelection (getModel ().isSelected ());
313
310
item .setEnabled (getModel ().isEnabled ());
311
+
314
312
}
315
313
316
314
private String getToolTipText (boolean attachKeybinding ) {
@@ -321,6 +319,8 @@ private String getToolTipText(boolean attachKeybinding) {
321
319
parmCmd = getModel ().getWbCommand ();
322
320
}
323
321
322
+ text = legacyActionLabelSupport (text , parmCmd );
323
+
324
324
if (parmCmd != null && text == null ) {
325
325
try {
326
326
text = parmCmd .getName ();
@@ -336,6 +336,14 @@ private String getToolTipText(boolean attachKeybinding) {
336
336
return text ;
337
337
}
338
338
339
+ private String legacyActionLabelSupport (String text , ParameterizedCommand command ) {
340
+
341
+ return java .util .Optional .of (command ).map (ParameterizedCommand ::getCommand ).map (Command ::getHandler )
342
+ .filter (INamedHandler .class ::isInstance ).map (INamedHandler .class ::cast )
343
+ .map (INamedHandler ::getHandlerName ).orElse (text );
344
+
345
+ }
346
+
339
347
@ Override
340
348
protected void handleWidgetDispose (Event event ) {
341
349
if (event .widget == widget ) {
@@ -394,7 +402,7 @@ public void dispose() {
394
402
@ Override
395
403
@ SuppressWarnings ("restriction" )
396
404
protected void handleHelpRequest () {
397
- if (helpService == null )
405
+ if (helpService == null )
398
406
return ;
399
407
String helpContextId = getModel ().getPersistedState ().get (EHelpService .HELP_CONTEXT_ID );
400
408
if (helpContextId != null ) {
0 commit comments