org.eclipse.jface.bindings.TriggerSequence Java Examples
The following examples show how to use
org.eclipse.jface.bindings.TriggerSequence.
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: KeysPreferencePage.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public String getColumnText(Object element, int index) { BindingElement bindingElement = ((BindingElement) element); switch (index) { case COMMAND_NAME_COLUMN: {// name String name = bindingElement.getName(); if (name != null && name.endsWith("()")) { name = name.substring(0, name.length() - 2); } return name; } case KEY_SEQUENCE_COLUMN: // keys TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); case CATEGORY_COLUMN: // category String id = bindingElement.getId(); if (id.equalsIgnoreCase("net.heartsome.cat.ts.command.preference")) { return Messages.getString("preferencepage.KeysPreferencePage.toolCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.lockToolBar")) { return Messages.getString("preferencepage.KeysPreferencePage.toolbarCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.showKeyAssist")) { return Messages.getString("preferencepage.KeysPreferencePage.helpCategory"); } return bindingElement.getCategory(); } return null; }
Example #2
Source File: KeyBindingHelper.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId) { final IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench() .getAdapter(IBindingService.class); TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId); for (TriggerSequence seq : activeBindingsFor) { if (seq instanceof KeySequence) { if (matchesKeybinding(keyCode, stateMask, seq)) { return true; } } } return false; }
Example #3
Source File: KeyBindingHelper.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private static boolean internalMatchesKeybinding(int keyCode, int stateMask, TriggerSequence seq) { KeySequence keySequence = (KeySequence) seq; KeyStroke[] keyStrokes = keySequence.getKeyStrokes(); if (keyStrokes.length > 1) { return false; // Only handling one step binding... the code below does not support things as "CTRL+X R" for // redo. } for (KeyStroke keyStroke : keyStrokes) { if (keyStroke.getNaturalKey() == keyCode && keyStroke.getModifierKeys() == stateMask) { return true; } } return false; }
Example #4
Source File: KeyBindingHelper.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId) { final IBindingService bindingSvc = PlatformUI.getWorkbench() .getAdapter(IBindingService.class); TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId); for (TriggerSequence seq : activeBindingsFor) { if (seq instanceof KeySequence) { KeySequence keySequence = (KeySequence) seq; if (matchesKeybinding(keyCode, stateMask, keySequence)) { return true; } } } return false; }
Example #5
Source File: KeysPreferencePage.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public String getColumnText(Object element, int index) { BindingElement bindingElement = ((BindingElement) element); switch (index) { case COMMAND_NAME_COLUMN: {// name String name = bindingElement.getName(); if (name != null && name.endsWith("()")) { name = name.substring(0, name.length() - 2); } return name; } case KEY_SEQUENCE_COLUMN: // keys TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); case CATEGORY_COLUMN: // category String id = bindingElement.getId(); if (id.equalsIgnoreCase("net.heartsome.cat.ts.command.preference")) { return Messages.getString("preferencepage.KeysPreferencePage.toolCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.lockToolBar")) { return Messages.getString("preferencepage.KeysPreferencePage.toolbarCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.showKeyAssist")) { return Messages.getString("preferencepage.KeysPreferencePage.helpCategory"); } return bindingElement.getCategory(); } return null; }
Example #6
Source File: CommandHelp.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Get the displayable key-binding information for the parameterized command * * @param com the command * @param activep - if true, return only active bindings * * @return a String array of binding sequence binding context information */ public static String[] getKeyBindingStrings(ParameterizedCommand com, boolean activep) { TriggerSequence trigger; // Get platform bindings for the ParameterizedCommand's Command Binding[] bindings = getBindings(com.getCommand(),activep); List<String> bindingInfo = new ArrayList<String>(); ParameterizedCommand c; for (Binding bind : bindings) { c = bind.getParameterizedCommand(); if (c != null && c.equals(com)) { trigger = bind.getTriggerSequence(); bindingInfo.add(trigger.toString()); bindingInfo.add(bind.getContextId()); } } return bindingInfo.toArray(new String[0]); }
Example #7
Source File: CommandHelp.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Get the displayable key-binding information for the command * * @param com - the command * @param activep - if true, return only active bindings * * @return a String array of binding sequence binding context information */ public static String[] getKeyBindingStrings(Command com, boolean activep) { String id = com.getId(); TriggerSequence trigger; // Get platform bindings for Command Binding[] bindings = getBindings(com,activep); List<String> bindingInfo = new ArrayList<String>(); ParameterizedCommand c; for (Binding bind : bindings) { c = bind.getParameterizedCommand(); if (c != null && c.getId().equals(id)) { trigger = bind.getTriggerSequence(); bindingInfo.add(trigger.toString()); bindingInfo.add(bind.getContextId()); } } return bindingInfo.toArray(new String[0]); }
Example #8
Source File: CodeAssistAdvancedConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static String getKeyboardShortcut(ParameterizedCommand command) { IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); fgLocalBindingManager.setBindings(bindingService.getBindings()); try { Scheme activeScheme= bindingService.getActiveScheme(); if (activeScheme != null) fgLocalBindingManager.setActiveScheme(activeScheme); } catch (NotDefinedException e) { JavaPlugin.log(e); } TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command); if (bindings.length > 0) return bindings[0].format(); return null; }
Example #9
Source File: KeysPreferencePage.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public String getColumnText(Object element, int index) { BindingElement bindingElement = ((BindingElement) element); switch (index) { case COMMAND_NAME_COLUMN: {// name String name = bindingElement.getName(); if (name != null && name.endsWith("()")) { name = name.substring(0, name.length() - 2); } return name; } case KEY_SEQUENCE_COLUMN: // keys TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); case CATEGORY_COLUMN: // category String id = bindingElement.getId(); if (id.equalsIgnoreCase("net.heartsome.cat.ts.command.preference")) { return Messages.getString("preferencepage.KeysPreferencePage.toolCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.lockToolBar")) { return Messages.getString("preferencepage.KeysPreferencePage.toolbarCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.showKeyAssist")) { return Messages.getString("preferencepage.KeysPreferencePage.helpCategory"); } return bindingElement.getCategory(); } return null; }
Example #10
Source File: EmacsMovementHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Does the trigger for this movement command contain the SHIFT key? * * Enforce that the <binding> and <binding>+SHIFT belong to the same Command. * If not, don't apply shift selection (if enabled) for this command (i.e. return false). * * @param event the Execution event that invoked this command * * @return true if SHIFT modifier was set, else false */ private boolean getShifted(ExecutionEvent event) { // NB: only single keystroke commands are valid boolean result = false; Object trigger = event.getTrigger(); Event e = null; if (trigger != null && trigger instanceof Event && ((e = (Event)trigger).stateMask & SWT.SHIFT )!= 0) { String cmdId = event.getCommand().getId(); int mask = (e.stateMask & SWT.MODIFIER_MASK) ^ SWT.SHIFT; int u_code = Character.toUpperCase((char)e.keyCode); IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); if (cmdId != null && bs != null) { TriggerSequence[] sequences = bs.getActiveBindingsFor(cmdId); for (TriggerSequence s : sequences) { if (s instanceof KeySequence) { KeyStroke[] strokes = ((KeySequence)s).getKeyStrokes(); if (strokes.length == 1) { KeyStroke k = strokes[strokes.length - 1]; // if keyCode is alpha, then we test uppercase, else keyCode if (k.getModifierKeys() == mask && (k.getNaturalKey() == u_code || k.getNaturalKey() == e.keyCode)) { result = true; break; } } } } } } return result; }
Example #11
Source File: AbstractMenuContributionItem.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void appendShortcut(ParameterizedCommand parameterizedCommand, MenuItem item) { TriggerSequence triggerSequence = eBindingService.getBestSequenceFor(parameterizedCommand); if (triggerSequence != null && triggerSequence instanceof KeySequence) { KeySequence keySequence = (KeySequence) triggerSequence; String rawLabel = item.getText(); item.setText(String.format("%s %s%s", rawLabel, '\t', keySequence.format())); } }
Example #12
Source File: EmacsHelpHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { EmacsPlusConsole console = EmacsPlusConsole.getInstance(); console.clear(); 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; }
Example #13
Source File: EmacsPlusUtils.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Return the context free set of key bindings * * @return A map of trigger (<code>TriggerSequence</code>) to bindings ( * <code>Collection</code> containing <code>Binding</code>). * or an empty map */ public static Map<TriggerSequence,Collection<Binding>> getTotalBindings() { Map<TriggerSequence,Collection<Binding>> result = Collections.emptyMap(); BindingService bs = getBindingService(); if (bs != null) { @SuppressWarnings("unchecked") // @see org.eclipse.jface.bindings.BindingManager#getActiveBindingsDisregardingContext() Map<TriggerSequence,Collection<Binding>> bindings = getBindingManager(bs).getActiveBindingsDisregardingContext(); result = bindings; } return result; }
Example #14
Source File: EmacsPlusUtils.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") public static Map<TriggerSequence,Binding> getPartialMatches(IBindingService ibs, KeySequence ks) { // juno e4 code was hosed, so temporarily use a different path to the results we need // return getBindingManager(((ibs instanceof BindingService) ? (BindingService)ibs : getBindingService())).getPartialMatches(ks); // original version is supposed to be fixed in Kepler+ - not sure I trust it return ibs.getPartialMatches(ks); }
Example #15
Source File: CommandHelp.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Get the best binding (as determined by Eclipse) for the Command * * @param cmd * @return the binding or null */ public static String getBestBinding(Command cmd) { String result = null; IBindingService binder = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); TriggerSequence bindingFor = binder.getBestActiveBindingFor(cmd.getId()); if (bindingFor != null) { result = bindingFor.format(); } return result; }
Example #16
Source File: WindowDeclOtherCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * A bit of hackery that tries to get the correct open-declaration command for the buffer * @param editor * @return the best match Command definition */ private Command getOpenCmd(IEditorPart editor) { Command result = null; try { IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class); List<Command> cans = new ArrayList<Command>(); List<Command> nocans = new ArrayList<Command>(); Command[] commands = ics.getDefinedCommands(); for (Command c : commands) { if (OD.equals(c.getName()) && c.isEnabled()) { TriggerSequence[] b = bs.getActiveBindingsFor(c.getId()); if (b.length > 0) { cans.add(c); } else { nocans.add(c); } } } // TODO: when > 1 try to refine the result heuristically? // if Eclipse returned more than one, then chose a bound command over non-bound if (cans.isEmpty()) { if (!nocans.isEmpty()) { // just grab first one result = nocans.get(0); } } else { // grab the first bound one result = cans.get(0); } } catch (Exception e) { } return result; }
Example #17
Source File: KeyBindingHelper.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @param commandId the command we want to know about * @return the 'best' key sequence that will activate the given command */ public static KeySequence getCommandKeyBinding(String commandId) { Assert.isNotNull(commandId); IBindingService bindingSvc; try { bindingSvc = PlatformUI.getWorkbench() .getAdapter(IBindingService.class); } catch (IllegalStateException e) { return null; } TriggerSequence keyBinding = bindingSvc.getBestActiveBindingFor(commandId); if (keyBinding instanceof KeySequence) { return (KeySequence) keyBinding; } List<Tuple<Binding, ParameterizedCommand>> matches = new ArrayList<Tuple<Binding, ParameterizedCommand>>(); //Ok, it may be that the binding we're looking for is not active, so, let's give a spin on all //the bindings Binding[] bindings = bindingSvc.getBindings(); for (Binding binding : bindings) { ParameterizedCommand command = binding.getParameterizedCommand(); if (command != null) { if (commandId.equals(command.getId())) { matches.add(new Tuple<Binding, ParameterizedCommand>(binding, command)); } } } for (Tuple<Binding, ParameterizedCommand> tuple : matches) { if (tuple.o1.getTriggerSequence() instanceof KeySequence) { KeySequence keySequence = (KeySequence) tuple.o1.getTriggerSequence(); return keySequence; } } return null; }
Example #18
Source File: LangContentAssistProcessor.java From goclipse with Eclipse Public License 1.0 | 5 votes |
protected String createIterationMessage() { TriggerSequence binding = getGroupingIterationBinding(); String nextCategoryLabel = getCategory(invocationIteration + 1).getName(); if(binding == null) { return MessageFormat.format(LangUIMessages.ContentAssistProcessor_toggle_affordance_click_gesture, getCurrentCategory().getName(), nextCategoryLabel, null); } else { return MessageFormat.format(LangUIMessages.ContentAssistProcessor_toggle_affordance_press_gesture, getCurrentCategory().getName(), nextCategoryLabel, binding.format()); } }
Example #19
Source File: LangContentAssistProcessor.java From goclipse with Eclipse Public License 1.0 | 5 votes |
protected KeySequence getGroupingIterationBinding() { IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); TriggerSequence binding = bindingSvc.getBestActiveBindingFor( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); if(binding instanceof KeySequence) return (KeySequence) binding; return null; }
Example #20
Source File: WorkspaceWizardPage.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Returns the active key binding for content assist. * * If no binding is set null is returned. */ private KeyStroke getActiveContentAssistBinding() { IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class); TriggerSequence[] activeBindingsFor = bindingService .getActiveBindingsFor(CONTENT_ASSIST_ECLIPSE_COMMAND_ID); if (activeBindingsFor.length > 0 && activeBindingsFor[0] instanceof KeySequence) { KeyStroke[] strokes = ((KeySequence) activeBindingsFor[0]).getKeyStrokes(); if (strokes.length == 1) { return strokes[0]; } } return null; }
Example #21
Source File: KbdMacroSaveHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private void saveMacro(ITextEditor editor,String name, File file) { IBindingService service = (IBindingService) editor.getSite().getService(IBindingService.class); KbdMacro kbdMacro = KbdMacroSupport.getInstance().getKbdMacro(name); TriggerSequence sequence = service.getBestActiveBindingFor(EmacsPlusUtils.kbdMacroId(name)); if (sequence != null && sequence instanceof KeySequence) { kbdMacro.setBindingKeys(((KeySequence)sequence).toString()); } writeMacro(editor,file,kbdMacro); kbdMacro.setBindingKeys(null); }
Example #22
Source File: KeysPreferencePage.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override protected Object getValue(Object element) { // System.out.println(element); BindingElement bindingElement = ((BindingElement) element); TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); }
Example #23
Source File: KeysPreferencePage.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override protected Object getValue(Object element) { // System.out.println(element); BindingElement bindingElement = ((BindingElement) element); TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); }
Example #24
Source File: KeysPreferencePage.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override protected Object getValue(Object element) { // System.out.println(element); BindingElement bindingElement = ((BindingElement) element); TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); }
Example #25
Source File: CorrectionCommandHandler.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static String getShortCutString(String proposalId) { if (proposalId != null) { IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); if (bindingService != null) { TriggerSequence[] activeBindingsFor= bindingService.getActiveBindingsFor(proposalId); if (activeBindingsFor.length > 0) { return activeBindingsFor[0].format(); } } } return null; }
Example #26
Source File: ContentAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private KeySequence getIterationBinding() { final IBindingService bindingSvc= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); TriggerSequence binding= bindingSvc.getBestActiveBindingFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); if (binding instanceof KeySequence) return (KeySequence) binding; return null; }
Example #27
Source File: KeyBindingHelper.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public static boolean matchesKeybinding(int keyCode, int stateMask, TriggerSequence seq) { int upperCase = Character.toUpperCase(keyCode); if (upperCase == keyCode) { return internalMatchesKeybinding(keyCode, stateMask, seq); } else { // try both: upper and lower case. return internalMatchesKeybinding(upperCase, stateMask, seq) || internalMatchesKeybinding(keyCode, stateMask, seq); } }
Example #28
Source File: FindBarActions.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private void updateTooltip(String commandId, String tooltip, ToolItem item) { List<TriggerSequence> bindings = fCommandToBinding.get(commandId); if (bindings != null && bindings.size() > 0) { item.setToolTipText(MessageFormat.format("{0} ({1})", tooltip, bindings.get(0))); //$NON-NLS-1$ } else { item.setToolTipText(tooltip); } }
Example #29
Source File: TextFieldNavigationHandler.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TriggerSequence[] getTriggerSequences() { return fTriggerSequences; }
Example #30
Source File: TextFieldNavigationHandler.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public Submission(TriggerSequence[] triggerSequences) { fTriggerSequences= triggerSequences; }