Search in sources :

Example 1 with Scheme

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

the class KeyController2 method setDefaultBindings.

/**
	 * Sets the bindings to default.
	 * @param bindingService
	 * @throws NotDefinedException
	 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
    // Fix the scheme in the local changes.
    final String defaultSchemeId = bindingService.getDefaultSchemeId();
    final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
    try {
        fBindingManager.setActiveScheme(defaultScheme);
    } catch (final NotDefinedException e) {
    // At least we tried....
    }
    // Restore any User defined bindings
    Binding[] bindings = fBindingManager.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
        String commandId = null;
        if (pCommand != null) {
            commandId = pCommand.getCommand().getId();
        }
        if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
            fBindingManager.removeBinding(bindings[i]);
        }
    }
    bindingModel.refresh(contextModel, lstRemove);
    saveBindings(bindingService);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) Scheme(org.eclipse.jface.bindings.Scheme) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 2 with Scheme

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

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

Scheme (org.eclipse.jface.bindings.Scheme)3 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)2 IBindingService (org.eclipse.ui.keys.IBindingService)2 CommandManager (org.eclipse.core.commands.CommandManager)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 ContextManager (org.eclipse.core.commands.contexts.ContextManager)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Binding (org.eclipse.jface.bindings.Binding)1 BindingManager (org.eclipse.jface.bindings.BindingManager)1 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)1 IWorkbench (org.eclipse.ui.IWorkbench)1