Search in sources :

Example 21 with AnAction

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

the class XsltConfigImpl method initComponent.

@Override
@SuppressWarnings({ "StringEquality" })
public void initComponent() {
    final Language xmlLang = StdFileTypes.XML.getLanguage();
    //            intentionManager.addAction(new DeleteUnusedParameterFix());
    //            intentionManager.addAction(new DeleteUnusedVariableFix());
    final XsltFormattingModelBuilder builder = new XsltFormattingModelBuilder(LanguageFormatting.INSTANCE.forLanguage(xmlLang));
    LanguageFormatting.INSTANCE.addExplicitExtension(xmlLang, builder);
    try {
        // TODO: put this into com.intellij.refactoring.actions.IntroduceParameterAction, just like IntroduceVariableAction
        final AnAction introduceParameter = ActionManager.getInstance().getAction("IntroduceParameter");
        if (introduceParameter != null) {
            introduceParameter.setInjectedContext(true);
        }
    } catch (Exception e) {
        Logger.getInstance(XsltConfigImpl.class.getName()).error(e);
    }
}
Also used : Language(com.intellij.lang.Language) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 22 with AnAction

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

the class AssignShortcutAction method getGoalActionId.

@Nullable
private static String getGoalActionId(DataContext context) {
    final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
    if (goals == null || goals.size() != 1) {
        return null;
    }
    MavenProject project = MavenActionUtil.getMavenProject(context);
    if (project == null)
        return null;
    String goal = goals.get(0);
    final MavenShortcutsManager shortcutsManager = getShortcutsManager(context);
    String actionId = shortcutsManager != null ? shortcutsManager.getActionId(project.getPath(), goal) : null;
    if (actionId != null) {
        AnAction action = ActionManager.getInstance().getAction(actionId);
        if (action == null) {
            MavenKeymapExtension.getOrRegisterAction(project, actionId, goal);
        }
    }
    return actionId;
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenShortcutsManager(org.jetbrains.idea.maven.tasks.MavenShortcutsManager) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with AnAction

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

the class BoundIconRenderer method getClickAction.

@Override
@Nullable
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            List<PsiFile> formFiles = getBoundFormFiles();
            if (formFiles.size() > 0) {
                final VirtualFile virtualFile = formFiles.get(0).getVirtualFile();
                if (virtualFile == null) {
                    return;
                }
                Project project = myElement.getProject();
                FileEditor[] editors = FileEditorManager.getInstance(project).openFile(virtualFile, true);
                if (myElement instanceof PsiField) {
                    for (FileEditor editor : editors) {
                        if (editor instanceof UIFormEditor) {
                            ((UIFormEditor) editor).selectComponent(((PsiField) myElement).getName());
                        }
                    }
                }
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) UIFormEditor(com.intellij.uiDesigner.editor.UIFormEditor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with AnAction

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

the class PyCharmEduInitialConfigurator method unregisterAction.

private static void unregisterAction(String actionId, String groupId) {
    ActionManager actionManager = ActionManager.getInstance();
    AnAction action = actionManager.getAction(actionId);
    if (action != null) {
        AnAction actionGroup = actionManager.getAction(groupId);
        if (actionGroup != null && actionGroup instanceof DefaultActionGroup) {
            ((DefaultActionGroup) actionGroup).remove(action);
            actionManager.unregisterAction(actionId);
        }
    }
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 25 with AnAction

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

the class PyExecuteFileLineMarkerProvider method collectSlowLineMarkers.

@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    if (elements.isEmpty()) {
        return;
    }
    Optional<PsiElement> psiElement = elements.stream().filter((element) -> element instanceof PsiFile).findFirst();
    if (!psiElement.isPresent())
        return;
    final PsiElement file = psiElement.get();
    final RunContextAction runAction = new PyStudyRunContextAction(DefaultRunExecutor.getRunExecutorInstance());
    final PyExecuteFileExtensionPoint[] extensions = ApplicationManager.getApplication().getExtensions(PyExecuteFileExtensionPoint.EP_NAME);
    final List<AnAction> actions = new ArrayList<>();
    final DefaultActionGroup group = new DefaultActionGroup();
    if (PlatformUtils.isPyCharmEducational()) {
        group.add(runAction);
    }
    for (PyExecuteFileExtensionPoint extension : extensions) {
        AnAction action = extension.getRunAction();
        if (action != null && extension.accept(file.getProject())) {
            actions.add(action);
            group.add(action);
        }
    }
    if (actions.isEmpty() && !PlatformUtils.isPyCharmEducational()) {
        return;
    }
    Icon icon = PlatformUtils.isPyCharmEducational() ? AllIcons.Actions.Execute : actions.get(0).getTemplatePresentation().getIcon();
    final LineMarkerInfo<PsiElement> markerInfo = new LineMarkerInfo<PsiElement>(file, file.getTextRange(), icon, Pass.LINE_MARKERS, e -> {
        String text = "Execute '" + e.getContainingFile().getName() + "'";
        return PlatformUtils.isPyCharmEducational() ? text : actions.get(0).getTemplatePresentation().getText();
    }, null, GutterIconRenderer.Alignment.RIGHT) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return PlatformUtils.isPyCharmEducational() ? runAction : actions.get(0);
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    if (!PlatformUtils.isPyCharmEducational() && actions.isEmpty()) {
                        return null;
                    }
                    if (actions.size() == 1) {
                        return null;
                    }
                    return group;
                }
            };
        }
    };
    result.add(markerInfo);
}
Also used : AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) Collection(java.util.Collection) PlatformUtils(com.intellij.util.PlatformUtils) AnAction(com.intellij.openapi.actionSystem.AnAction) RunContextAction(com.intellij.execution.actions.RunContextAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiFile(com.intellij.psi.PsiFile) Optional(java.util.Optional) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) javax.swing(javax.swing) RunContextAction(com.intellij.execution.actions.RunContextAction) ArrayList(java.util.ArrayList) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

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