Search in sources :

Example 1 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project buck by facebook.

the class BuckBuildManager method showNoTargetMessage.

/**
   * Print "no selected target" error message to console window.
   * Also provide a hyperlink which can directly jump to "Choose Target" GUI window.
   */
public void showNoTargetMessage(Project project) {
    BuckModule buckModule = project.getComponent(BuckModule.class);
    buckModule.getBuckEventsConsumer().consumeConsoleEvent("Please choose a build target!");
    BuckToolWindowFactory.outputConsoleMessage(project, "Please ", ConsoleViewContentType.ERROR_OUTPUT);
    BuckToolWindowFactory.outputConsoleHyperlink(project, "choose a build target!\n", new HyperlinkInfo() {

        @Override
        public void navigate(Project project) {
            JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
            AnAction action = ActionManager.getInstance().getAction("buck.ChooseTarget");
            action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) JComponent(javax.swing.JComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 2 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoGenerateTestMethodActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null) {
        return AnAction.EMPTY_ARRAY;
    }
    Project project = e.getProject();
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (project == null || editor == null)
        return AnAction.EMPTY_ARRAY;
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    ArrayList<AnAction> children = ContainerUtil.newArrayList();
    for (GoTestFramework framework : GoTestFramework.all()) {
        if (framework.isAvailableOnFile(file)) {
            children.addAll(framework.getGenerateMethodActions());
        }
    }
    return !children.isEmpty() ? children.toArray(new AnAction[children.size()]) : AnAction.EMPTY_ARRAY;
}
Also used : Project(com.intellij.openapi.project.Project) GoTestFramework(com.goide.runconfig.testing.GoTestFramework) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoSurrounderTestBase method doTest.

protected void doTest(@NotNull String codeBefore, @NotNull String expectedCodeAfter, @NotNull String surrounderDescription, boolean apply) {
    PsiFile file = myFixture.configureByText("a.go", normalizeCode(codeBefore));
    List<AnAction> applicable = SurroundWithHandler.buildSurroundActions(myFixture.getProject(), myFixture.getEditor(), file, null);
    if (applicable == null) {
        assertFalse(apply);
        return;
    }
    String suffix = ". " + surrounderDescription;
    for (AnAction action : applicable) {
        String actionPresentation = action.getTemplatePresentation().getText();
        if (actionPresentation != null && StringUtil.endsWith(actionPresentation, suffix)) {
            assertTrue(apply);
            myFixture.testAction(action);
            return;
        }
    }
    if (apply) {
        myFixture.checkResult(normalizeCode(expectedCodeAfter), true);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 4 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-plugins by StepicOrg.

the class StudyProjectComponent method registerShortcuts.

private void registerShortcuts() {
    StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
    if (window != null) {
        List<AnAction> actionsOnToolbar = window.getActions(true);
        if (actionsOnToolbar != null) {
            actionsOnToolbar.stream().filter(action -> action instanceof StudyActionWithShortcut).map(action -> (StudyActionWithShortcut) action).forEach(action -> {
                String id = action.getActionId();
                String[] shortcuts = action.getShortcuts();
                if (shortcuts != null) {
                    addShortcut(id, shortcuts);
                }
            });
        } else {
            logger.warn("Actions on toolbar are nulls");
        }
    }
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ModuleManager(com.intellij.openapi.module.ModuleManager) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Keymap(com.intellij.openapi.keymap.Keymap) ArrayList(java.util.ArrayList) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) StudyActionWithShortcut(org.stepik.core.actions.StudyActionWithShortcut) Metrics(org.stepik.core.metrics.Metrics) Map(java.util.Map) StudyToolWindowFactory(org.stepik.core.ui.StudyToolWindowFactory) Project(com.intellij.openapi.project.Project) ProjectComponent(com.intellij.openapi.components.ProjectComponent) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) SUCCESSFUL(org.stepik.core.metrics.MetricsStatus.SUCCESSFUL) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) ExecutorService(java.util.concurrent.ExecutorService) HashMap(com.intellij.util.containers.hash.HashMap) ToolWindowAnchor(com.intellij.openapi.wm.ToolWindowAnchor) ToolWindow(com.intellij.openapi.wm.ToolWindow) AnAction(com.intellij.openapi.actionSystem.AnAction) UISettings(com.intellij.ide.ui.UISettings) Executors(java.util.concurrent.Executors) Platform(javafx.application.Platform) List(java.util.List) Shortcut(com.intellij.openapi.actionSystem.Shortcut) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) StudyToolWindow(org.stepik.core.ui.StudyToolWindow) javax.swing(javax.swing) StudyToolWindow(org.stepik.core.ui.StudyToolWindow) StudyActionWithShortcut(org.stepik.core.actions.StudyActionWithShortcut) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 5 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class MavenRunConfigurationMenu method update.

@Override
public void update(AnActionEvent e) {
    for (AnAction action : getChildActionsOrStubs()) {
        if (action instanceof ExecuteMavenRunConfigurationAction) {
            remove(action);
        }
    }
    final Project project = e.getProject();
    final RunnerAndConfigurationSettings settings = MavenDataKeys.RUN_CONFIGURATION.getData(e.getDataContext());
    if (settings == null || project == null)
        return;
    Executor[] executors = ExecutorRegistry.getInstance().getRegisteredExecutors();
    for (int i = executors.length; --i >= 0; ) {
        final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executors[i].getId(), settings.getConfiguration());
        AnAction action = new ExecuteMavenRunConfigurationAction(executors[i], runner != null, project, settings);
        addAction(action, Constraints.FIRST);
    }
    super.update(e);
}
Also used : Project(com.intellij.openapi.project.Project) ProgramRunner(com.intellij.execution.runners.ProgramRunner) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5