}
return;
}
if (widget instanceof MenuItem) {
MenuItem mi = (MenuItem) widget;
if (textChanged) {
int accelerator = 0;
String acceleratorText = null;
IAction updatedAction = getAction();
String text = null;
accelerator = updatedAction.getAccelerator();
ExternalActionManager.ICallback callback = ExternalActionManager
.getInstance().getCallback();
// Block accelerators that are already in use.
if ((accelerator != 0) && (callback != null)
&& (callback.isAcceleratorInUse(accelerator))) {
accelerator = 0;
}
/*
* Process accelerators on GTK in a special way to avoid Bug
* 42009. We will override the native input method by
* allowing these reserved accelerators to be placed on the
* menu. We will only do this for "Ctrl+Shift+[0-9A-FU]".
*/
final String commandId = updatedAction
.getActionDefinitionId();
if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback)
&& (commandId != null)) {
final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
final IKeyLookup lookup = KeyLookupFactory.getDefault();
final TriggerSequence[] triggerSequences = bindingManagerCallback
.getActiveBindingsFor(commandId);
for (int i = 0; i < triggerSequences.length; i++) {
final TriggerSequence triggerSequence = triggerSequences[i];
final Trigger[] triggers = triggerSequence
.getTriggers();
if (triggers.length == 1) {
final Trigger trigger = triggers[0];
if (trigger instanceof KeyStroke) {
final KeyStroke currentKeyStroke = (KeyStroke) trigger;
final int currentNaturalKey = currentKeyStroke
.getNaturalKey();
if ((currentKeyStroke.getModifierKeys() == (lookup
.getCtrl() | lookup.getShift()))
&& ((currentNaturalKey >= '0' && currentNaturalKey <= '9')
|| (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) {
accelerator = currentKeyStroke
.getModifierKeys()
| currentNaturalKey;
acceleratorText = triggerSequence
.format();
break;
}
}
}
}
}
if (accelerator == 0) {
if ((callback != null) && (commandId != null)) {
acceleratorText = callback
.getAcceleratorText(commandId);
}
}
IContributionManagerOverrides overrides = null;
if (getParent() != null) {
overrides = getParent().getOverrides();
}
if (overrides != null) {
text = getParent().getOverrides().getText(this);
}
mi.setAccelerator(accelerator);
if (text == null) {
text = updatedAction.getText();
}
if (text != null && acceleratorText == null) {
// use extracted accelerator text in case accelerator
// cannot be fully represented in one int (e.g.
// multi-stroke keys)
acceleratorText = LegacyActionTools
.extractAcceleratorText(text);
if (acceleratorText == null && accelerator != 0) {
acceleratorText = Action
.convertAccelerator(accelerator);
}
}
if (text == null) {
text = ""; //$NON-NLS-1$
} else {
text = Action.removeAcceleratorText(text);
}
if (acceleratorText == null) {
mi.setText(text);
} else {
mi.setText(text + '\t' + acceleratorText);
}
}
if (imageChanged) {
updateImages(false);
}
if (enableStateChanged) {
boolean shouldBeEnabled = action.isEnabled()
&& isEnabledAllowed();
if (mi.getEnabled() != shouldBeEnabled) {
mi.setEnabled(shouldBeEnabled);
}
}
if (checkChanged) {
boolean bv = action.isChecked();
if (mi.getSelection() != bv) {
mi.setSelection(bv);
}
}
return;
}