Java Code Examples for org.eclipse.jface.bindings.keys.KeySequence#getInstance()
The following examples show how to use
org.eclipse.jface.bindings.keys.KeySequence#getInstance() .
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: KeyHandlerMinibuffer.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Check if the (accumulated) key strokes have a single binding * * @param state * @param keyCode * @param character * * @return true if most unique binding, else false */ protected boolean checkKey(int state, int keyCode, int character) { boolean result = true; keys.add(getKey(state,keyCode,character)); trigger = KeySequence.getInstance(keys); binding = bindingService.getPerfectMatch(trigger); boolean partial = bindingService.isPartialMatch(trigger); if (binding == null) { if (!partial) { keyCharacter = character; result = false; } } else if (partial) { // keep looking when there are additional partial matches binding = null; } return result; }
Example 2
Source File: KeyboardBindingsTask.java From workspacemechanic with Eclipse Public License 1.0 | 5 votes |
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 3
Source File: KeyBindingUtil.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * getKeySequence * * @return */ public static KeySequence[] getKeySequences(CommandElement command) { String[] bindings = command.getKeyBindings(); if (ArrayUtil.isEmpty(bindings)) { return NO_BINDINGS; } List<KeySequence> result = new ArrayList<KeySequence>(bindings.length); for (String binding : bindings) { try { // Need to convert the format String normalizedKeyBinding = normalizeKeyBinding(binding); KeySequence sequence = KeySequence.getInstance(normalizedKeyBinding); result.add(sequence); } catch (ParseException e) { String message = MessageFormat.format(Messages.CommandElement_Invalid_Key_Binding, new Object[] { binding, command.getDisplayName(), command.getPath(), e.getMessage() }); // Log to scripting console ScriptLogger.logError(message); IdeLog.logError(ScriptingUIPlugin.getDefault(), message); } } return result.toArray(new KeySequence[result.size()]); }
Example 4
Source File: KbdMacroBindHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Check for C-x C-k <key> binding conflict * * @param editor * @param c * @return IBindingResult with C-x C-k <key> information */ private IBindingResult getBinding(ITextEditor editor, char c) { IBindingResult result = null; try { final KeySequence sequence = KeySequence.getInstance(KeySequence.getInstance(STD_KBD_PREFIX), KeyStroke.getInstance(c)); final Binding binding = checkForBinding(editor, sequence); result = new IBindingResult() { public Binding getKeyBinding() { return binding; } public String getKeyString() { return sequence.format(); } public KeySequence getTrigger() { return sequence; } }; } catch (ParseException e) { } return result; }
Example 5
Source File: DynamicInitializer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * @throws ParseException */ public KeySequence getTrigger() throws ParseException { if (trigger == null) { trigger = KeySequence.getInstance(keyString); } return trigger; }
Example 6
Source File: QuickOutline.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 4 votes |
protected boolean isInvocationEvent(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); return keySequence.startsWith(triggerSequence, true); }
Example 7
Source File: KeybindingsManager.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private boolean processKeyStroke(Event event, KeyStroke keyStroke) { IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class); KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence(); KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, keyStroke); if (uniqueKeySequences.contains(sequenceAfterKeyStroke)) { IEvaluationService evaluationService = (IEvaluationService) workbench.getService(IEvaluationService.class); IEvaluationContext evaluationContext = evaluationService.getCurrentState(); IWorkbenchPart workbenchPart = (IWorkbenchPart) evaluationContext.getVariable(ISources.ACTIVE_PART_NAME); ICommandElementsProvider commandElementsProvider = (ICommandElementsProvider) workbenchPart .getAdapter(ICommandElementsProvider.class); if (commandElementsProvider != null) { // Is there a Eclipse binding that matches the key sequence? Binding binding = null; if (bindingService.isPerfectMatch(sequenceAfterKeyStroke)) { // Record it binding = bindingService.getPerfectMatch(sequenceAfterKeyStroke); } List<CommandElement> commandElements = commandElementsProvider .getCommandElements(sequenceAfterKeyStroke); if (commandElements.size() == 0) { if (binding == null) { // Remember the prefix incrementState(sequenceAfterKeyStroke); } else { // Reset our state resetState(); } // Do not consume the event. Let Eclipse handle it. return false; } else { if (binding == null && commandElements.size() == 1) { // We have a unique scripting command to execute executeCommandElement(commandElementsProvider, commandElements.get(0)); // Reset our state resetState(); // The event should be consumed return true; } else { // We need to show commands menu to the user IContextService contextService = (IContextService) workbench.getService(IContextService.class); popup(workbenchPart.getSite().getShell(), bindingService, contextService, commandElementsProvider, commandElements, event, binding, getInitialLocation(commandElementsProvider)); // Reset our state resetState(); // The event should be consumed return true; } } } } else if (uniqueKeySequencesPrefixes.contains(sequenceAfterKeyStroke)) { // Prefix match // Is there a Eclipse command with a perfect match if (bindingService.isPerfectMatch(sequenceAfterKeyStroke)) { // Reset our state resetState(); } else { // Remember the prefix incrementState(sequenceAfterKeyStroke); } } else { // Reset our state resetState(); } // We did not handle the event. Do not consume the event. Let Eclipse handle it. return false; }
Example 8
Source File: KeyBindingHelper.java From Pydev with Eclipse Public License 1.0 | 4 votes |
public static KeySequence getKeySequence(String text) throws ParseException, IllegalArgumentException { KeySequence keySequence = KeySequence.getInstance(KeyStroke.getInstance(text)); return keySequence; }
Example 9
Source File: KeyBindingState.java From APICloud-Studio with GNU General Public License v3.0 | 3 votes |
/** * Constructs a new instance of <code>KeyBindingState</code> with an empty key sequence, set to reset fully. * * @param workbenchToNotify * The workbench that this state should keep advised of changes to the key binding state; must not be * <code>null</code>. */ KeyBindingState(IWorkbench workbenchToNotify) { currentSequence = KeySequence.getInstance(); workbench = workbenchToNotify; associatedWindow = workbench.getActiveWorkbenchWindow(); }
Example 10
Source File: KeyBindingState.java From APICloud-Studio with GNU General Public License v3.0 | 2 votes |
/** * <p> * Resets the state based on the current properties. If the state is to collapse fully or if there are no key * strokes, then it sets the state to have an empty key sequence. Otherwise, it leaves the first key stroke in the * sequence. * </p> * <p> * The workbench's status lines are updated, if appropriate. * </p> */ void reset() { currentSequence = KeySequence.getInstance(); }