List of usage examples for org.eclipse.jface.bindings.keys KeySequence getInstance
public static final KeySequence getInstance(final String string) throws ParseException
KeySequence by parsing a given formal string representation. From source file:com.aptana.editor.findbar.impl.FindBarActions.java
License:Open Source License
/** * Updates the list of commands -> binding available. *//*from w w w . j a va 2 s. c o m*/ public void updateCommandToBinding() { fCommandToBinding = getCommandToBindings(); FindBarDecorator dec = findBarDecorator.get(); if (dec != null) { // Whenever we get the bindings, update the tooltips accordingly. updateTooltip(TOGGLE_WORD_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_WholeWord, dec.wholeWord); updateTooltip(TOGGLE_CASE_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_CaseSensitive, dec.caseSensitive); if (dec.regularExpression != null) { updateTooltip(TOGGLE_REGEXP_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_RegularExpression, dec.regularExpression); } updateTooltip(TOGGLE_SEARCH_BACKWARD_COMMAND_ID, Messages.FindBarDecorator_LABEL_SearchBackward, dec.searchBackward); updateTooltip(TOGGLE_COUNT_MATCHES_COMMAND_ID, Messages.FindBarDecorator_TOOLTIP_ShowMatchCount, dec.countMatches); updateTooltip(TOGGLE_SEARCH_SELECTION_COMMAND_ID, Messages.FindBarDecorator_LABEL_SearchSelection, dec.searchSelection); updateTooltip(SHOW_OPTIONS_COMMAND_ID, Messages.FindBarDecorator_LABEL_ShowOptions, dec.options); String prevHistoryKey = KeySequence.getInstance(KeyStroke.getInstance(SWT.MOD1, SWT.ARROW_UP)) .toString(); String nextHistoryKey = KeySequence.getInstance(KeyStroke.getInstance(SWT.MOD1, SWT.ARROW_DOWN)) .toString(); List<TriggerSequence> bindings = fCommandToBinding.get(FOCUS_REPLACE_COMMAND_ID); if (!CollectionsUtil.isEmpty(bindings)) { List<TriggerSequence> newlineTriggers = fCommandToBinding.get(INPUT_NEWLINE_COMMAND_ID); List<String> triggers = new ArrayList<String>(newlineTriggers.size() + 1); triggers.add(bindings.get(0).toString()); for (TriggerSequence sequence : newlineTriggers) { triggers.add(sequence.toString()); } if (triggers.size() < 3) { triggers.add(StringUtil.EMPTY); } triggers.add(prevHistoryKey); triggers.add(nextHistoryKey); dec.textReplace .setToolTipText(MessageFormat.format(Messages.FindBarActions_TOOLTIP_FocusReplaceCombo, triggers.toArray(new Object[triggers.size()]))); } bindings = fCommandToBinding.get(FOCUS_FIND_COMMAND_ID); if (!CollectionsUtil.isEmpty(bindings)) { List<TriggerSequence> newlineTriggers = fCommandToBinding.get(INPUT_NEWLINE_COMMAND_ID); List<String> triggers = new ArrayList<String>(newlineTriggers.size() + 1); triggers.add(bindings.get(0).toString()); for (TriggerSequence sequence : newlineTriggers) { triggers.add(sequence.toString()); } if (triggers.size() < 3) { triggers.add(StringUtil.EMPTY); } triggers.add(prevHistoryKey); triggers.add(nextHistoryKey); dec.textFind.setToolTipText(MessageFormat.format(Messages.FindBarActions_TOOLTIP_FocusFindCombo, triggers.toArray(new Object[triggers.size()]))); } } }
From source file:com.aptana.scripting.model.CommandElement.java
License:Open Source License
/** * getKeySequence//from w w w . j av a 2 s . c o m * * @return */ public KeySequence[] getKeySequences() { String[] bindings = this.getKeyBindings(); List<KeySequence> result = new ArrayList<KeySequence>(); if (bindings != null && bindings.length > 0) { for (String binding : bindings) { try { // Need to convert the format String normalizedKeyBinding = ScriptUtils.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, this.getDisplayName(), this.getPath(), e.getMessage() }); ScriptLogger.logError(message); } } } return result.toArray(new KeySequence[result.size()]); }
From source file:com.aptana.scripting.ui.KeyBindingUtil.java
License:Open Source License
/** * getKeySequence/*from w ww . j ava 2 s. c o m*/ * * @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()]); }
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private void updateKeyBinding(Map<String, String> map) throws CoreException { try {//from w w w .j a v a 2 s . c om String platform = map.get(XML_ATTRIBUTE_PLATFORM); String commandName = map.get(XML_ATTRIBUTE_COMMANDID); String stdKeys = map.get(XML_ATTRIBUTE_KEYS); Binding binding = findBinding(commandName, platform); if (binding == null) { return; } Command command = binding.getParameterizedCommand().getCommand(); ParameterizedCommand cmd = new ParameterizedCommand(command, null); String schemeId = binding.getSchemeId(); String contextId = binding.getContextId(); String locale = binding.getLocale(); String wm = null; int type = Binding.USER; KeySequence stdSeq = KeySequence.getInstance(stdKeys); Binding newBind = new KeyBinding(stdSeq, cmd, schemeId, contextId, locale, platform, wm, type); bindingManager.removeBindings(stdSeq, schemeId, contextId, null, null, null, type); bindingManager.addBinding(newBind); } catch (NotDefinedException ex) { throw createException(ex, ex.getMessage()); } catch (ParseException ex) { throw createException(ex, ex.getMessage()); } }
From source file:com.google.dart.tools.ui.omni.OmniBoxPopup.java
License:Open Source License
private KeyAdapter getKeyAdapter() { if (keyAdapter == null) { keyAdapter = new KeyAdapter() { @Override/*from www . ja va2 s . co m*/ public void keyPressed(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); TriggerSequence[] sequences = getInvokingCommandKeySequences(); if (sequences == null) { return; } for (int i = 0; i < sequences.length; i++) { if (sequences[i].equals(keySequence)) { e.doit = false; toggleShowAllMatches(); return; } } } }; } return keyAdapter; }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyboardBindingsTask.java
License:Open Source License
private void modifyBindingsForRemoveChangeSet(final KbaChangeSet changeSet, final KeyBindings bindings, final Scheme scheme) { if (!ENABLE_EXP_REM()) { return;//from w w w . j a v a 2 s . com } for (KbaBinding toRemove : changeSet.getBindingList()) { Command commandToRemove; try { commandToRemove = commandService.getCommand(toRemove.getCid()); } catch (RuntimeException e) { log.logError(e); throw e; } KeySequence triggerSequence; try { triggerSequence = KeySequence.getInstance(toRemove.getKeySequence()); } catch (ParseException e) { log.logError(e, "Invalid key sequence: %s", toRemove.getKeySequence()); throw new RuntimeException(e); } // Removing a system binding means one of: // 1. if it's a user binding, remove it // 2. if it's a system binding, create a null-command user binding doppleganger bindings.removeBindingIfPresent(scheme, changeSet.getPlatform(), changeSet.getContextId(), triggerSequence, commandToRemove, toRemove.getParameters()); // If our remove binding is against the "null" platform, it should apply // to all platforms. The only one that matters is the current platform if (changeSet.getPlatform() == null) { bindings.removeBindingIfPresent(scheme, SWT.getPlatform(), changeSet.getContextId(), triggerSequence, commandToRemove, toRemove.getParameters()); } } }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyboardBindingsTask.java
License:Open Source License
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; }//w ww.ja v a 2 s . c o m 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); } }
From source file:com.mulgasoft.emacsplus.commands.EmacsHelpHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { EmacsPlusConsole console = EmacsPlusConsole.getInstance(); console.clear();// w ww . j a v a 2 s .c o m console.activate(); IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench() .getService(IBindingService.class); String id = (event.getCommand() != null ? event.getCommand().getId() : null); if (id != null) { try { TriggerSequence trigger = bindingService.getBestActiveBindingFor(event.getCommand().getId()); Trigger[] trigs = trigger.getTriggers(); KeyStroke key = (KeyStroke) trigs[0]; Collection<Binding> partials = EmacsPlusUtils .getPartialMatches(bindingService, KeySequence.getInstance(key)).values(); for (Binding bind : partials) { ParameterizedCommand cmd = bind.getParameterizedCommand(); if (cmd.getId().startsWith(EmacsPlusUtils.MULGASOFT)) { console.printBold(bind.getTriggerSequence().toString()); console.print(SWT.TAB + cmd.getCommand().getName()); String desc = cmd.getCommand().getDescription(); if (desc != null) { desc = desc.replaceAll(CR, EMPTY_STR); console.print(" - " + desc + CR); //$NON-NLS-1$ } else { console.print(CR); } } } } catch (Exception e) { } console.setFocus(true); } return null; }
From source file:com.mulgasoft.emacsplus.commands.IndentForTabHandler.java
License:Open Source License
/** * Return the exact binding if it exists and is enabled, else null * //from www . j a va 2 s. c om * @param editor * @param keyCode * @param mode * @return binding if it exists and is enabled, else null */ private Binding getBinding(ITextEditor editor, char keyCode, int mode) { Binding result = null; // ensure key is upper case IBindingService bindingService = (IBindingService) editor.getSite().getService(IBindingService.class); KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(keyCode)); result = bindingService.getPerfectMatch(KeySequence.getInstance(key)); if (result != null && !result.getParameterizedCommand().getCommand().isEnabled()) { result = null; } return result; }
From source file:com.mulgasoft.emacsplus.commands.KbdMacroLoadHandler.java
License:Open Source License
/** * Load the macro from the File/*from w w w . ja v a2 s . c om*/ * If the macro was saved with its binding, then restore that as well * unless there is a conflict and the user decides against it * * @param editor * @param name - the kbd macro's name * @param file - the file where the keyboard macro resides */ private void loadMacro(ITextEditor editor, String name, File file, boolean forceIt) { try { FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); KbdMacro kbdMacro = (KbdMacro) ois.readObject(); ois.close(); String keyString = kbdMacro.getBindingKeys(); final KeySequence sequence = (keyString != null ? KeySequence.getInstance(keyString) : null); kbdMacro.setBindingKeys(null); // housekeeping: binding string is added on save String badCommand = null; if ((badCommand = checkMacro(editor, kbdMacro)) == null) { final Command command = defineKbdMacro(editor, name); // register loaded macro KbdMacroSupport.getInstance().nameKbdMacro(name, kbdMacro); // now see if we have a binding also if (sequence != null) { final String msg = String.format(LOADED_AND_BOUND, name, keyString); final Binding oldBinding = checkForBinding(editor, sequence); if (!forceIt && oldBinding != null) { // macro's binding is already present, ask for advice mbState = yesnoState(name, String.format(BINDING_QUESTION, keyString, FORMAT_S, FORMAT_S), new IKbdMacroOperation() { public void doOperation(ITextEditor editor, String name, File file) { bindMacro(editor, command, sequence, oldBinding); asyncShowMessage(editor, msg, false); } }); mbState.run(editor); } else { bindMacro(editor, command, sequence, oldBinding); asyncShowMessage(editor, msg, false); } } else { asyncShowMessage(editor, String.format(LOADED, name), false); } } else { asyncShowMessage(editor, String.format(BAD_CMD, badCommand), true); } } catch (Exception e) { String msg = e.getMessage(); asyncShowMessage(editor, String.format(ABORT_LOAD, name, (msg != null ? msg : e.toString())), true); } }