@Override public TriggerSequence createSequence(String sequence) { try { return KeySequence.getInstance(sequence); } catch (ParseException e) { // should probably log } return null; }
if (!keySequence.isComplete()) { throw new IllegalArgumentException( "Cannot bind to an incomplete key sequence"); //$NON-NLS-1$ if (keySequence.isEmpty()) { throw new IllegalArgumentException( "Cannot bind to an empty key sequence"); //$NON-NLS-1$
/** * <p> * Determines whether the given event represents a key press that should be handled as an * out-of-order event. An out-of-order key press is one that is passed to the focus control * first. Only if the focus control fails to respond will the regular key bindings get applied. * </p> * <p> * Care must be taken in choosing which keys are chosen as out-of-order keys. This method has * only been designed and test to work with the unmodified "Escape" key stroke. * </p> * * @param keyStrokes * The key stroke in which to look for out-of-order keys; must not be * <code>null</code>. * @return <code>true</code> if the key is an out-of-order key; <code>false</code> otherwise. */ private static boolean isOutOfOrderKey(List<KeyStroke> keyStrokes) { // Compare to see if one of the possible key strokes is out of order. final KeyStroke[] outOfOrderKeyStrokes = outOfOrderKeys.getKeyStrokes(); final int outOfOrderKeyStrokesLength = outOfOrderKeyStrokes.length; for (int i = 0; i < outOfOrderKeyStrokesLength; i++) { if (keyStrokes.contains(outOfOrderKeyStrokes[i])) { return true; } } return false; }
/** * Creates an instance of <code>KeySequence</code> given a key sequence * and a key stroke. * * @param keySequence * a key sequence. Must not be <code>null</code>. * @param keyStroke * a key stroke. Must not be <code>null</code>. * @return a key sequence that is equal to the given key sequence with the * given key stroke appended to the end. Guaranteed not to be * <code>null</code>. */ public static final KeySequence getInstance(final KeySequence keySequence, final KeyStroke keyStroke) { if (keySequence == null || keyStroke == null) { throw new NullPointerException(); } final KeyStroke[] oldKeyStrokes = keySequence.getKeyStrokes(); final int oldKeyStrokeLength = oldKeyStrokes.length; final KeyStroke[] newKeyStrokes = new KeyStroke[oldKeyStrokeLength + 1]; System .arraycopy(oldKeyStrokes, 0, newKeyStrokes, 0, oldKeyStrokeLength); newKeyStrokes[oldKeyStrokeLength] = keyStroke; return new KeySequence(newKeyStrokes); }
protected boolean isInvocationEvent(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); return keySequence.startsWith(triggerSequence, true); }
/** * Handles the modify event on the underlying text widget. * * @param event * The triggering event; ignored. */ public void modifyText(ModifyEvent event) { try { // The original sequence. KeySequence originalSequence = getKeySequence(); // The new sequence drawn from the text. String contents = getText(); KeySequence newSequence = KeySequence.getInstance(contents); // Check to see if they're the same. if (!originalSequence.equals(newSequence)) { setKeySequence(newSequence); } } catch (ParseException e) { // Abort any cut/paste-driven modifications setKeySequence(getKeySequence()); } } }
.getKeyStrokes(); final int newKeyStrokesLength = oldKeyStrokes.length - 1; if (newKeyStrokesLength >= 1) { System.arraycopy(oldKeyStrokes, 0, newKeyStrokes, 0, newKeyStrokesLength); setKeySequence(KeySequence.getInstance(newKeyStrokes)); } else { setKeySequence(KeySequence.getInstance());
final KeyStroke[] oldKeyStrokes = keySequence.getKeyStrokes(); final KeyStroke[] newKeyStrokes; if ((hasIncompleteStroke()) && (!keySequence.isEmpty())) { final int newKeyStrokesLength = oldKeyStrokes.length - 1; newKeyStrokes = new KeyStroke[newKeyStrokesLength]; setKeySequence(KeySequence.getInstance(keyStrokes));
final KeyStroke[] oldKeyStrokes = keySequence.getKeyStrokes(); if (maxStrokes < oldKeyStrokes.length) { final KeyStroke[] newKeyStrokes = new KeyStroke[maxStrokes]; .arraycopy(oldKeyStrokes, 0, newKeyStrokes, 0, maxStrokes); keySequence = KeySequence.getInstance(newKeyStrokes); String newString = keySequence.format(); if (!currentString.equals(newString)) { text.setText(keySequence.format()); text.addModifyListener(updateSequenceListener); text.setSelection(getText().length());
keySequence = KeySequence.getInstance(keySequenceText); } catch (final ParseException e) { addWarning(warningsToLog, "Could not parse key sequence", //$NON-NLS-1$ return null; if (keySequence.isEmpty() || !keySequence.isComplete()) { addWarning( warningsToLog, "Key bindings should not have an empty or incomplete key sequence", //$NON-NLS-1$ configurationElement, commandId, "keySequence", //$NON-NLS-1$ keySequence.toString()); return null;
startTextIndex = string.length(); currentStrokes.add(keyStrokes[i]); string = KeySequence.getInstance(currentStrokes).format(); string = KeySequence.getInstance(currentStrokes).format();
KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next()); if (isPartialMatch(sequenceAfterKeyStroke)) { final ParameterizedCommand cmd = getPerfectMatch(sequenceAfterKeyStroke); try { return executeCommand(cmd, event) || !sequenceBeforeKeyStroke.isEmpty(); } catch (final CommandException e) { return true; if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) { openKeyAssistShell(errorMatch); return !sequenceBeforeKeyStroke.isEmpty();
@Override public Map getPartialMatches(KeySequence keySequence) { try { final org.eclipse.jface.bindings.keys.KeySequence sequence = org.eclipse.jface.bindings.keys.KeySequence .getInstance(keySequence.toString()); final Map partialMatches = bindingManager .getPartialMatches(sequence); final Map returnValue = new HashMap(); final Iterator matchItr = partialMatches.entrySet().iterator(); while (matchItr.hasNext()) { final Map.Entry entry = (Map.Entry) matchItr.next(); final TriggerSequence trigger = (TriggerSequence) entry .getKey(); if (trigger instanceof org.eclipse.jface.bindings.keys.KeySequence) { final org.eclipse.jface.bindings.keys.KeySequence triggerKey = (org.eclipse.jface.bindings.keys.KeySequence) trigger; returnValue.put(KeySequence.getInstance(triggerKey .toString()), entry.getValue()); } } return returnValue; } catch (final ParseException e) { return new HashMap(); } catch (final org.eclipse.ui.keys.ParseException e) { return new HashMap(); } }
if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getKeySequence().equals(keySequence)) { if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement() .getId(); if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement() .getId();
if (commandSequence != null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) { control.addFocusListener(new FocusListener() { private CommandKeyListener fCommandKeyListener;
/** * Creates an instance of <code>KeySequence</code> given a single key * stroke. * * @param keyStroke * a single key stroke. Must not be <code>null</code>. * @return a key sequence. Guaranteed not to be <code>null</code>. */ public static final KeySequence getInstance(final KeyStroke keyStroke) { return new KeySequence(new KeyStroke[] { keyStroke }); }
/** * Tests whether the current key sequence has a stroke with no natural key. * * @return <code>true</code> is there is an incomplete stroke; * <code>false</code> otherwise. */ private boolean hasIncompleteStroke() { return !keySequence.isComplete(); }
/** * Updates the text of the status line of the associated shell with the * current sequence. */ private void updateStatusLines() { StatusLineContributionItem statusLine = getStatusLine(); if (statusLine != null) { statusLine.setText(getCurrentSequence().format()); } } }
/** * Handles the modify event on the underlying text widget. * * @param event * The triggering event; ignored. */ @Override public void modifyText(ModifyEvent event) { try { // The original sequence. KeySequence originalSequence = getKeySequence(); // The new sequence drawn from the text. String contents = getText(); KeySequence newSequence = KeySequence.getInstance(contents); // Check to see if they're the same. if (!originalSequence.equals(newSequence)) { setKeySequence(newSequence); } } catch (ParseException e) { // Abort any cut/paste-driven modifications setKeySequence(getKeySequence()); } } }
.getKeyStrokes(); final int newKeyStrokesLength = oldKeyStrokes.length - 1; if (newKeyStrokesLength >= 1) { System.arraycopy(oldKeyStrokes, 0, newKeyStrokes, 0, newKeyStrokesLength); setKeySequence(KeySequence.getInstance(newKeyStrokes)); } else { setKeySequence(KeySequence.getInstance());