Java Code Examples for com.intellij.openapi.actionSystem.AnActionEvent#getInputEvent()
The following examples show how to use
com.intellij.openapi.actionSystem.AnActionEvent#getInputEvent() .
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: PopupChoiceAction.java From StringManipulation with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent e) { super.update(e); Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); if (editor == null) { e.getPresentation().setEnabled(false); return; } Project project = getEventProject(e); if (project != null) { InputEvent inputEvent = e.getInputEvent(); boolean onlyAltDown = false; if (inputEvent != null) { onlyAltDown = inputEvent.isAltDown() && !inputEvent.isShiftDown() && !inputEvent.isMetaDown() && !inputEvent.isControlDown(); } LookupEx activeLookup = LookupManager.getInstance(project).getActiveLookup(); boolean dialogOpen = isFromDialog(project); boolean popupCheck = activeLookup == null || (activeLookup != null && !onlyAltDown); boolean dialogCheck = !dialogOpen || (dialogOpen && !onlyAltDown); e.getPresentation().setEnabled((popupCheck && dialogCheck)); } }
Example 2
Source File: PasteFromX11Action.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor == null || !SystemInfo.isXWindow) { presentation.setEnabled(false); } else { boolean rightPlace = true; final InputEvent inputEvent = e.getInputEvent(); if (inputEvent instanceof MouseEvent) { rightPlace = false; final MouseEvent me = (MouseEvent)inputEvent; if (editor.getMouseEventArea(me) == EditorMouseEventArea.EDITING_AREA) { final Component component = SwingUtilities.getDeepestComponentAt(me.getComponent(), me.getX(), me.getY()); rightPlace = !(component instanceof JScrollBar); } } presentation.setEnabled(rightPlace); } }
Example 3
Source File: KeyPromoter.java From IntelliJ-Key-Promoter-X with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void beforeActionPerformed(@NotNull AnAction action, @NotNull DataContext dataContext, AnActionEvent event) { final InputEvent input = event.getInputEvent(); if (input instanceof MouseEvent) { // The following is a hack to work around an issue with IDEA, where certain events arrive // twice. See https://youtrack.jetbrains.com/issue/IDEA-219133 if (input.getWhen() != 0 && lastEventTime == input.getWhen()) { return; } lastEventTime = input.getWhen(); final String place = event.getPlace(); KeyPromoterAction kpAction; if ("MainMenu".equals(place)) { if (keyPromoterSettings.isMenusEnabled()) { kpAction = new KeyPromoterAction(action, event, KeyPromoterAction.ActionSource.MENU_ENTRY); showTip(kpAction); } } else if ("MainToolbar".equals(place)) { if (keyPromoterSettings.isToolbarButtonsEnabled()) { kpAction = new KeyPromoterAction(action, event, KeyPromoterAction.ActionSource.MAIN_TOOLBAR); showTip(kpAction); } } else if (place.matches(".*Popup")) { if (keyPromoterSettings.isEditorPopupEnabled()) { kpAction = new KeyPromoterAction(action, event, KeyPromoterAction.ActionSource.POPUP); showTip(kpAction); } } else if (keyPromoterSettings.isAllButtonsEnabled()) { kpAction = new KeyPromoterAction(action, event, KeyPromoterAction.ActionSource.OTHER); showTip(kpAction); } } }
Example 4
Source File: GoToChangePopupBuilder.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { JBPopup popup = createPopup(e); InputEvent event = e.getInputEvent(); if (event instanceof MouseEvent) { popup.show(new RelativePoint((MouseEvent)event)); } else { popup.showInBestPositionFor(e.getDataContext()); } }
Example 5
Source File: NavigateAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(AnActionEvent e) { if (myInfo.getNavigationHandler() != null) { MouseEvent mouseEvent = (MouseEvent)e.getInputEvent(); T element = myInfo.getElement(); if (element == null || !element.isValid()) return; myInfo.getNavigationHandler().navigate(mouseEvent, element); } }
Example 6
Source File: ShowExpressionTypeAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void beforeActionPerformedUpdate(@Nonnull AnActionEvent e) { super.beforeActionPerformedUpdate(e); // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut. myRequestFocus = ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent); }
Example 7
Source File: GotoDeclarationAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void update(final AnActionEvent event) { InputEvent inputEvent = event.getInputEvent(); if (inputEvent instanceof MouseEvent) { Component component = inputEvent.getComponent(); if (component != null) { Point point = ((MouseEvent)inputEvent).getPoint(); Component componentAt = SwingUtilities.getDeepestComponentAt(component, point.x, point.y); if (componentAt instanceof EditorGutterComponentEx) { event.getPresentation().setEnabled(false); return; } } } for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { try { String text = handler.getActionText(event.getDataContext()); if (text != null) { Presentation presentation = event.getPresentation(); presentation.setText(text); break; } } catch (AbstractMethodError e) { LOG.error(handler.toString(), e); } } super.update(event); }
Example 8
Source File: ShowErrorDescriptionAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void beforeActionPerformedUpdate(@Nonnull final AnActionEvent e) { super.beforeActionPerformedUpdate(e); // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut. myRequestFocus = ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent); changeState(); }
Example 9
Source File: QueryAction.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 4 votes |
private String getQueryExecutionAction(AnActionEvent e) { return e.getInputEvent() instanceof KeyEvent ? EXECUTE_WITH_SHORTCUT_ACTION : EXECUTE_WITH_MOUSE_ACTION; }
Example 10
Source File: ChainActionEvent.java From emacsIDEAs with Apache License 2.0 | 4 votes |
public ChainActionEvent(AnActionEvent e, Runnable runnable, Editor _editor, Project _project) { super(e.getInputEvent(), e.getDataContext(), e.getPlace(), e.getPresentation(), e.getActionManager(), e.getModifiers()); this._pendingAction = runnable; this._editor = _editor; this._project = _project; }
Example 11
Source File: TestRuleAction.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** Only show if selection is a grammar and in a rule */ @Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setText("Test ANTLR Rule"); // default text VirtualFile grammarFile = MyActionUtils.getGrammarFileFromEvent(e); if ( grammarFile==null ) { // we clicked somewhere outside text or non grammar file presentation.setEnabled(false); presentation.setVisible(false); return; } ParserRuleRefNode r = null; InputEvent inputEvent = e.getInputEvent(); if ( inputEvent instanceof MouseEvent ) { // this seems to be after update() called 2x and we have selected the action r = MyActionUtils.getParserRuleSurroundingRef(e); } else { // If editor component, mouse event not happened yet to update caret so must ask for mouse position Editor editor = e.getData(PlatformDataKeys.EDITOR); if ( editor!=null ) { Point mousePosition = editor.getContentComponent().getMousePosition(); if ( mousePosition!=null ) { LogicalPosition pos = editor.xyToLogicalPosition(mousePosition); int offset = editor.logicalPositionToOffset(pos); PsiFile file = e.getData(LangDataKeys.PSI_FILE); if ( file!=null ) { PsiElement el = file.findElementAt(offset); if ( el!=null ) { r = MyActionUtils.getParserRuleSurroundingRef(el); } } } } if ( r==null ) { r = MyActionUtils.getParserRuleSurroundingRef(e); } } if ( r==null ) { presentation.setEnabled(false); return; } presentation.setVisible(true); String ruleName = r.getText(); if ( Character.isLowerCase(ruleName.charAt(0)) ) { presentation.setEnabled(true); presentation.setText("Test Rule "+ruleName); } else { presentation.setEnabled(false); } }