List of usage examples for org.eclipse.jface.bindings.keys SWTKeySupport convertAcceleratorToKeyStroke
public static final KeyStroke convertAcceleratorToKeyStroke(int accelerator)
From source file:com.aptana.ui.keybinding.KeyBindingHelper.java
License:Open Source License
public static boolean isKeyEventComplete(Event event) { // Is this a complete KeyStroke return SWTKeySupport.convertAcceleratorToKeyStroke(SWTKeySupport.convertEventToUnmodifiedAccelerator(event)) .isComplete();// w ww. j a v a 2 s .c o m }
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// w w w. j a v a 2 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.mousefeed.eclipse.ActionActionDescGenerator.java
License:Open Source License
/** * Converts the provided key combination code to accelerator. * // w w w . ja va2 s .c o m * @param accelerator * The accelerator to convert; should be a valid SWT accelerator * value. * @return The equivalent key stroke; never <code>null</code>. */ private String keyToStr(final int accelerator) { return SWTKeySupport.convertAcceleratorToKeyStroke(accelerator).format(); }
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:de.walware.ecommons.ui.dialogs.QuickTreeInformationControl.java
License:Open Source License
private void initIterateKeys() { if (this.commandId == null || this.iterationCount == 1) { return;/*from w w w.jav a 2 s . c om*/ } final IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench() .getService(IBindingService.class); if (bindingSvc == null) { return; } { final TriggerSequence sequence = bindingSvc.getBestActiveBindingFor(this.commandId); final KeyStroke keyStroke = getKeyStroke(sequence); if (keyStroke == null) { return; } this.commandBestKeyStrokeFormatted = keyStroke.format(); } { final TriggerSequence[] sequences = bindingSvc.getActiveBindingsFor(this.commandId); this.commandActiveKeyStrokes = new ArrayList<KeyStroke>(sequences.length); for (int i = 0; i < sequences.length; i++) { final KeyStroke keyStroke = getKeyStroke(sequences[i]); if (keyStroke != null) { this.commandActiveKeyStrokes.add(keyStroke); } } } this.commandKeyListener = new KeyAdapter() { @Override public void keyPressed(final KeyEvent event) { final KeyStroke keyStroke = SWTKeySupport .convertAcceleratorToKeyStroke(SWTKeySupport.convertEventToUnmodifiedAccelerator(event)); for (final KeyStroke activeKeyStroke : QuickTreeInformationControl.this.commandActiveKeyStrokes) { if (activeKeyStroke.equals(keyStroke)) { event.doit = false; iterate(); return; } } } }; }
From source file:eu.esdihumboldt.hale.ui.functions.groovy.GroovyScriptPage.java
License:Open Source License
@Override protected void addActions(ToolBar toolbar, final CompilingSourceViewer<GroovyAST> viewer) { super.addActions(toolbar, viewer); // GroovyASTTray.createToolItem(toolbar, this, viewer); try {/*from w w w. j a v a 2 s . c o m*/ final TriggerSequence astTrigger = KeySequence.getInstance("F8"); viewer.appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (astTrigger.equals(sequence)) { GroovyASTTray.showTray(GroovyScriptPage.this, viewer); event.doit = false; } } }); } catch (Exception e) { log.error("Error installing AST view listener", e); } }
From source file:eu.esdihumboldt.hale.ui.util.source.SourceViewerKeyBindings.java
License:Open Source License
/** * Install the ability to delete a line through <code>CTRL+D</code> on a * text viewer./* www .j a v a 2 s . co m*/ * * @param viewer the text viewer */ public static void installDeleteLine(final TextViewer viewer) { try { final TriggerSequence trigger = KeySequence.getInstance("CTRL+D"); viewer.appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (trigger.equals(sequence)) { // determine the current selection int startOffset; int endOffset; Point sel = viewer.getTextWidget().getSelectionRange(); if (sel != null) { startOffset = sel.x; endOffset = startOffset + sel.y; } else { startOffset = viewer.getTextWidget().getCaretOffset(); endOffset = startOffset; } try { // determine the involved lines IDocument doc = viewer.getDocument(); int startLine = doc.getLineOfOffset(startOffset); int endLine = doc.getLineOfOffset(endOffset); // derive start and end offset startOffset = doc.getLineOffset(startLine); if (startLine != endLine) { // delete multiple lines endOffset = doc.getLineOffset(endLine) + doc.getLineLength(endLine); } else { // delete one line endOffset = startOffset + doc.getLineLength(endLine); } // delete the line doc.replace(startOffset, endOffset - startOffset, ""); event.doit = false; } catch (Exception e) { log.warn("Failed to delete line in document", e); } } } }); } catch (ParseException e) { log.error("Failed to install delete line listener on source viewer", e); } }
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.//ww w . j a va 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:eu.esdihumboldt.hale.ui.util.source.TextViewerOperationSupport.java
License:Open Source License
/** * Adds support for the given operations to be triggered through a key * sequence to a text viewer.// w w w. j av a 2s .c o m * * @param viewer the text viewer * @param operations key sequences mapped to operations */ public static void install(final TextViewer viewer, final Map<TriggerSequence, Integer> operations) { viewer.appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); Integer op = operations.get(sequence); if (op != null) { if (viewer.canDoOperation(op)) { e.doit = false; viewer.doOperation(op); } } } }); }
From source file:io.usethesource.impulse.editor.OutlineInformationControl.java
License:Open Source License
private KeyAdapter getKeyAdapter() { if (fKeyAdapter == null) { fKeyAdapter = new KeyAdapter() { public void keyPressed(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); KeyStroke[] strokes = keySequence.getKeyStrokes(); for (int i = 0; i < strokes.length; i++) { // HACK Hard-wired code for detecting Ctrl-O... if ((strokes[i].getModifierKeys() & SWT.CTRL) != 0 && strokes[i].getNaturalKey() == 'O') { e.doit = false;// w w w. j a v a2s .c o m toggleShowInheritedMembers(); return; } } // KeySequence[] sequences= new KeySequence[0]; // getInvokingCommandKeySequences(); // RMF 6/1/2006 - disabled since impl used deprecated API // if (sequences == null) // return; // for(int i= 0; i < sequences.length; i++) { // if (sequences[i].equals(keySequence)) { // e.doit= false; // toggleShowInheritedMembers(); // return; // } // } } }; } return fKeyAdapter; }