Search in sources :

Example 16 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project erlide_eclipse by erlang.

the class KeyBindingHelper method matchesKeybinding.

// END pre-defined helpers
/**
 * @param event
 *            the key event to be checked
 * @param commandId
 *            the command to be checked
 * @return true if the given key event can trigger the passed command (and false
 *         otherwise).
 */
public static boolean matchesKeybinding(final KeyEvent event, final String commandId) {
    final IBindingService bindingSvc = PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    if (bindingSvc == null) {
        return false;
    }
    final TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId);
    for (final TriggerSequence seq : activeBindingsFor) {
        if (seq instanceof KeySequence) {
            final KeySequence keySequence = (KeySequence) seq;
            final KeyStroke[] keyStrokes = keySequence.getKeyStrokes();
            for (final KeyStroke keyStroke : keyStrokes) {
                if (keyStroke.getNaturalKey() == event.keyCode && (keyStroke.getModifierKeys() & event.stateMask) != 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) IBindingService(org.eclipse.ui.keys.IBindingService) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 17 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project erlide_eclipse by erlang.

the class KeyBindingHelper method getCommandKeyBinding.

/**
 * @param commandId
 *            the command we want to know about
 * @return the 'best' key sequence that will activate the given command
 */
public static KeySequence getCommandKeyBinding(final String commandId) {
    final IBindingService bindingSvc = PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    if (bindingSvc == null) {
        return null;
    }
    final TriggerSequence binding = bindingSvc.getBestActiveBindingFor(commandId);
    if (binding instanceof KeySequence) {
        return (KeySequence) binding;
    }
    return null;
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) IBindingService(org.eclipse.ui.keys.IBindingService) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Aggregations

TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)17 IBindingService (org.eclipse.ui.keys.IBindingService)13 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)7 Binding (org.eclipse.jface.bindings.Binding)4 Iterator (java.util.Iterator)3 Command (org.eclipse.core.commands.Command)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)3 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)3 ArrayList (java.util.ArrayList)2 ParseException (org.eclipse.jface.bindings.keys.ParseException)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 VerifyEvent (org.eclipse.swt.events.VerifyEvent)2 Point (org.eclipse.swt.graphics.Point)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 Nullable (org.jkiss.code.Nullable)2 Collection (java.util.Collection)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 Scheme (org.eclipse.jface.bindings.Scheme)1