List of usage examples for org.eclipse.jface.bindings.keys KeySequence equals
@Override
public final boolean equals(final Object object)
From source file:com.aptana.editor.common.internal.scripting.CommandElementsProvider.java
License:Open Source License
public List<CommandElement> getCommandElements(KeySequence keySequence) { List<CommandElement> commandElements = new LinkedList<CommandElement>(); int caretOffset = TextEditorUtils.getCaretOffset(textEditor); try {// w w w .j a va 2 s .c o m String contentTypeAtOffset = CommonEditorPlugin.getDefault().getDocumentScopeManager() .getScopeAtOffset(textViewer, caretOffset); IModelFilter filter = new ScopeFilter(contentTypeAtOffset); List<CommandElement> commandsFromScope = BundleManager.getInstance().getExecutableCommands(filter); for (CommandElement commandElement : commandsFromScope) { if (commandElement instanceof SnippetElement) { continue; } KeySequence[] commandElementKeySequences = KeyBindingUtil.getKeySequences(commandElement); for (KeySequence commandElementKeySequence : commandElementKeySequences) { if (keySequence.equals(commandElementKeySequence)) { commandElements.add(commandElement); break; } } } } catch (BadLocationException e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } return commandElements; }
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") private void createDefinitionArea(Composite parent) { final Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.command2")); //$NON-NLS-1$ nameField = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY); nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.description")); //$NON-NLS-1$ descriptionField = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP); GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); layoutData.heightHint = 50;//from w w w . ja v a 2s .c o m descriptionField.setLayoutData(layoutData); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.key_sequence")); //$NON-NLS-1$ Composite keyGroup = new Composite(composite, SWT.NONE); keyGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; keyGroup.setLayout(layout); keyField = new Text(keyGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); keyField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); keySequenceField = new KeySequenceText(keyField); keySequenceField.setKeyStrokeLimit(2); keySequenceField.addPropertyChangeListener(new IPropertyChangeListener() { public final void propertyChange(final PropertyChangeEvent event) { if (!event.getOldValue().equals(event.getNewValue())) { final KeySequence keySequence = keySequenceField.getKeySequence(); if (selectedCommand == null || !keySequence.isComplete()) return; boolean empty = keySequence.isEmpty(); Binding newBinding; Binding b = commandMap.get(selectedCommand.getId()); if (b != null) { if (!keySequence.equals(b.getTriggerSequence())) { newBinding = new KeyBinding(keySequence, empty ? null : b.getParameterizedCommand(), activeSchemeId, b.getContextId(), null, null, null, Binding.USER); userMap.remove(b.getTriggerSequence()); userMap.put(keySequence, newBinding); if (empty) commandMap.remove(selectedCommand.getId()); else commandMap.put(selectedCommand.getId(), newBinding); } } else if (!empty) { ParameterizedCommand pc = new ParameterizedCommand(selectedCommand, null); newBinding = new KeyBinding(keySequence, pc, activeSchemeId, "org.eclipse.ui.contexts.window", //$NON-NLS-1$ null, null, null, Binding.USER); userMap.put(keySequence, newBinding); commandMap.put(selectedCommand.getId(), newBinding); } refreshViewer(); doValidate(); keyField.setSelection(keyField.getTextLimit()); } } }); final Button helpButton = new Button(keyGroup, SWT.ARROW | SWT.LEFT); helpButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); helpButton.setToolTipText(Messages.getString("KeyPreferencePage.add_a_special_key")); //$NON-NLS-1$ // Arrow buttons aren't normally added to the tab list. Let's fix that. final Control[] tabStops = keyGroup.getTabList(); final ArrayList<Control> newTabStops = new ArrayList<Control>(); for (int i = 0; i < tabStops.length; i++) { Control tabStop = tabStops[i]; newTabStops.add(tabStop); if (keyField.equals(tabStop)) newTabStops.add(helpButton); } keyGroup.setTabList(newTabStops.toArray(new Control[newTabStops.size()])); // Construct the menu to attach to the above button. final Menu addKeyMenu = new Menu(helpButton); final Iterator<?> trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator(); while (trappedKeyItr.hasNext()) { final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next(); final MenuItem menuItem = new MenuItem(addKeyMenu, SWT.PUSH); menuItem.setText(trappedKey.format()); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { keySequenceField.insert(trappedKey); keyField.setFocus(); keyField.setSelection(keyField.getTextLimit()); } }); } helpButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent selectionEvent) { Point buttonLocation = helpButton.getLocation(); buttonLocation = composite.toDisplay(buttonLocation.x, buttonLocation.y); Point buttonSize = helpButton.getSize(); addKeyMenu.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y); addKeyMenu.setVisible(true); } }); new Label(composite, SWT.NONE); userLabel = new Label(composite, SWT.NONE); userLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); }
From source file:de.xirp.ui.widgets.dialogs.preferences.HotkeysFolder.java
License:Open Source License
/** * Tests if the given key is already used for an other command. * /*ww w . ja v a 2 s . c om*/ * @param command * the actual command to check. * @param seq * the key to check. * @return <code>true</code> if the given key is free to be used * by the given command. */ private boolean isFree(CommandDefinition command, KeySequence seq) { if (seq.toString().equalsIgnoreCase(FORMAL_EMPTY_KEY)) { return true; } KeySequence old = keyMappings.get(command); if (old != null && old.equals(seq)) { return true; } else { return !keyMappings.values().contains(seq); } }
From source file:eu.esdihumboldt.hale.ui.util.source.SourceViewerUndoSupport.java
License:Open Source License
/** * Adds undo support to the given source viewer. Should only be called if * for this viewer the undo/redo support is not provided through the * workbench./*from w w w .ja v a 2 s . c o m*/ * * @param viewer the source viewer */ public static void install(final SourceViewer viewer) { IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); TriggerSequence undo = null; TriggerSequence redo = null; if (bs != null) { undo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_UNDO); redo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_REDO); /* * Note: Curiously this need not be the same as what is displayed in * the main menu. When testing on Linux, CTRL+SHIT+Z was the binding * in the main menu, but here CTRL+Y was returned. */ } try { // fall-back bindings if (undo == null) { undo = KeySequence.getInstance("M1+Z"); } if (redo == null) { redo = KeySequence.getInstance("M1+Y"); } final TriggerSequence undoSeq = undo; final TriggerSequence redoSeq = redo; viewer.getTextWidget().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (sequence.equals(undoSeq)) { IUndoManager um = viewer.getUndoManager(); if (um.undoable()) { um.undo(); } } else if (sequence.equals(redoSeq)) { IUndoManager um = viewer.getUndoManager(); if (um.redoable()) { um.redo(); } } } }); } catch (ParseException e) { log.error("Could not created key sequences for source viewer undo/redo support", e); } }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
/** * <p>/*from w w w. j a va 2 s. com*/ * Tests whether the preference store will be read automatically when a * change to the preference store is made. * </p> * * @throws ParseException * If "ALT+SHIFT+Q A" cannot be parsed by KeySequence. */ public final void testAutoLoad() throws ParseException { // Get the services. ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); bindingService.readRegistryAndPreferences(commandService); // Check the pre-conditions. final String emacsSchemeId = EMACS_SCHEME_ID; assertFalse("The active scheme should be Emacs yet", emacsSchemeId.equals(bindingService.getActiveScheme().getId())); final KeySequence formalKeySequence = KeySequence.getInstance("ALT+SHIFT+Q A"); final String commandId = "org.eclipse.ui.views.showView"; Binding[] bindings = bindingService.getBindings(); int i; for (i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ((binding.getType() == Binding.USER) && (formalKeySequence.equals(binding.getTriggerSequence()))) { final ParameterizedCommand command = binding.getParameterizedCommand(); final String actualCommandId = (command == null) ? null : command.getCommand().getId(); assertFalse("The command should not yet be bound", commandId.equals(actualCommandId)); break; } } assertEquals("There shouldn't be a matching command yet", bindings.length, i); // Modify the preference store. final IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); store.setValue("org.eclipse.ui.commands", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.ui.commands><activeKeyConfiguration keyConfigurationId=\"" + emacsSchemeId + "\"/><keyBinding commandId=\"" + commandId + "\" contextId=\"org.eclipse.ui.contexts.window\" keyConfigurationId=\"org.eclipse.ui.defaultAcceleratorConfiguration\" keySequence=\"" + formalKeySequence + "\"/></org.eclipse.ui.commands>"); // Check that the values have changed. assertEquals("The active scheme should now be Emacs", emacsSchemeId, bindingService.getActiveScheme().getId()); bindings = bindingService.getBindings(); for (i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ((binding.getType() == Binding.USER) && (formalKeySequence.equals(binding.getTriggerSequence()))) { final ParameterizedCommand command = binding.getParameterizedCommand(); final String actualCommandId = (command == null) ? null : command.getCommand().getId(); assertEquals("The command should be bound to 'ALT+SHIFT+Q A'", commandId, actualCommandId); break; } } assertFalse("There should be a matching command now", (bindings.length == i)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
public final void testSinglePlatform() throws Exception { // Get the services. ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand about = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.help.aboutAction"), null); KeySequence m18A = KeySequence.getInstance("M1+8 A"); KeySequence m18B = KeySequence.getInstance("M1+8 B"); int numAboutBindings = 0; Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() == Binding.SYSTEM) { String platform = binding.getPlatform(); int idx = (platform == null ? -1 : platform.indexOf(',')); assertEquals(binding.toString(), -1, idx); if (about.equals(binding.getParameterizedCommand())) { if (m18A.equals(binding.getTriggerSequence())) { numAboutBindings++;//from w w w .java 2 s.c om assertNull("M+8 A", binding.getPlatform()); } else if (m18B.equals(binding.getTriggerSequence())) { numAboutBindings++; // assertEquals(Util.WS_CARBON, binding.getPlatform()); // temp work around for honouring carbon bindings assertTrue("failure for platform: " + binding.getPlatform(), Util.WS_CARBON.equals(binding.getPlatform()) || Util.WS_COCOA.equals(binding.getPlatform())); } } } } if (Util.WS_CARBON.equals(SWT.getPlatform()) || Util.WS_COCOA.equals(SWT.getPlatform())) { assertEquals(2, numAboutBindings); } else { assertEquals(1, numAboutBindings); } }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
public final void testBindingTransform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand addWS = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null); KeySequence m18w = KeySequence.getInstance("M1+8 W"); KeySequence m28w = KeySequence.getInstance("M2+8 W"); boolean foundDeleteMarker = false; int numOfMarkers = 0; Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() == Binding.SYSTEM) { String platform = binding.getPlatform(); int idx = (platform == null ? -1 : platform.indexOf(',')); assertEquals(binding.toString(), -1, idx); if (addWS.equals(binding.getParameterizedCommand())) { if (m18w.equals(binding.getTriggerSequence())) { numOfMarkers++;/*from w w w. j a v a 2 s. c o m*/ assertNull(m18w.format(), binding.getPlatform()); } else if (m28w.equals(binding.getTriggerSequence())) { numOfMarkers++; assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); } } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) { assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); numOfMarkers++; foundDeleteMarker = true; } } } assertEquals(3, numOfMarkers); assertTrue("Unable to find delete marker", foundDeleteMarker); TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS); assertEquals(1, activeBindingsFor.length); }
From source file:org.eclipse.rcptt.tesla.recording.core.swt.rap.SWTAssertManager.java
License:Open Source License
public boolean isShortcutRequest(Event e, String[] shortcuts) { if (shortcuts == null) { return false; }/*from ww w . ja va2s. c o m*/ int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (shortcuts != null) { for (String formatted : shortcuts) { try { KeySequence shortcut = KeySequence.getInstance(formatted); if (sequence.equals(shortcut)) { return true; } } catch (ParseException e1) { TeslaCore.log("Invalid shortcut: " + formatted); } } } return false; }
From source file:org.eclipse.rcptt.ui.panels.main.ControlPanelWindow.java
License:Open Source License
private void handleStopRecordShortcutPressed(KeySequence sequence) { TriggerSequence[] shortcuts = RecordingContextManager.Instance.getStopRecordShortcuts(); if (shortcuts != null) { for (TriggerSequence s : shortcuts) { if (sequence.equals(s)) { recordingSupport.setMode(RecordingMode.Stopped); }/*from w ww. j a v a2s. co m*/ } } }
From source file:org.eclipse.rcptt.ui.recording.UiNetworkRecorder.java
License:Open Source License
private boolean isShortcutsRequest(Type command, TriggerSequence[] shortcuts) { Event e = new Event(); e.character = command.getCharacter(); e.keyCode = command.getCode();// w ww. j av a2s . c om e.stateMask = command.getState(); int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (assertModeShortcuts != null) { for (TriggerSequence s : shortcuts) { if (sequence.equals(s)) { return true; } } } return false; }