Java Code Examples for com.intellij.openapi.actionSystem.AnActionEvent#getData()
The following examples show how to use
com.intellij.openapi.actionSystem.AnActionEvent#getData() .
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: CompareFilesAction.java From consulo with Apache License 2.0 | 6 votes |
@Nullable @Override protected DiffRequest getDiffRequest(@Nonnull AnActionEvent e) { Project project = e.getProject(); DiffRequest diffRequest = e.getData(DIFF_REQUEST); if (diffRequest != null) { return diffRequest; } VirtualFile[] data = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (data.length == 1) { VirtualFile otherFile = getOtherFile(project, data[0]); if (otherFile == null) return null; if (!hasContent(data[0])) return null; return DiffRequestFactory.getInstance().createFromFiles(project, data[0], otherFile); } else { return DiffRequestFactory.getInstance().createFromFiles(project, data[0], data[1]); } }
Example 2
Source File: ToggleWindowedModeAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void setSelected(AnActionEvent event, boolean flag) { Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { return; } String id = ToolWindowManager.getInstance(project).getActiveToolWindowId(); if (id == null) { return; } ToolWindowManagerEx mgr = ToolWindowManagerEx.getInstanceEx(project); ToolWindowEx toolWindow = (ToolWindowEx)mgr.getToolWindow(id); ToolWindowType type = toolWindow.getType(); if (ToolWindowType.WINDOWED == type) { toolWindow.setType(toolWindow.getInternalType(), null); } else { toolWindow.setType(ToolWindowType.WINDOWED, null); } }
Example 3
Source File: ChangelistDescriptionAction.java From p4ic4idea with Apache License 2.0 | 6 votes |
private Pair<OptionalClientServerConfig, P4ChangelistId> findAttachedFileRevision(AnActionEvent e) { final VirtualFile file; { final Boolean nonLocal = e.getData(VcsDataKeys.VCS_NON_LOCAL_HISTORY_SESSION); if (Boolean.TRUE.equals(nonLocal)) { LOG.info("non-local VCS history session; ignoring changelist description action"); return null; } file = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE); if (file == null || file.isDirectory()) { LOG.info("No VCS virtual file associated with changelist description action; ignoring request."); return null; } } final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION); if (!(revision instanceof P4HistoryVcsFileRevision)) { LOG.info("No file revision associated with file " + file); return null; } P4HistoryVcsFileRevision history = (P4HistoryVcsFileRevision) revision; return Pair.create(new OptionalClientServerConfig(history.getClientConfig()), history.getChangelistId()); }
Example 4
Source File: EditorAction.java From idea-latex with MIT License | 5 votes |
@Override final public void update(AnActionEvent event) { final VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); final Project project = event.getData(CommonDataKeys.PROJECT); final TextEditor editor = getEditor(event); if (virtualFile == null || project == null || editor == null) { return; } update(event, project, virtualFile, editor); }
Example 5
Source File: CopyBlazeTargetPathAction.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private static Label getSelectedTarget(AnActionEvent e) { PsiElement psiElement = e.getData(CommonDataKeys.PSI_ELEMENT); if (!(psiElement instanceof FuncallExpression)) { return null; } return ((FuncallExpression) psiElement).resolveBuildLabel(); }
Example 6
Source File: EditorHeaderToggleAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void setSelected(@Nonnull AnActionEvent e, boolean selected) { SearchSession search = e.getData(SearchSession.KEY); if (search != null) { setSelected(search, selected); } }
Example 7
Source File: SettingsAction.java From railways with MIT License | 5 votes |
/** * Implement this method to provide your action handler. * * @param e Carries information on the invocation place */ @Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); RoutesManager rm = RoutesView.getInstance(project).getCurrentRoutesManager(); if (rm == null) return; RailwaysSettingsDialog.configure(rm.getModule()); }
Example 8
Source File: ToggleAutoTestAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void setSelected(AnActionEvent e, boolean state) { Project project = e.getData(CommonDataKeys.PROJECT); RunContentDescriptor descriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR); ExecutionEnvironment environment = e.getData(LangDataKeys.EXECUTION_ENVIRONMENT); if (project != null && descriptor != null && environment != null) { getAutoTestManager(project).setAutoTestEnabled(descriptor, environment, state); } }
Example 9
Source File: FileDeleteAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); final Boolean available = event.getData(FileChooserKeys.DELETE_ACTION_AVAILABLE); if (available != null && !available) { presentation.setEnabled(false); presentation.setVisible(false); return; } super.update(event); }
Example 10
Source File: LibrariesAction.java From intellij-sdk-docs with Apache License 2.0 | 5 votes |
@Override public void update(@NotNull final AnActionEvent event) { Project project = event.getProject(); if (project == null) return; Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); if (element instanceof PsiClass) { PsiFile psiFile = ((PsiClass) element).getContainingFile(); if (psiFile == null) return; VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) return; event.getPresentation().setEnabledAndVisible(true); } }
Example 11
Source File: ProjectWindowAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isSelected(AnActionEvent e) { // show check mark for active and visible project frame final Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { return false; } return myProjectLocation.equals(project.getPresentableUrl()); }
Example 12
Source File: OnEventGenerateAction.java From litho with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_ON_EVENT_GENERATION + ".invoke"); super.actionPerformed(e); final PsiFile file = e.getData(CommonDataKeys.PSI_FILE); LithoPluginUtils.getFirstLayoutSpec(file) .ifPresent(ComponentGenerateUtils::updateLayoutComponent); }
Example 13
Source File: TabListAction.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isTabListAvailable(AnActionEvent e) { JBTabsImpl tabs = e.getData(JBTabsImpl.NAVIGATION_ACTIONS_KEY); if (tabs == null || !tabs.isEditorTabs()) { return false; } return tabs.canShowMorePopup(); }
Example 14
Source File: TwigExtractLanguageAction.java From idea-php-symfony2-plugin with MIT License | 4 votes |
public void update(AnActionEvent event) { Project project = event.getData(PlatformDataKeys.PROJECT); if (project == null || !Symfony2ProjectComponent.isEnabled(project)) { this.setStatus(event, false); return; } PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE); if(!(psiFile instanceof TwigFile)) { this.setStatus(event, false); return; } Editor editor = event.getData(PlatformDataKeys.EDITOR); if(editor == null) { this.setStatus(event, false); return; } // find valid PsiElement context, because only html text is a valid extractor action PsiElement psiElement; if(editor.getSelectionModel().hasSelection()) { psiElement = psiFile.findElementAt(editor.getSelectionModel().getSelectionStart()); } else { psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset()); } if(psiElement == null) { this.setStatus(event, false); return; } // <a title="TEXT">TEXT</a> IElementType elementType = psiElement.getNode().getElementType(); if(elementType == XmlTokenType.XML_DATA_CHARACTERS || elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) { this.setStatus(event, true); } else { this.setStatus(event, false); } }
Example 15
Source File: FileChooserAction.java From consulo with Apache License 2.0 | 4 votes |
final public void actionPerformed(AnActionEvent e) { FileSystemTree tree = e.getData(FileSystemTree.DATA_KEY); actionPerformed(tree, e); }
Example 16
Source File: ShowRootsColumnAction.java From consulo with Apache License 2.0 | 4 votes |
@Override public void update(@Nonnull AnActionEvent e) { super.update(e); VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI); if (ui == null || !ui.isMultipleRoots()) e.getPresentation().setEnabledAndVisible(false); }
Example 17
Source File: GenerateLexerRulesForLiteralsAction.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void actionPerformed(AnActionEvent e) { LOG.info("actionPerformed GenerateLexerRulesForLiteralsAction"); final Project project = e.getProject(); final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); if (psiFile == null) { return; } String inputText = psiFile.getText(); ParsingResult results = ParsingUtils.parseANTLRGrammar(inputText); final Parser parser = results.parser; final ParseTree tree = results.tree; Collection<ParseTree> literalNodes = XPath.findAll(tree, "//ruleBlock//STRING_LITERAL", parser); LinkedHashMap<String, String> lexerRules = new LinkedHashMap<String, String>(); for (ParseTree node : literalNodes) { String literal = node.getText(); String ruleText = String.format("%s : %s ;", RefactorUtils.getLexerRuleNameFromLiteral(literal), literal); lexerRules.put(literal, ruleText); } // remove those already defined String lexerRulesXPath = "//lexerRule"; String treePattern = "<TOKEN_REF> : <STRING_LITERAL>;"; ParseTreePattern p = parser.compileParseTreePattern(treePattern, ANTLRv4Parser.RULE_lexerRule); List<ParseTreeMatch> matches = p.findAll(tree, lexerRulesXPath); for (ParseTreeMatch match : matches) { ParseTree lit = match.get("STRING_LITERAL"); if (lexerRules.containsKey(lit.getText())) { // we have rule for this literal already lexerRules.remove(lit.getText()); } } final LiteralChooser chooser = new LiteralChooser(project, new ArrayList<String>(lexerRules.values())); chooser.show(); List<String> selectedElements = chooser.getSelectedElements(); // chooser disposed automatically. final Editor editor = e.getData(PlatformDataKeys.EDITOR); final Document doc = editor.getDocument(); final CommonTokenStream tokens = (CommonTokenStream) parser.getTokenStream(); // System.out.println(selectedElements); if (selectedElements != null) { String text = doc.getText(); int cursorOffset = editor.getCaretModel().getOffset(); // make sure it's not in middle of rule; put between. // System.out.println("offset "+cursorOffset); Collection<ParseTree> allRuleNodes = XPath.findAll(tree, "//ruleSpec", parser); for (ParseTree r : allRuleNodes) { Interval extent = r.getSourceInterval(); // token indexes int start = tokens.get(extent.a).getStartIndex(); int stop = tokens.get(extent.b).getStopIndex(); // System.out.println("rule "+r.getChild(0).getText()+": "+start+".."+stop); if (cursorOffset < start) { // before this rule, so must be between previous and this one cursorOffset = start; // put right before this rule break; } else if (cursorOffset >= start && cursorOffset <= stop) { // cursor in this rule cursorOffset = stop + 2; // put right before this rule (after newline) if (cursorOffset >= text.length()) { cursorOffset = text.length(); } break; } } String allRules = Utils.join(selectedElements.iterator(), "\n"); text = text.substring(0, cursorOffset) + "\n" + allRules + "\n" + text.substring(cursorOffset, text.length()); MyPsiUtils.replacePsiFileFromText(project, psiFile, text); } }
Example 18
Source File: Actions.java From KJump with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void update(@NotNull AnActionEvent e) { Editor editor = e.getData(CommonDataKeys.EDITOR); e.getPresentation().setEnabled(editor != null); }
Example 19
Source File: ToggleBreadcrumbsAction.java From consulo with Apache License 2.0 | 4 votes |
@Contract("null -> null") @Nullable static Editor findEditor(@Nullable AnActionEvent event) { return event == null ? null : event.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE); }
Example 20
Source File: SendProjectFileAction2.java From SmartIM4IntelliJ with Apache License 2.0 | 4 votes |
@Override protected void gotoActionPerformed(AnActionEvent anActionEvent) { Project project = anActionEvent.getData(CommonDataKeys.PROJECT); ChooseByNameModel model = new GotoFileModel(project); showNavigationPopup(anActionEvent, model, new Callback(), false); }