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;
}
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;
}
Aggregations