List of usage examples for org.eclipse.jface.bindings.keys SWTKeySupport convertEventToUnmodifiedAccelerator
public static final int convertEventToUnmodifiedAccelerator(final KeyEvent event)
Converts the given event into an SWT accelerator value -- considering the unmodified character with all modifier keys.
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();/*from w w w. ja v a2s. co 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/*from w w w .j a va2 s. c o 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.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 . ja va 2 s . co m } 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 {// w ww . j av a2 s. c om 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./*from ww w . j a v a 2s . c o 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.//w ww . j av a 2s .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 ww. ja va 2 s . 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;/*from w w w . j a va 2s . 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; }
From source file:org.eclipse.babel.editor.widgets.suggestion.SuggestionBubble.java
License:Open Source License
private void init() { // Focus handling simulation for non-Windows systems if (!win) {//from ww w. j av a2 s. co m shell.getDisplay().addFilter(SWT.MouseDown, new Listener() { @Override public void handleEvent(Event event) { if (isCursorInsideTextField() && text.getText().length() == 0 && !isCreated() && text.isFocusControl()) { suggestionFilter.setSearchText(""); createDialog(); tableViewer.refresh(); } else { if (partialTranslationDialog != null) { if (!partialTranslationDialog.isCursorInsideDialog() && !isCursorInsideDialog()) { dispose(); } } else { if (!isCursorInsideDialog()) { dispose(); } } } } }); } // shell resize listener to dispose suggestion bubble shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { if (dialog != null && dialog.getShell() != null) { dialog.close(); } } }); // shell move listener shell.addListener(SWT.Move, new Listener() { public void handleEvent(Event e) { if (dialog != null && dialog.getShell() != null) { dialog.close(); } } }); // get ScrolledComposite ScrolledComposite scrolledComposite = (ScrolledComposite) text.getParent().getParent().getParent() .getParent(); // scroll listener scrolledComposite.getVerticalBar().addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { if (dialog != null && dialog.getShell() != null) { dialog.close(); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); // ModifyListener text.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { recalculatePosition(); if (dialog != null && dialog.getShell() != null && !tableViewer.getControl().isDisposed()) { suggestionFilter.setSearchText(text.getText().trim()); tableViewer.refresh(); if (tableViewer.getTable().getItemCount() == 0) { if (noSug == null || noSug.isDisposed()) { noSug = new Label(composite, SWT.NONE); noSug.setText("No suggestions available"); noSug.moveAbove(tableViewer.getControl()); noSug.setBackground(ResourceManager.getColor(255, 255, 225)); composite.layout(); } } else { if (noSug != null && !noSug.isDisposed()) { tableViewer.getTable().setSelection(0); noSug.dispose(); composite.layout(); } } suggestionFilter.setSearchText(""); } } }); // KeyListener text.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { if ((e.keyCode == SWT.CR || e.keyCode == SWT.LF) && (dialog != null && dialog.getShell() != null) && tableViewer.getTable().getSelectionIndex() != -1) { e.doit = false; } int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeyStroke keyStroke = SWTKeySupport.convertAcceleratorToKeyStroke(accelerator); KeySequence sequence = KeySequence.getInstance(keyStroke); if (sequence.format().equals(CONTENT_ASSIST)) { if (isCreated()) { if (noSug != null && !noSug.isDisposed()) { noSug.dispose(); composite.layout(); } suggestionFilter.setSearchText(""); tableViewer.refresh(); tableViewer.getTable().setSelection(0); } else { createDialog(); suggestionFilter.setSearchText(text.getText().trim()); tableViewer.refresh(); } e.doit = false; } } @Override public void keyReleased(KeyEvent e) { if (dialog == null || dialog.getShell() == null) { return; } if (e.keyCode == SWT.ESC) { dialog.close(); return; } // Changing selection with keyboard arrows and applying // translation with enter int currentSelectionIndex = tableViewer.getTable().getSelectionIndex(); if (e.keyCode == SWT.ARROW_DOWN) { if (currentSelectionIndex >= tableViewer.getTable().getItemCount() - 1) { tableViewer.getTable().setSelection(0); } else { tableViewer.getTable().setSelection(currentSelectionIndex + 1); } } if (e.keyCode == SWT.ARROW_UP) { if (currentSelectionIndex <= 0) { tableViewer.getTable().setSelection(tableViewer.getTable().getItemCount() - 1); } else { tableViewer.getTable().setSelection(currentSelectionIndex - 1); } } if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { applySuggestion(text); } } }); // FocusListener text.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { if (win && !isCreated() && text.getText().length() == 0) { suggestionFilter.setSearchText(""); createDialog(); tableViewer.refresh(); } } @Override public void focusLost(FocusEvent e) { if (win && dialog != null && !isCursorInsideDialog()) { dialog.close(); } } }); //MouseListener for Windows systems if (win) { text.addMouseListener(new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { // Nothing to do } @Override public void mouseDown(MouseEvent e) { // Nothing to do } @Override public void mouseUp(MouseEvent e) { if (caret != null) { if (dialog != null && !caret.equals(text.getCaretLocation())) { dialog.close(); caret = text.getCaretLocation(); } } else { caret = text.getCaretLocation(); } if (partialTranslationDialog != null && !partialTranslationDialog.isCursorInsideDialog()) { partialTranslationDialog.dispose(); } } }); } }