org.eclipse.jface.bindings.keys.KeyBinding Java Examples
The following examples show how to use
org.eclipse.jface.bindings.keys.KeyBinding.
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: KbdMacroLoadHandler.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Bind the loaded macro to its previous key binding, removing any conflicts * * @param editor * @param command - the new kbd macro command * @param sequence - key sequence for binding * @param previous - conflicting binding */ private void bindMacro(ITextEditor editor, Command command, KeySequence sequence, Binding previous) { if (command != null && sequence != null) { IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) : (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); if (service instanceof BindingService) { BindingService bindingMgr = (BindingService) service; if (previous != null) { bindingMgr.removeBinding(previous); } ParameterizedCommand p = new ParameterizedCommand(command, null); Binding binding = new KeyBinding(sequence, p, KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER); bindingMgr.addBinding(binding); // check for conflicts independent of the current Eclipse context checkConflicts(bindingMgr,sequence,binding); } } }
Example #2
Source File: KeyBindings.java From workspacemechanic with Eclipse Public License 1.0 | 5 votes |
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 #3
Source File: KeyController2.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example #4
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example #5
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example #6
Source File: KbdMacroBindHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Add the binding to the Emacs+ scheme * * @param editor * @param bindingResult */ private void addBinding(ITextEditor editor, IBindingResult bindingResult, String name) { IBindingService service = (IBindingService) editor.getSite().getService(IBindingService.class); if (service instanceof BindingService) { try { BindingService bindingMgr = (BindingService) service; if (bindingResult.getKeyBinding() != null) { // we're overwriting a binding, out with the old bindingMgr.removeBinding(bindingResult.getKeyBinding()); } Command command = null; if (name != null) { ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class); String id = EmacsPlusUtils.kbdMacroId(name); // check first, as getCommand will create it if it doesn't already exist if (ics.getDefinedCommandIds().contains(id)) { command = ics.getCommand(id); } } else { // use the unexposed category command = nameKbdMacro(KBD_LNAME + nameid++, editor, KBD_GAZONK); } if (command != null) { Binding binding = new KeyBinding(bindingResult.getTrigger(), new ParameterizedCommand(command, null), KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER); bindingMgr.addBinding(binding); asyncShowMessage(editor, String.format(BOUND, bindingResult.getKeyString()), false); } else { asyncShowMessage(editor, String.format(NO_NAME_UNO, name), true); } } catch (Exception e) { asyncShowMessage(editor, String.format(ABORT, bindingResult.getKeyString()), true); } } }
Example #7
Source File: BindKeysHelper.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @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 #8
Source File: BindingModel2.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }
Example #9
Source File: BindingModel2.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }
Example #10
Source File: BindingModel2.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }