org.eclipse.jface.bindings.Scheme Java Examples

The following examples show how to use org.eclipse.jface.bindings.Scheme. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShieldStartup.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void earlyStartup() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	workbench.getDisplay().asyncExec(new Runnable() {
		
		public void run() {
			// 在工作台初始化后,移除平台默认的 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();
				}
			}
		}
	});
}
 
Example #2
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #4
Source File: KeyboardBindingsTask.java    From workspacemechanic with Eclipse Public License 1.0 6 votes vote down vote up
private EvaluationResult doEvaluate(
    final KbaChangeSet changeSet) {

  final KeyBindings bindings = new KeyBindings(bindingService.getBindings());

  final Scheme scheme = bindingService.getScheme(changeSet.getSchemeId());

  switch (changeSet.getAction()) {
  case ADD:
    modifyBindingsForAddChangeSet(changeSet, bindings, scheme);
    break;
  case REMOVE:
    modifyBindingsForRemoveChangeSet(changeSet, bindings, scheme);
    break;
  default:
    throw new UnsupportedOperationException();  
  }

  return new EvaluationResult(scheme, bindings);
}
 
Example #5
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getKeyboardShortcut(ParameterizedCommand command) {
	IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
	fgLocalBindingManager.setBindings(bindingService.getBindings());
	try {
		Scheme activeScheme= bindingService.getActiveScheme();
		if (activeScheme != null)
			fgLocalBindingManager.setActiveScheme(activeScheme);
	} catch (NotDefinedException e) {
		JavaPlugin.log(e);
	}

	TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
	if (bindings.length > 0)
		return bindings[0].format();
	return null;
}
 
Example #7
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #8
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #10
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param force if true, we'll create the user binding regardless of having some existing binding. Otherwise,
 * we'll not allow the creation if a binding already exists for it.
 *
 * Note: conflicting bindings should be removed before (through removeUserBindingsWithFilter). If they're
 * not removed, a conflict will be created in the bindings.
 */
public void addUserBindings(KeySequence keySequence, ParameterizedCommand command) throws Exception {
    Scheme activeScheme = bindingService.getActiveScheme();
    String schemeId = activeScheme.getId();

    localChangeManager.addBinding(new KeyBinding(keySequence, command,
            schemeId, contextId, null, null, null, Binding.USER));

}
 
Example #11
Source File: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Bind a scheme / platform / context / trigger sequence to a command.
 */
public void addIfNotPresent(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    ParameterizedCommand command) {
  Map<String,String> params = commandParamMap(command);
  Binding binding = find(scheme, platform, triggerSequence, command.getId(), params);
  // If no binding exists, create the user binding, add it and return true.
  if (binding == null) {
    Binding bindingToAdd = createBinding(scheme, platform, contextId, triggerSequence, command);
    addUserBinding(bindingToAdd);
    addedBindings.add(bindingToAdd);
    return;
  }

  /*
   * If a system binding exists for this scheme / sequence, find out if there's a
   * user binding hiding it, and if so remove it.
   */
  if ((binding.getType() == Binding.SYSTEM)) {
    // Finding a user binding to a null command.
    // ZORZELLA: do we even need to supply params?
    Binding userBinding = find(scheme, platform, triggerSequence, null, params, userBindings);
    if (userBinding != null) {
      userBindings.remove(userBinding);
      return;
    }
  }
  return;
}
 
Example #12
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #13
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #14
Source File: ShieldStartup.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
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();
		}
	}
}
 
Example #15
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #16
Source File: KeyboardBindingsTask.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private void modifyBindingsForAddChangeSet(final KbaChangeSet changeSet,
    final KeyBindings bindings, final Scheme scheme) {
  for (KbaBinding toAdd : changeSet.getBindingList()) {
    Command commandToAdd = commandService.getCommand(toAdd.getCid());
    if (!commandToAdd.isDefined()) {
      log.logWarning("Command '" + toAdd.getCid() + "' does not exist. Skipping.");
      continue;
    }
    ParameterizedCommand parameterizedCommandToAdd =
        ParameterizedCommand.generateCommand(commandToAdd, toAdd.getParameters());

    KeySequence triggerSequence;
    try {
      triggerSequence = KeySequence.getInstance(toAdd.getKeySequence());
    } catch (ParseException e) {
      log.logError(e, "Invalid key sequence: %s", toAdd.getKeySequence());
      throw new RuntimeException(e);
    }

    bindings.addIfNotPresent(
        scheme, 
        changeSet.getPlatform(), 
        changeSet.getContextId(), 
        triggerSequence,
        parameterizedCommandToAdd);
  }
}
 
Example #17
Source File: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private Binding createBinding(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    ParameterizedCommand parameterizedCommand) {

  Binding newBinding =
      new KeyBinding(triggerSequence, parameterizedCommand, scheme.getId(),
          contextId, null, platform, null, Binding.USER);

  return newBinding;
}
 
Example #18
Source File: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds a binding in {@code list} that matches the given
 * {@code triggerSequence}, {@code scheme} and {@code cid}. If not found,
 * return {@code null}.
 */
private static Binding find(
    Scheme scheme,
    String platform,
    KeySequence triggerSequence,
    String cid,
    Map<String,String> params,
    List<Binding> list) {
  for (Binding binding : list) {
    if (binding.getSchemeId().equals(scheme.getId())
      && (binding.getTriggerSequence().equals(triggerSequence))
      && Objects.equal(binding.getPlatform(),  platform)) {
        ParameterizedCommand param = binding.getParameterizedCommand();
        if (param == null) {
          if (cid == null) {
            return binding;
          }
          continue;
        }
        Command command = param.getCommand();
        if (cid == null) {
          return command == null ? binding : null;
        }
        if (cid.equals(command.getId())) {
          Map<String,String> temp = commandParamMap(param);
          if (equalMaps(temp, params)) {
            return binding;
          }
        }
      }
  }
  return null;
}
 
Example #19
Source File: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private Binding find(
    Scheme scheme,
    String platform,
    KeySequence triggerSequence,
    String cid,
    Map<String, String> params) {
  Binding userBinding = find(scheme, platform, triggerSequence, cid, params, userBindings);
  if (userBinding != null) {
    return userBinding;
  }
  return find(scheme, platform, triggerSequence, cid, params, systemBindings);
}
 
Example #20
Source File: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Remove a binding.
 */
public void removeBindingIfPresent(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    Command command,
    Map<String, String> params) {

  Binding binding = find(scheme, platform, triggerSequence, command.getId(), params, userBindings);

  if (binding != null) {
    userBindings.remove(binding);
    removedBindings.add(binding);
    return;
  }

  binding = find(scheme, platform, triggerSequence, command.getId(), params, systemBindings);
  if (binding != null) {
    if (find(scheme, platform, triggerSequence, null, params, userBindings) == null) {
      Binding bindingToRemoveWithNullCommand = createBinding(scheme, platform, contextId, triggerSequence, null);
      // Removing a system binding means creating a weird system binding with
      // a null command
      addUserBinding(bindingToRemoveWithNullCommand);
      removedBindings.add(binding);
      return;
    }
  }
  return;
}
 
Example #21
Source File: KeyboardBindingsTask.java    From workspacemechanic with Eclipse Public License 1.0 4 votes vote down vote up
public EvaluationResult(
    final Scheme scheme,
    final KeyBindings keyBindings) {
  this.scheme = scheme;
  this.keyBindings = keyBindings;
}
 
Example #22
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param contextId defines the keys context we'll work with...
 *
 * We'll only remove/add bindings to this context.
 */
public BindKeysHelper(String contextId) {
    Assert.isNotNull(contextId);
    this.contextId = contextId;

    // Set the context we're working with.
    Set<String> activeContextIds = new HashSet<>();
    activeContextIds.add(contextId);
    contextManager.setActiveContextIds(activeContextIds);

    // Check that the context we're working with actually exists
    IWorkbench workbench = PlatformUI.getWorkbench();
    bindingService = (IBindingService) workbench.getService(IBindingService.class);
    IContextService contextService = (IContextService) workbench.getService(IContextService.class);
    Context context = contextService.getContext(contextId);
    if (context == null || context.isDefined() == false) {
        throw new RuntimeException("The context: " + contextId + " does not exist.");
    }

    Scheme activeScheme = bindingService.getActiveScheme();
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();

    // Make a copy we can work with locally (we'll apply changes later based on this copy).
    try {
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = localChangeManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        localChangeManager.setActiveScheme(activeScheme);
    } catch (final NotDefinedException e) {
        throw new Error("There is a programmer error in the bind keys helper"); //$NON-NLS-1$
    }
    localChangeManager.setLocale(bindingService.getLocale());
    localChangeManager.setPlatform(bindingService.getPlatform());
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        initialState.add(binding);
    }
    localChangeManager.setBindings(bindings);
}