Search in sources :

Example 1 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project translationstudio8 by heartsome.

the class BindingModel2 method restoreBinding.

/**
	 * Restores the specified BindingElement. A refresh should be performed afterwards. The refresh may be done after
	 * several elements have been restored.
	 * @param element
	 */
public void restoreBinding(BindingElement element) {
    if (element == null) {
        return;
    }
    Object modelObject = element.getModelObject();
    ParameterizedCommand cmd = null;
    if (modelObject instanceof ParameterizedCommand) {
        cmd = (ParameterizedCommand) modelObject;
        TriggerSequence trigger = bindingManager.getBestActiveBindingFor(cmd.getId());
        Binding binding = bindingManager.getPerfectMatch(trigger);
        if (binding != null && binding.getType() == Binding.SYSTEM) {
            return;
        }
    } else if (modelObject instanceof KeyBinding) {
        cmd = ((KeyBinding) modelObject).getParameterizedCommand();
    }
    // Remove any USER bindings
    Binding[] managerBindings = bindingManager.getBindings();
    ArrayList systemBindings = new ArrayList();
    ArrayList removalBindings = new ArrayList();
    for (int i = 0; i < managerBindings.length; i++) {
        if (managerBindings[i].getParameterizedCommand() == null) {
            removalBindings.add(managerBindings[i]);
        } else if (managerBindings[i].getParameterizedCommand().equals(cmd)) {
            if (managerBindings[i].getType() == Binding.USER) {
                bindingManager.removeBinding(managerBindings[i]);
            } else if (managerBindings[i].getType() == Binding.SYSTEM) {
                systemBindings.add(managerBindings[i]);
            }
        }
    }
    // Clear the USER bindings for parameterized commands
    Iterator i = systemBindings.iterator();
    while (i.hasNext()) {
        Binding sys = (Binding) i.next();
        Iterator j = removalBindings.iterator();
        while (j.hasNext()) {
            Binding del = (Binding) j.next();
            if (deletes(del, sys) && del.getType() == Binding.USER) {
                bindingManager.removeBinding(del);
            }
        }
    }
    setSelectedElement(null);
    bindingElements.remove(element);
    bindingToElement.remove(modelObject);
    commandToElement.remove(modelObject);
    controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, element);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 2 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project n4js by eclipse.

the class WorkspaceWizardPage method getActiveContentAssistBinding.

/**
 * Returns the active key binding for content assist.
 *
 * If no binding is set null is returned.
 */
private KeyStroke getActiveContentAssistBinding() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(CONTENT_ASSIST_ECLIPSE_COMMAND_ID);
    if (activeBindingsFor.length > 0 && activeBindingsFor[0] instanceof KeySequence) {
        KeyStroke[] strokes = ((KeySequence) activeBindingsFor[0]).getKeyStrokes();
        if (strokes.length == 1) {
            return strokes[0];
        }
    }
    return null;
}
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 3 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence 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)

Example 4 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project webtools.sourceediting by eclipse.

the class StructuredContentAssistProcessor method getIterationBinding.

/**
 * @return {@link KeySequence} used by user to iterate to the next page
 */
private KeySequence getIterationBinding() {
    final IBindingService bindingSvc = PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    TriggerSequence binding = bindingSvc.getBestActiveBindingFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
    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)

Example 5 with TriggerSequence

use of org.eclipse.jface.bindings.TriggerSequence in project dbeaver by serge-rider.

the class ActionUtils method findCommandDescription.

@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly, String paramName, String paramValue) {
    String commandName = null;
    String shortcut = null;
    ICommandService commandService = serviceLocator.getService(ICommandService.class);
    if (commandService != null) {
        Command command = commandService.getCommand(commandId);
        if (command != null && command.isDefined()) {
            try {
                commandName = command.getName();
            } catch (NotDefinedException e) {
                log.debug(e);
            }
        }
    }
    IBindingService bindingService = serviceLocator.getService(IBindingService.class);
    if (bindingService != null) {
        TriggerSequence sequence = null;
        for (Binding b : bindingService.getBindings()) {
            ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
            if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
                if (paramName != null) {
                    Object cmdParamValue = parameterizedCommand.getParameterMap().get(paramName);
                    if (!CommonUtils.equalObjects(cmdParamValue, paramValue)) {
                        continue;
                    }
                }
                sequence = b.getTriggerSequence();
                break;
            }
        }
        if (sequence == null) {
            sequence = bindingService.getBestActiveBindingFor(commandId);
        }
        if (sequence != null) {
            shortcut = sequence.format();
        }
    }
    if (shortcutOnly) {
        return shortcut == null ? "" : shortcut;
    }
    if (shortcut == null) {
        return commandName;
    }
    if (commandName == null) {
        return shortcut;
    }
    return commandName + " (" + shortcut + ")";
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IBindingService(org.eclipse.ui.keys.IBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) Nullable(org.jkiss.code.Nullable)

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