Java Code Examples for org.eclipse.jface.bindings.keys.KeyStroke#getInstance()
The following examples show how to use
org.eclipse.jface.bindings.keys.KeyStroke#getInstance() .
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: CommandDataDialog.java From EasyShell with Eclipse Public License 2.0 | 6 votes |
private ContentProposalAdapter addContentAssistSimple(Text textControl) { char[] autoActivationCharacters = new char[] { '$', '{' }; KeyStroke keyStroke = null; try { keyStroke = KeyStroke.getInstance("Ctrl+Space"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // assume that myTextControl has already been created in some way List<Variable> variables = Variable.getVisibleVariables(); String[] proposals = new String [variables.size()]; for(int i=0;i<variables.size();i++) { proposals[i] = variables.get(i).getFullVariableName(); } ContentProposalAdapter adapter = new ContentProposalAdapter( textControl , new TextContentAdapter(), new SimpleContentProposalProvider(proposals), keyStroke, autoActivationCharacters); adapter.setPropagateKeys(false); adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE); //adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); return adapter; }
Example 2
Source File: WithMinibuffer.java From e4macs with Eclipse Public License 1.0 | 6 votes |
protected boolean hasBinding(KeyEvent event, int mode) { boolean result = false; // ensure key is upper case KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(event.keyCode)); boolean isFilterDisabled = !getKeyFilter(); try { if (isFilterDisabled) { setKeyFilter(true); } result = bindingService.isPerfectMatch(KeySequence.getInstance(key)); } finally { if (isFilterDisabled) { setKeyFilter(false); } } return result; }
Example 3
Source File: KbdMacroSupport.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Check for a full command binding that was executed directly by the minibuffer * Remove the binding entry and add the command id entry * * @param binding */ void checkBinding(Binding binding) { boolean processed = false; int index = macro.size() -1; Event keyevent = macro.get(index).getEvent(); if (keyevent != null) { KeyStroke keyStroke = KeyStroke.getInstance(keyevent.stateMask, (int)Character.toUpperCase((char)keyevent.keyCode)); if (keyStroke.equals(binding.getTriggerSequence().getTriggers()[0])) { // remove (possibly partial) binding macro.remove(index); // flag for minibuffer exit addExit(); // and insert command macro.add(new KbdEvent(binding.getParameterizedCommand().getId())); processed = true; } } if (!processed) { // then it's a command unto itself (e.g. ARROW_RIGHT) // flag for minibuffer exit addExit(); // and insert command macro.add(new KbdEvent(binding.getParameterizedCommand().getId())); processed = true; } }
Example 4
Source File: KbdMacroSupport.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Check for a binding that is not a full command and was not handled by the minibuffer * Remove the partial binding and add the command id entry * * @param cmdId * @param trigger * @param onExit - it is the endMacro command, ignore id entry */ void checkTrigger(String cmdId, Map<?,?> parameters, Event trigger, boolean onExit) { int index = macro.size() -1; if (!macro.isEmpty() && trigger != null && macro.get(index).isSubCmd()) { Event event = macro.get(index).getEvent(); // have trigger and previous entry is a subCmd type KeyStroke key = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(event.keyCode)); IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); Collection<Binding> values = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values(); // Check partial binding for (Binding v : values) { if (cmdId.equals((v.getParameterizedCommand().getId()))) { // remove (possibly partial) binding macro.remove(index); // flag for minibuffer exit macro.add(new KbdEvent(true)); break; } } } if (!onExit) { macro.add(new KbdEvent(cmdId, parameters)); } }
Example 5
Source File: QuickOutlinePopup.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.2 */ public void setEvent(Event event) { this.invokingKeystrokeFormatted = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(SWTKeySupport.convertEventToUnmodifiedAccelerator(event))) .format(); this.invokingKeystroke = KeyStroke.getInstance(event.stateMask, event.keyCode); }
Example 6
Source File: NpmInstallWidget.java From typescript.java with MIT License | 5 votes |
private void addContentProposal(Text text) { char[] autoActivationCharacters = null;// new char[] { '.' }; KeyStroke keyStroke = null; try { keyStroke = KeyStroke.getInstance("Ctrl+Space"); } catch (ParseException e) { e.printStackTrace(); } adapter = new VersionContentProposalAdapter(text, new TextContentAdapter(), new VersionContentProposalProvider(), keyStroke, autoActivationCharacters); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); adapter.setPropagateKeys(true); adapter.setLabelProvider(VersionLabelProvider.getInstance()); }
Example 7
Source File: AbstractEditorPropertySection.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void enableXtext(Control styledText, Injector injector) { final StyledTextXtextAdapter xtextAdapter = new StyledTextXtextAdapter(injector); xtextAdapter.getFakeResourceContext().getFakeResource().eAdapters() .add(new ContextElementAdapter(getEObject())); xtextAdapter.adapt((StyledText) styledText, false); initContextMenu(styledText); completionProposalAdapter = new CompletionProposalAdapter(styledText, xtextAdapter.getContentAssistant(), KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null); form.getBody().setEnabled(isEditable()); }
Example 8
Source File: FieldAssistHelper.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param keyStroke * @param triggerKey * @return */ private KeyStroke getKeyStroke( String triggerKey ) { try { return KeyStroke.getInstance( triggerKey ); } catch ( Exception e ) // Catch all exceptions to avoid breaking UI. { return KeyStroke.getInstance( SWT.F10 ); } }
Example 9
Source File: IndentForTabHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Return the exact binding if it exists and is enabled, else null * * @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; }
Example 10
Source File: WithMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Based on the KeyEvent, get the perfect match binding * * @param event * @param checkEnabled if true, the command in the binding must be enabled * @return a binding that perfectly matches the KeyEvent, or null */ // TODO explain why always force ALT in normal case? private Binding getBinding(KeyEvent event, int mode, boolean checkEnabled) { Binding result = null; // ensure key is upper case KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(event.keyCode)); boolean isFilterDisabled = !getKeyFilter(); try { if (isFilterDisabled) { setKeyFilter(true); } // Shadowed commands shouldn't be enabled, but they are ... so protect // (e.g. C-x will perfect match and be enabled even though shadowed by C-x C-x) if (checkEnabled && bindingService.isPartialMatch(KeySequence.getInstance(key))) { result = null; } else { result = bindingService.getPerfectMatch(KeySequence.getInstance(key)); if (result != null && checkEnabled && !result.getParameterizedCommand().getCommand().isEnabled()) { result = null; } } } finally { if (isFilterDisabled) { setKeyFilter(false); } } return result; }
Example 11
Source File: ISearchMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Dynamically determine the bindings for forward and reverse i-search * For repeat search, Emacs treats i-search and i-search-regexp identically * * @param event * @return the FORWARD, REVERSE, or the source keyCode */ private int checkKeyCode(VerifyEvent event) { int result = event.keyCode; Integer val = keyHash.get(Integer.valueOf(event.keyCode + event.stateMask)); if (val == null) { KeyStroke keyst = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(result)); IBindingService bindingService = getBindingService(); Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyst)); if (binding != null) { if (ISF.equals(binding.getParameterizedCommand().getId())){ result = FORWARD; keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD)); } else if (ISB.equals(binding.getParameterizedCommand().getId())) { result = REVERSE; keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE)); } else if (ISRF.equals(binding.getParameterizedCommand().getId())) { result = FORWARD; keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD)); } else if (ISRB.equals(binding.getParameterizedCommand().getId())) { result = REVERSE; keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE)); } } } else { result = val; } return result; }
Example 12
Source File: KeyHandlerMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private KeyStroke getKey(int state, int keyCode,int character) { int result = keyCode; if (state ==0 && keys.size() == 0) { result = keyCode; } else if (state == SWT.SHIFT) { // handle characters with different shift values state = 0; result = character; } else { result = Character.toUpperCase(keyCode); } return KeyStroke.getInstance(state,result); }
Example 13
Source File: XtextStyledTextCellEditor.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected CompletionProposalAdapter createCompletionProposalAdapter(StyledText styledText, final IContentAssistant contentAssistant) { return new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null); }
Example 14
Source File: StyledTextXtextAdapter.java From statecharts with Eclipse Public License 1.0 | 4 votes |
public void adapt(StyledText styledText, boolean decorate) { this.styledText = styledText; // perform initialization of fake resource context updateFakeResourceContext(); // connect Xtext document to fake resource initXtextDocument(getFakeResourceContext()); // connect xtext document to xtext source viewer this.sourceviewer = createXtextSourceViewer(); this.decorationSupport = createSourceViewerDecorationSupport(); configureSourceViewerDecorationSupport(getDecorationSupport()); // install semantic highlighting support installHighlightingHelper(); this.validationJob = createValidationJob(); getXtextDocument().setValidationJob(getValidationJob()); styledText.setData(StyledTextXtextAdapter.class.getCanonicalName(), this); final IContentAssistant contentAssistant = getXtextSourceviewer().getContentAssistant(); final CompletionProposalAdapter completionProposalAdapter = new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null); if ((styledText.getStyle() & SWT.SINGLE) != 0) { // The regular key down event is too late (after popup is closed). // when using the StyledText.VerifyKey event (3005), we get the // event early enough! styledText.addListener(3005, new Listener() { @Override public void handleEvent(Event event) { if (event.character == SWT.CR && !completionProposalAdapter.isProposalPopupOpen()) { Event selectionEvent = new Event(); selectionEvent.type = SWT.DefaultSelection; selectionEvent.widget = event.widget; for (Listener l : event.widget.getListeners(SWT.DefaultSelection)) { l.handleEvent(selectionEvent); } } } }); } // Register focus tracker for evaluating the active focus control in // core expression IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); service.addFocusTracker(styledText, StyledText.class.getCanonicalName()); if (decorate) { // add JDT Style code completion hint decoration this.decoration = createContentAssistDecoration(styledText); } initSelectionProvider(); }
Example 15
Source File: GamaKeyBindings.java From gama with GNU General Public License v3.0 | 4 votes |
public PluggableBinding(final int modifiers, final int keyCode) { super(); this.key = KeyStroke.getInstance(modifiers, keyCode); }