List of usage examples for org.eclipse.jface.bindings.keys KeySequence getInstance
public static final KeySequence getInstance(final KeySequence keySequence, final KeyStroke keyStroke)
KeySequence given a key sequence and a key stroke. From source file:com.aptana.scripting.keybindings.internal.KeybindingsManager.java
License:Open Source License
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); }/*from ww w . j a v a2 s.c o m*/ 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; }
From source file:com.mulgasoft.emacsplus.commands.KbdMacroBindHandler.java
License:Open Source License
/** * Check for C-x C-k <key> binding conflict * /* w ww . j a v a 2 s . c o m*/ * @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; }
From source file:org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.java
License:Open Source License
/** * @param potentialKeyStrokes/*from w w w .j a v a 2 s. co m*/ * @param event * @return */ public boolean press(List<KeyStroke> potentialKeyStrokes, Event event) { KeySequence errorSequence = null; Collection<Binding> errorMatch = null; KeySequence sequenceBeforeKeyStroke = state; for (Iterator<KeyStroke> iterator = potentialKeyStrokes.iterator(); iterator.hasNext();) { KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next()); if (isPartialMatch(sequenceAfterKeyStroke)) { incrementState(sequenceAfterKeyStroke); return true; } else if (isPerfectMatch(sequenceAfterKeyStroke)) { final ParameterizedCommand cmd = getPerfectMatch(sequenceAfterKeyStroke); try { return executeCommand(cmd, event) || !sequenceBeforeKeyStroke.isEmpty(); } catch (final CommandException e) { return true; } } else if ((keyAssistDialog != null) && (keyAssistDialog.getShell() != null) && ((event.keyCode == SWT.ARROW_DOWN) || (event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_LEFT) || (event.keyCode == SWT.ARROW_RIGHT) || (event.keyCode == SWT.CR) || (event.keyCode == SWT.PAGE_UP) || (event.keyCode == SWT.PAGE_DOWN))) { // We don't want to swallow keyboard navigation keys. return false; } else { Collection<Binding> matches = getBindingService().getConflictsFor(sequenceAfterKeyStroke); if (matches != null && !matches.isEmpty()) { errorSequence = sequenceAfterKeyStroke; errorMatch = matches; } } } resetState(true); if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) { openKeyAssistShell(errorMatch); } return !sequenceBeforeKeyStroke.isEmpty(); }
From source file:org.eclipse.ui.internal.keys.WorkbenchKeyboard.java
License:Open Source License
/** * Processes a key press with respect to the key binding architecture. This * updates the mode of the command manager, and runs the current handler for * the command that matches the key sequence, if any. * * @param potentialKeyStrokes//from w ww. j a v a2 s.c o m * The key strokes that could potentially match, in the order of * priority; must not be <code>null</code>. * @param event * The event; may be <code>null</code>. * @return <code>true</code> if a command is executed; <code>false</code> * otherwise. */ public boolean press(List potentialKeyStrokes, Event event) { if (DEBUG && DEBUG_VERBOSE) { Tracing.printTrace("KEYS", //$NON-NLS-1$ "WorkbenchKeyboard.press(potentialKeyStrokes = " //$NON-NLS-1$ + potentialKeyStrokes + ')'); } final Widget widget = event.widget; updateShellKludge(widget); KeySequence errorSequence = null; Collection errorMatch = null; KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence(); for (Iterator iterator = potentialKeyStrokes.iterator(); iterator.hasNext();) { KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, (KeyStroke) iterator.next()); if (isPartialMatch(sequenceAfterKeyStroke)) { incrementState(sequenceAfterKeyStroke); return true; } else if (isPerfectMatch(sequenceAfterKeyStroke)) { final Binding binding = getPerfectMatch(sequenceAfterKeyStroke); try { return executeCommand(binding, event) || !sequenceBeforeKeyStroke.isEmpty(); } catch (final CommandException e) { logException(e, binding.getParameterizedCommand()); return true; } } else if ((keyAssistDialog != null) && (keyAssistDialog.getShell() != null) && ((event.keyCode == SWT.ARROW_DOWN) || (event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_LEFT) || (event.keyCode == SWT.ARROW_RIGHT) || (event.keyCode == SWT.CR) || (event.keyCode == SWT.PAGE_UP) || (event.keyCode == SWT.PAGE_DOWN))) { // We don't want to swallow keyboard navigation keys. return false; } else { Collection match = getBindingService().getConflictsFor(sequenceAfterKeyStroke); if (match != null) { errorSequence = sequenceAfterKeyStroke; errorMatch = match; } } } resetState(true); if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) { openKeyAssistShell(errorMatch); } return !sequenceBeforeKeyStroke.isEmpty(); }