Search in sources :

Example 1 with Trigger

use of org.eclipse.jface.bindings.Trigger in project egit by eclipse.

the class UIUtils method getKeystrokeOfBestActiveBindingFor.

/**
 * Look up best active binding's keystroke for the given command
 *
 * @param commandId
 *            The identifier of the command for which the best active
 *            binding's keystroke should be retrieved; must not be null.
 * @return {@code KeyStroke} for the best active binding for the specified
 *         commandId or {@code null} if no binding is defined or if the
 *         binding service returns a {@code TriggerSequence} containing more
 *         than one {@code Trigger}.
 */
@Nullable
public static KeyStroke getKeystrokeOfBestActiveBindingFor(String commandId) {
    IBindingService bindingService = AdapterUtils.adapt(PlatformUI.getWorkbench(), IBindingService.class);
    if (bindingService == null) {
        return null;
    }
    TriggerSequence ts = bindingService.getBestActiveBindingFor(commandId);
    if (ts == null)
        return null;
    Trigger[] triggers = ts.getTriggers();
    if (triggers.length == 1 && triggers[0] instanceof KeyStroke)
        return (KeyStroke) triggers[0];
    else
        return null;
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) Trigger(org.eclipse.jface.bindings.Trigger) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) IBindingService(org.eclipse.ui.keys.IBindingService) Nullable(org.eclipse.jgit.annotations.Nullable)

Aggregations

Trigger (org.eclipse.jface.bindings.Trigger)1 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)1 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)1 Nullable (org.eclipse.jgit.annotations.Nullable)1 IBindingService (org.eclipse.ui.keys.IBindingService)1