Search in sources :

Example 1 with IBindingService

use of org.eclipse.ui.keys.IBindingService in project dbeaver by serge-rider.

the class ActionUtils method findCommandDescription.

@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {
    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())) {
                sequence = b.getTriggerSequence();
            }
        }
        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)

Example 2 with IBindingService

use of org.eclipse.ui.keys.IBindingService in project translationstudio8 by heartsome.

the class ShieldStartup method earlyStartup.

public void earlyStartup() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    // 在工作台初始化后,移除平台默认的 scheme
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    Scheme[] schemes = bindingService.getDefinedSchemes();
    for (int i = 0; i < schemes.length; i++) {
        String id = schemes[i].getId();
        if (id.equals(platformDefaultScheme) || id.equals(platformEmacsScheme)) {
            schemes[i].undefine();
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Scheme(org.eclipse.jface.bindings.Scheme) IBindingService(org.eclipse.ui.keys.IBindingService)

Example 3 with IBindingService

use of org.eclipse.ui.keys.IBindingService in project translationstudio8 by heartsome.

the class TmMatchEditDialog method close.

@Override
public boolean close() {
    IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
    bindingService.setKeyFilterEnabled(true);
    srcSegmentViewer.reset();
    tgtSegmentViewer.reset();
    return super.close();
}
Also used : IBindingService(org.eclipse.ui.keys.IBindingService)

Example 4 with IBindingService

use of org.eclipse.ui.keys.IBindingService in project translationstudio8 by heartsome.

the class KeyController2 method filterDupliteBind.

@SuppressWarnings("restriction")
public void filterDupliteBind() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service = (BindingService) bindingService;
    BindingManager bindingManager = service.getBindingManager();
    //service.getBindingManager().
    Binding[] bindings = bindingManager.getBindings();
    List<Binding> bindTemp = new ArrayList<Binding>();
    List<String> ids = new ArrayList<String>();
    for (Binding bind : bindings) {
        if (null == bind) {
            continue;
        }
        ParameterizedCommand command = bind.getParameterizedCommand();
        if (null == command) {
            continue;
        }
        String id = command.getId();
        if (!ids.contains(id)) {
            ids.add(id);
            bindTemp.add(bind);
        }
    }
    bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) BindingManager(org.eclipse.jface.bindings.BindingManager) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) IBindingService(org.eclipse.ui.keys.IBindingService) BindingService(org.eclipse.ui.internal.keys.BindingService) ArrayList(java.util.ArrayList) IBindingService(org.eclipse.ui.keys.IBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 5 with IBindingService

use of org.eclipse.ui.keys.IBindingService in project translationstudio8 by heartsome.

the class KeyController2 method loadModelBackend.

private static BindingManager loadModelBackend(IServiceLocator locator) {
    IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
    BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
            if (definedSchemes[i] == bindingService.getActiveScheme()) {
                modelActiveScheme = copy;
            }
        }
        bindingManager.setActiveScheme(modelActiveScheme);
    } catch (final NotDefinedException e) {
        StatusManager.getManager().handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Keys page found an undefined scheme", //$NON-NLS-1$
        e));
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());
    bindingManager.setBindings(bindingService.getBindings());
    return bindingManager;
}
Also used : BindingManager(org.eclipse.jface.bindings.BindingManager) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CommandManager(org.eclipse.core.commands.CommandManager) Scheme(org.eclipse.jface.bindings.Scheme) ContextManager(org.eclipse.core.commands.contexts.ContextManager) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IBindingService(org.eclipse.ui.keys.IBindingService)

Aggregations

IBindingService (org.eclipse.ui.keys.IBindingService)7 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 Binding (org.eclipse.jface.bindings.Binding)3 IWorkbench (org.eclipse.ui.IWorkbench)3 ArrayList (java.util.ArrayList)2 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)2 BindingManager (org.eclipse.jface.bindings.BindingManager)2 Scheme (org.eclipse.jface.bindings.Scheme)2 BindingService (org.eclipse.ui.internal.keys.BindingService)2 ContextType (com.reprezen.swagedit.core.assist.contexts.ContextType)1 Command (org.eclipse.core.commands.Command)1 CommandManager (org.eclipse.core.commands.CommandManager)1 ContextManager (org.eclipse.core.commands.contexts.ContextManager)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)1 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)1 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ICommandService (org.eclipse.ui.commands.ICommandService)1