Search in sources :

Example 1 with RunContextAction

use of com.intellij.execution.actions.RunContextAction 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)

Example 2 with RunContextAction

use of com.intellij.execution.actions.RunContextAction in project intellij-community by JetBrains.

the class ExecutorRegistryImpl method initExecutor.

synchronized void initExecutor(@NotNull final Executor executor) {
    if (myId2Executor.get(executor.getId()) != null) {
        LOG.error("Executor with id: \"" + executor.getId() + "\" was already registered!");
    }
    if (myContextActionIdSet.contains(executor.getContextActionId())) {
        LOG.error("Executor with context action id: \"" + executor.getContextActionId() + "\" was already registered!");
    }
    myExecutors.add(executor);
    myId2Executor.put(executor.getId(), executor);
    myContextActionIdSet.add(executor.getContextActionId());
    registerAction(executor.getId(), new ExecutorAction(executor), RUNNERS_GROUP, myId2Action);
    registerAction(executor.getContextActionId(), new RunContextAction(executor), RUN_CONTEXT_GROUP, myContextActionId2Action);
}
Also used : RunContextAction(com.intellij.execution.actions.RunContextAction)

Aggregations

RunContextAction (com.intellij.execution.actions.RunContextAction)2 Pass (com.intellij.codeHighlighting.Pass)1 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 AllIcons (com.intellij.icons.AllIcons)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PlatformUtils (com.intellij.util.PlatformUtils)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 javax.swing (javax.swing)1 NotNull (org.jetbrains.annotations.NotNull)1