Search in sources :

Example 91 with AnAction

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

the class AbstractGithubTagDownloadedProjectGenerator method createGitHubLink.

public ActionLink createGitHubLink() {
    final ActionLink link = new ActionLink(getName() + " on GitHub", new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            BrowserUtil.open("https://github.com/" + getGithubUserName() + "/" + getGithubRepositoryName());
        }
    });
    link.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    return link;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionLink(com.intellij.ui.components.labels.ActionLink)

Example 92 with AnAction

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

the class BaseGenerateTestSupportMethodAction method createEditTemplateAction.

@Nullable
@Override
public AnAction createEditTemplateAction(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
    final PsiClass targetClass = editor == null || file == null ? null : getTargetClass(editor, file);
    if (targetClass != null) {
        final List<TestFramework> frameworks = TestIntegrationUtils.findSuitableFrameworks(targetClass);
        final TestIntegrationUtils.MethodKind methodKind = ((MyHandler) getHandler()).myMethodKind;
        if (!frameworks.isEmpty()) {
            return new AnAction("Edit Template") {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    chooseAndPerform(editor, frameworks, framework -> {
                        final FileTemplateDescriptor descriptor = methodKind.getFileTemplateDescriptor(framework);
                        if (descriptor != null) {
                            final String fileName = descriptor.getFileName();
                            AllFileTemplatesConfigurable.editCodeTemplate(FileUtil.getNameWithoutExtension(fileName), project);
                        } else {
                            HintManager.getInstance().showErrorHint(editor, "No template found for " + framework.getName() + ":" + BaseGenerateTestSupportMethodAction.this.getTemplatePresentation().getText());
                        }
                    });
                }
            };
        }
    }
    return null;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Project(com.intellij.openapi.project.Project) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with AnAction

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

the class RunLineMarkerTest method testTestClassWithMain.

public void testTestClassWithMain() throws Exception {
    myFixture.addClass("package junit.framework; public class TestCase {}");
    myFixture.configureByText("MainTest.java", "public class <caret>MainTest extends junit.framework.TestCase {\n" + "    public static void main(String[] args) {\n" + "    }\n" + "    public void testFoo() {\n" + "    }\n" + "}");
    List<GutterMark> marks = myFixture.findGuttersAtCaret();
    assertEquals(1, marks.size());
    GutterIconRenderer mark = (GutterIconRenderer) marks.get(0);
    ActionGroup group = mark.getPopupMenuActions();
    assertNotNull(group);
    TestActionEvent event = new TestActionEvent();
    List<AnAction> list = ContainerUtil.findAll(group.getChildren(event), action -> {
        TestActionEvent actionEvent = new TestActionEvent();
        action.update(actionEvent);
        String text = actionEvent.getPresentation().getText();
        return text != null && text.startsWith("Run ") && text.endsWith("'");
    });
    assertEquals(list.toString(), 2, list.size());
    list.get(0).update(event);
    assertEquals("Run 'MainTest.main()'", event.getPresentation().getText());
    list.get(1).update(event);
    assertEquals("Run 'MainTest'", event.getPresentation().getText());
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) GutterMark(com.intellij.codeInsight.daemon.GutterMark) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 94 with AnAction

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

the class DvcsQuickListContentProvider method getVcsActions.

@Nullable
public List<AnAction> getVcsActions(@Nullable Project project, @Nullable AbstractVcs activeVcs, @Nullable DataContext dataContext) {
    if (activeVcs == null || !getVcsName().equals(activeVcs.getName())) {
        return null;
    }
    final ActionManager manager = ActionManager.getInstance();
    final List<AnAction> actions = new ArrayList<>();
    actions.add(new Separator(activeVcs.getDisplayName()));
    add("CheckinProject", manager, actions);
    add("CheckinFiles", manager, actions);
    add("ChangesView.Revert", manager, actions);
    addSeparator(actions);
    add("Vcs.ShowTabbedFileHistory", manager, actions);
    add("Annotate", manager, actions);
    add("Compare.SameVersion", manager, actions);
    addSeparator(actions);
    addVcsSpecificActions(manager, actions);
    return actions;
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) ArrayList(java.util.ArrayList) AnAction(com.intellij.openapi.actionSystem.AnAction) Separator(com.intellij.openapi.actionSystem.Separator) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with AnAction

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

the class ShowGeneratedManifestTest method testMenuGroup.

@Test
public void testMenuGroup() {
    ViewGeneratedManifestGroup group = (ViewGeneratedManifestGroup) ActionManager.getInstance().getAction("osmorc.viewGeneratedManifests");
    assertNotNull(group);
    @SuppressWarnings("deprecation") DataContext context = DataManager.getInstance().getDataContext();
    AnActionEvent event = AnActionEvent.createFromAnAction(group, null, "", context);
    AnAction[] actions = group.getChildren(event);
    assertEquals(3, actions.length);
    Arrays.sort(actions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
    assertEquals("[t0] t0.jar", actions[0].getTemplatePresentation().getText());
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Test(org.junit.Test)

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