Search in sources :

Example 11 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project KaiZen-OpenAPI-Editor by RepreZen.

the class QuickOutline method isInvocationEvent.

protected boolean isInvocationEvent(KeyEvent e) {
    int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
    KeySequence keySequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
    return keySequence.startsWith(triggerSequence, true);
}
Also used : KeySequence(org.eclipse.jface.bindings.keys.KeySequence) Point(org.eclipse.swt.graphics.Point)

Example 12 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project whole by wholeplatform.

the class ActionRegistry method registerKeyActions.

public void registerKeyActions(AbstractKeyHandler keyHandler) {
    keyHandler.put(KeySequence.getInstance(KeyStroke.getInstance(SWT.F2)), true, actionFactory.createDirectEditAction());
    for (IEditorKit editorKit : ReflectionFactory.getEditorKits()) {
        for (ILanguageKit lk : ReflectionFactory.getLanguageKits(false)) {
            if (!editorKit.canApply(lk))
                continue;
            for (Object[] textAction : E4Utils.textActionsFor(lk, ((IGEFEditorKit) editorKit).getActionFactory().textActions())) {
                KeySequence keySequence = (KeySequence) textAction[0];
                Class<IUpdatableAction> actionClass = (Class<IUpdatableAction>) textAction[2];
                try {
                    IUpdatableAction action = actionClass.getConstructor(IEclipseContext.class).newInstance(context);
                    keyHandler.put(editorKit, keySequence, true, action);
                } catch (Exception e) {
                }
            }
        }
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IEditorKit(org.whole.lang.reflect.IEditorKit) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 13 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence 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 14 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence 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

KeySequence (org.eclipse.jface.bindings.keys.KeySequence)14 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)7 IBindingService (org.eclipse.ui.keys.IBindingService)5 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)3 ParseException (org.eclipse.jface.bindings.keys.ParseException)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 VerifyEvent (org.eclipse.swt.events.VerifyEvent)2 Point (org.eclipse.swt.graphics.Point)2 BindingElement (org.eclipse.ui.internal.keys.model.BindingElement)2 Collection (java.util.Collection)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Binding (org.eclipse.jface.bindings.Binding)1 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)1 KeySequenceText (org.eclipse.jface.bindings.keys.KeySequenceText)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1