com.intellij.openapi.actionSystem.AnActionEvent Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.AnActionEvent. 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: CommitMessageTemplateAction.java    From intellij-commit-message-template-plugin with MIT License 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    final CommitMessageI checkinPanel = getCheckinPanel(e);
    if (checkinPanel == null) {
        return;
    }

    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    CommitMessageTemplateConfig config = CommitMessageTemplateConfig.getInstance(project);

    if (config != null) {
        String commitMessage = config.getCommitMessage();
        if (!commitMessage.isEmpty()) {
            checkinPanel.setCommitMessage(commitMessage);
        }
    }
}
 
Example #2
Source File: AddAction.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getData(CommonDataKeys.PROJECT);
    final VirtualFile[] files = VcsUtil.getVirtualFiles(anActionEvent);

    final List<VcsException> errors = new ArrayList<VcsException>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        public void run() {
            ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
            errors.addAll(TFSVcs.getInstance(project).getCheckinEnvironment().scheduleUnversionedFilesForAddition(Arrays.asList(files)));
        }
    }, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_ADD_SCHEDULING), false, project);

    if (!errors.isEmpty()) {
        AbstractVcsHelper.getInstance(project).showErrors(errors, TFSVcs.TFVC_NAME);
    }
}
 
Example #3
Source File: EditFavoritesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = e.getProject();
  FavoritesViewTreeBuilder treeBuilder = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY);
  String listName = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY);
  if (project == null || treeBuilder == null || listName == null) {
    return;
  }
  FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
  FavoritesListProvider provider = favoritesManager.getListProvider(listName);
  Set<Object> selection = treeBuilder.getSelectedElements();
  if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)) {
    provider.handle(CommonActionsPanel.Buttons.EDIT, project, selection, treeBuilder.getTree());
    return;
  }
  favoritesManager.renameList(project, listName);
}
 
Example #4
Source File: BuckUninstallAction.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOnPooledThread(final AnActionEvent e) {
  Project project = e.getProject();
  BuckBuildManager buildManager = BuckBuildManager.getInstance(project);
  String target = buildManager.getCurrentSavedTarget(project);
  BuckModule buckModule = project.getComponent(BuckModule.class);
  buckModule.attach(target);

  if (target == null) {
    buildManager.showNoTargetMessage(project);
    return;
  }

  // Initiate a buck uninstall
  BuckBuildCommandHandler handler = new BuckBuildCommandHandler(project, BuckCommand.UNINSTALL);
  handler.command().addParameter(target);
  buildManager.runBuckCommandWhileConnectedToBuck(handler, ACTION_TITLE, buckModule);
}
 
Example #5
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static PsiElement getSelectedPsiElement(AnActionEvent e) {
	Editor editor = e.getData(PlatformDataKeys.EDITOR);

	if ( editor==null ) { // not in editor
		PsiElement selectedNavElement = e.getData(LangDataKeys.PSI_ELEMENT);
		// in nav bar?
		if ( selectedNavElement==null || !(selectedNavElement instanceof ParserRuleRefNode) ) {
			return null;
		}
		return selectedNavElement;
	}

	// in editor
	PsiFile file = e.getData(LangDataKeys.PSI_FILE);
	if ( file==null ) {
		return null;
	}

	int offset = editor.getCaretModel().getOffset();
	PsiElement el = file.findElementAt(offset);
	return el;
}
 
Example #6
Source File: CreateElementActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public final void actionPerformed(@Nonnull final AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  if (view == null) {
    return;
  }

  final Project project = e.getProject();

  final PsiDirectory dir = view.getOrChooseDirectory();
  if (dir == null) return;

  invokeDialog(project, dir, elements -> {

    for (PsiElement createdElement : elements) {
      view.selectElement(createdElement);
    }
  });
}
 
Example #7
Source File: ContentEntryEditingAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  super.update(e);
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(true);
  final VirtualFile[] files = getSelectedFiles();
  if (files.length == 0) {
    presentation.setEnabled(false);
    return;
  }
  for (VirtualFile file : files) {
    if (file == null || !file.isDirectory()) {
      presentation.setEnabled(false);
      break;
    }
  }
}
 
Example #8
Source File: CopyRevisionNumberAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER);
  if (revision == null) {
    VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (fileRevision != null) {
      revision = fileRevision.getRevisionNumber();
    }
  }
  if (revision == null) {
    return;
  }

  String rev = revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString();
  CopyPasteManager.getInstance().setContents(new StringSelection(rev));
}
 
Example #9
Source File: AbstractCreateFormAction.java    From react-templates-plugin with MIT License 6 votes vote down vote up
public void update(final AnActionEvent e) {
        super.update(e);
//        final Project project = e.getData(CommonDataKeys.PROJECT);
//        final Presentation presentation = e.getPresentation();
//        if (presentation.isEnabled()) {
//            final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
//            if (view != null) {
//                final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
//                final PsiDirectory[] dirs = view.getDirectories();
//                for (final PsiDirectory dir : dirs) {
//                    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
//                        return;
//                    }
//                }
//            }
//
//            presentation.setEnabled(false);
//            presentation.setVisible(false);
//        }
    }
 
Example #10
Source File: OpenSolutionAction.java    From leetcode-editor with Apache License 2.0 6 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent anActionEvent) {
    JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
    if (tree == null) {
        anActionEvent.getPresentation().setEnabled(false);
        return;
    }
    Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
    if (question == null) {
        anActionEvent.getPresentation().setEnabled(false);
        return;
    }
    if (Constant.ARTICLE_LIVE_NONE.equals(question.getArticleLive())) {
        anActionEvent.getPresentation().setEnabled(false);
    } else {
        anActionEvent.getPresentation().setEnabled(true);
    }
}
 
Example #11
Source File: RefreshLogAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VcsLogUtil.triggerUsage(e);

  VcsLogManager logManager = e.getRequiredData(VcsLogInternalDataKeys.LOG_MANAGER);

  // diagnostic for possible refresh problems
  VcsLogUi ui = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI);
  if (ui instanceof VcsLogUiImpl) {
    VcsLogFilterer filterer = ((VcsLogUiImpl)ui).getFilterer();
    if (!filterer.isValid()) {
      String message = "Trying to refresh invalid log tab.";
      if (!logManager.getDataManager().getProgress().isRunning()) {
        LOG.error(message);
      } else {
        LOG.warn(message);
      }
      filterer.setValid(true);
    }
  }

  logManager.getDataManager().refreshSoftly();
}
 
Example #12
Source File: ClearOneAction.java    From leetcode-editor with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) {

    String codeType = config.getCodeType();
    CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType);
    if (codeTypeEnum == null) {
        MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
        return;
    }

    String filePath = PersistentConfig.getInstance().getTempFilePath() + VelocityUtils.convert(config.getCustomFileName(), question) + codeTypeEnum.getSuffix();

    File file = new File(filePath);
    if (file.exists()) {
        ApplicationManager.getApplication().invokeAndWait(() -> {
            VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
            if (FileEditorManager.getInstance(anActionEvent.getProject()).isFileOpen(vf)) {
                FileEditorManager.getInstance(anActionEvent.getProject()).closeFile(vf);
            }
            file.delete();
        });
    }
    MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg(question.getFormTitle(), PropertiesUtils.getInfo("clear.success"));

}
 
Example #13
Source File: OnEventGenerateAction.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  // Applies visibility of the Generate Action group
  super.update(e);
  final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
  if (!LithoPluginUtils.isLithoSpec(file)) {
    e.getPresentation().setEnabledAndVisible(false);
  }
}
 
Example #14
Source File: EsyShellAction.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project != null) {
        doAction(project, CliType.Esy.SHELL);
    }
}
 
Example #15
Source File: JSGraphQLToggleVariablesAction.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void setSelected(AnActionEvent e, boolean state) {

    final Editor variablesEditor = getVariablesEditor(e);
    if (variablesEditor != null) {

        final Editor queryEditor = variablesEditor.getUserData(JSGraphQLLanguageUIProjectService.GRAPH_QL_QUERY_EDITOR);
        if(queryEditor == null) {
            // not linked to a query editor
            return;
        }

        final ScrollingModel scroll = queryEditor.getScrollingModel();
        final int currentScroll = scroll.getVerticalScrollOffset();

        variablesEditor.putUserData(JS_GRAPH_QL_VARIABLES_MODEL, state ? Boolean.TRUE : Boolean.FALSE);
        variablesEditor.getComponent().setVisible(state);

        if (state) {
            variablesEditor.getContentComponent().grabFocus();
        } else {
            queryEditor.getContentComponent().grabFocus();
        }

        // restore scroll position after the editor has had a chance to re-layout
        ApplicationManager.getApplication().invokeLater(() -> {
            UIUtil.invokeLaterIfNeeded(() -> scroll.scrollVertically(currentScroll));
        });

    }

}
 
Example #16
Source File: CollapseProjectTreeAction.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
@Override
public final void actionPerformed(final AnActionEvent anActionEvent) {
    JTree jTree = windowObjects.getjTree();

    for (int i = 0; i < jTree.getRowCount(); i++) {
        jTree.collapsePath(jTree.getPathForRow(i));
    }
    jTree.updateUI();
}
 
Example #17
Source File: AddToNewFavoritesListAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = e.getProject();
  Collection<AbstractTreeNode> nodesToAdd = AddToFavoritesAction.getNodesToAdd(e.getDataContext(), true);
  if (nodesToAdd != null) {
    final String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
    if (newName != null) {
      FavoritesManager.getInstance(project).addRoots(newName, nodesToAdd);
    }
  }
}
 
Example #18
Source File: FloobitsWindow.java    From floobits-intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    FloobitsPlugin floobitsPlugin = FloobitsPlugin.getInstance(e.getProject());
    if (floobitsPlugin != null) {
        floobitsPlugin.context.toggleFloobitsWindow();
    }
}
 
Example #19
Source File: FlutterViewToggleableAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final void update(@NotNull AnActionEvent e) {
  // selected
  final boolean selected = this.isSelected();
  final Presentation presentation = e.getPresentation();
  presentation.putClientProperty("selected", selected);

  if (!app.isSessionActive()) {
    dispose();
    e.getPresentation().setEnabled(false);
    return;
  }

  if (currentValueSubscription == null) {
    currentValueSubscription =
      app.getVMServiceManager().getServiceExtensionState(extensionDescription.getExtension()).listen((state) -> {
        if (presentation.getClientProperty("selected") != (Boolean)state.isEnabled()) {
          presentation.putClientProperty("selected", state.isEnabled());
        }
      }, true);
  }

  presentation.setText(
    isSelected()
    ? extensionDescription.getEnabledText()
    : extensionDescription.getDisabledText());

  app.hasServiceExtension(extensionDescription.getExtension(), (enabled) -> {
    e.getPresentation().setEnabled(app.isSessionActive() && enabled);
  });
}
 
Example #20
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static ParserRuleRefNode getParserRuleSurroundingRef(AnActionEvent e) {
	PsiElement selectedPsiNode = getSelectedPsiElement(e);
	RuleSpecNode ruleSpecNode = getRuleSurroundingRef(selectedPsiNode, ParserRuleSpecNode.class);
	if ( ruleSpecNode==null ) return null;
	// find the name of rule under ParserRuleSpecNode
	return PsiTreeUtil.findChildOfType(ruleSpecNode, ParserRuleRefNode.class);
}
 
Example #21
Source File: AbstractMissingFilesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final List<FilePath> files = e.getData(ChangesListView.MISSING_FILES_DATA_KEY);
  if (files == null) return;

  final ProgressManager progressManager = ProgressManager.getInstance();
  final Runnable action = new Runnable() {
    public void run() {
      final List<VcsException> allExceptions = new ArrayList<VcsException>();
      ChangesUtil.processFilePathsByVcs(project, files, new ChangesUtil.PerVcsProcessor<FilePath>() {
        public void process(final AbstractVcs vcs, final List<FilePath> items) {
          final List<VcsException> exceptions = processFiles(vcs, files);
          if (exceptions != null) {
            allExceptions.addAll(exceptions);
          }
        }
      });

      for (FilePath file : files) {
        VcsDirtyScopeManager.getInstance(project).fileDirty(file);
      }
      ChangesViewManager.getInstance(project).scheduleRefresh();
      if (allExceptions.size() > 0) {
        AbstractVcsHelper.getInstance(project).showErrors(allExceptions, "VCS Errors");
      }
    }
  };
  if (synchronously()) {
    action.run();
  } else {
    progressManager.runProcessWithProgressSynchronously(action, getName(), true, project);
  }
}
 
Example #22
Source File: TestcaseAction.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) {
    if (StringUtils.isBlank(question.getTestCase())) {
        String codeType = PersistentConfig.getInstance().getInitConfig().getCodeType();
        CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType);

        CodeManager.setTestCaeAndLang(question, codeTypeEnum, anActionEvent.getProject());
    }
    AtomicReference<String> text = new AtomicReference<>(TestcaseAction.class.getName());
    ApplicationManager.getApplication().invokeAndWait(() -> {
        TestcasePanel dialog = new TestcasePanel(anActionEvent.getProject());
        dialog.setTitle(question.getFormTitle() + " Testcase");
        dialog.setText(question.getTestCase());
        if (dialog.showAndGet()) {
            text.set(dialog.testcaseText());

        }
    });
    if (!TestcaseAction.class.getName().equals(text.get())) {
        if (StringUtils.isBlank(text.get())) {
            MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("test.case"));
            return;
        } else {
            question.setTestCase(text.get());
            CodeManager.RunCodeCode(question, anActionEvent.getProject());
        }
    }

}
 
Example #23
Source File: AceJumpCopyAction.java    From emacsIDEAs with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Editor editor = e.getData(PlatformDataKeys.EDITOR);

    AceJumpAction.getInstance().switchEditorIfNeed(e);
    AceJumpAction.getInstance().addCommandAroundJump(new CopyAfterJumpCommand(editor));
    AceJumpAction.getInstance().performAction(e);
}
 
Example #24
Source File: CollapseOrExpandGraphAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  VcsLogUtil.triggerUsage(e);

  VcsLogUi ui = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI);
  executeAction((VcsLogUiImpl)ui);
}
 
Example #25
Source File: NewBundleCompilerPass.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {

    Project project = getEventProject(event);
    if(project == null) {
        this.setStatus(event, false);
        return;
    }

    PsiDirectory bundleDirContext = BundleClassGeneratorUtil.getBundleDirContext(event);
    if(bundleDirContext == null) {
        return;
    }

    final PhpClass phpClass = BundleClassGeneratorUtil.getBundleClassInDirectory(bundleDirContext);
    if(phpClass == null) {
        return;
    }

    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
            PsiElement psiFile = PhpBundleFileFactory.invokeCreateCompilerPass(phpClass, null);
            if(psiFile != null) {
                new OpenFileDescriptor(getProject(), psiFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }
        }

        @Override
        public String getGroupID() {
            return "Create CompilerClass";
        }
    }.execute();

}
 
Example #26
Source File: PositionAction.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
    VirtualFile vf = ArrayUtil.getFirstElement(FileEditorManager.getInstance(e.getProject()).getSelectedFiles());
    if (vf == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(e.getProject()).getEditor(vf.getPath());
    if (leetcodeEditor == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    e.getPresentation().setEnabled(true);
}
 
Example #27
Source File: ScheduleForAdditionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(@Nonnull AnActionEvent e) {
  boolean enabled = e.getProject() != null && !isEmpty(getUnversionedFiles(e, e.getProject()));

  e.getPresentation().setEnabled(enabled);
  if (ActionPlaces.ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION.equals(e.getPlace()) || ActionPlaces.CHANGES_VIEW_POPUP.equals(e.getPlace())) {
    e.getPresentation().setVisible(enabled);
  }
}
 
Example #28
Source File: ToggleBookmarkAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return;
  BookmarkInContextInfo info = new BookmarkInContextInfo(dataContext, project).invoke();
  if (info.getFile() == null) return;

  if (info.getBookmarkAtPlace() != null) {
    BookmarkManager.getInstance(project).removeBookmark(info.getBookmarkAtPlace());
  }
  else {
    BookmarkManager.getInstance(project).addTextBookmark(info.getFile(), info.getLine(), "");
  }
}
 
Example #29
Source File: SymfonySymbolSearchAction.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
protected void gotoActionPerformed(AnActionEvent paramAnActionEvent) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
    Project localProject = paramAnActionEvent.getData(CommonDataKeys.PROJECT);
    if (localProject != null) {
        SymfonySymbolSearchModel searchModel = new SymfonySymbolSearchModel(localProject, new ChooseByNameContributor[] { new Symfony2NavigationContributor(localProject) });
        showNavigationPopup(paramAnActionEvent, searchModel, new MyGotoCallback(), null, true);
    }
}
 
Example #30
Source File: OpenRepositoryVersionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(final AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES);
  e.getPresentation().setEnabled(project != null && changes != null &&
                                 (! CommittedChangesBrowserUseCase.IN_AIR.equals(e.getDataContext().getData(CommittedChangesBrowserUseCase.DATA_KEY))) &&
                                 hasValidChanges(changes) &&
                                 ModalityState.NON_MODAL.equals(ModalityState.current()));
}