List of usage examples for org.eclipse.jface.bindings.keys KeySequence startsWith
public final boolean startsWith(final TriggerSequence triggerSequence, final boolean equals)
From source file:com.reprezen.swagedit.core.editor.outline.QuickOutline.java
License:Open Source License
protected boolean isInvocationEvent(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); return keySequence.startsWith(triggerSequence, true); }
From source file:org.eclipse.ui.internal.keys.KeyAssistDialog.java
License:Open Source License
/** * Returns a string representing the key sequence used to open this dialog. * * @return the string describing the key sequence, or <code>null</code> if * it cannot be determined./*from www. ja v a 2s .c om*/ */ private String getKeySequenceString() { final Command command = commandService.getCommand(IWorkbenchCommandConstants.WINDOW_SHOW_KEY_ASSIST); final TriggerSequence[] keyBindings = bindingService .getActiveBindingsFor(new ParameterizedCommand(command, null)); final int keyBindingsCount = keyBindings.length; final KeySequence currentState = keyBindingState.getCurrentSequence(); final int prefixSize = currentState.getKeyStrokes().length; // Try to find the first possible matching key binding. KeySequence keySequence = null; for (int i = 0; i < keyBindingsCount; i++) { keySequence = (KeySequence) keyBindings[i]; // Now just double-check to make sure the key is still possible. if (prefixSize > 0) { if (keySequence.startsWith(currentState, false)) { /* * Okay, so we have a partial match. Replace the key binding * with the required suffix completion. */ final KeyStroke[] oldKeyStrokes = keySequence.getKeyStrokes(); final int newSize = oldKeyStrokes.length - prefixSize; final KeyStroke[] newKeyStrokes = new KeyStroke[newSize]; System.arraycopy(oldKeyStrokes, prefixSize, newKeyStrokes, 0, newSize); keySequence = KeySequence.getInstance(newKeyStrokes); break; } /* * The prefix doesn't match, so null out the key binding and try * again. */ keySequence = null; continue; } // There is no prefix, so just grab the first. break; } if (keySequence == null) { return null; // couldn't find a suitable key binding } // RAP [if]: need session aware messages // return NLS.bind(KeyAssistMessages.openPreferencePage, keySequence // .format()); return NLS.bind(KeyAssistMessages.get().openPreferencePage, keySequence.format()); }