Search in sources :

Example 1 with ActionGroup

use of com.intellij.openapi.actionSystem.ActionGroup 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 ActionGroup

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

the class SmartPopupActionGroup method getChildrenCountRecursive.

private static int getChildrenCountRecursive(ActionGroup group) {
    AnAction[] children;
    if (group instanceof DefaultActionGroup) {
        children = ((DefaultActionGroup) group).getChildActionsOrStubs();
    } else {
        children = group.getChildren(null);
    }
    int count = 0;
    for (AnAction child : children) {
        if (child instanceof ActionGroup) {
            count += getChildrenCountRecursive((ActionGroup) child);
        } else {
            count++;
        }
    }
    return count;
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 3 with ActionGroup

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

the class TabInfo method setActions.

public TabInfo setActions(ActionGroup group, String place) {
    ActionGroup old = myGroup;
    myGroup = group;
    myPlace = place;
    myChangeSupport.firePropertyChange(ACTION_GROUP, old, myGroup);
    return this;
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup)

Example 4 with ActionGroup

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

the class MaintenanceAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("MaintenanceGroup");
    JBPopupFactory.getInstance().createActionGroupPopup("Maintenance", group, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true).showInFocusCenter();
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup)

Example 5 with ActionGroup

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

the class CustomActionsSchema method isCorrectActionGroup.

public boolean isCorrectActionGroup(ActionGroup group, String defaultGroupName) {
    if (myActions.isEmpty()) {
        return false;
    }
    final String text = group.getTemplatePresentation().getText();
    if (!StringUtil.isEmpty(text)) {
        for (ActionUrl url : myActions) {
            if (url.getGroupPath().contains(text) || url.getGroupPath().contains(defaultGroupName)) {
                return true;
            }
            if (url.getComponent() instanceof Group) {
                final Group urlGroup = (Group) url.getComponent();
                String id = urlGroup.getName() != null ? urlGroup.getName() : urlGroup.getId();
                if (id == null || id.equals(text) || id.equals(defaultGroupName)) {
                    return true;
                }
            }
        }
        return false;
    }
    return true;
}
Also used : Group(com.intellij.openapi.keymap.impl.ui.Group) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup)

Aggregations

ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)32 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)9 AnAction (com.intellij.openapi.actionSystem.AnAction)8 NotNull (org.jetbrains.annotations.NotNull)6 ActionManager (com.intellij.openapi.actionSystem.ActionManager)4 ActionToolbar (com.intellij.openapi.actionSystem.ActionToolbar)4 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)3 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 Pass (com.intellij.codeHighlighting.Pass)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 BranchActionGroup (com.intellij.dvcs.ui.BranchActionGroup)2 BranchActionGroupPopup.wrapWithMoreActionIfNeeded (com.intellij.dvcs.ui.BranchActionGroupPopup.wrapWithMoreActionIfNeeded)2 FAVORITE_BRANCH_COMPARATOR (com.intellij.dvcs.ui.BranchActionUtil.FAVORITE_BRANCH_COMPARATOR)2 BranchActionUtil.getNumOfTopShownBranches (com.intellij.dvcs.ui.BranchActionUtil.getNumOfTopShownBranches)2 AllIcons (com.intellij.icons.AllIcons)2 Group (com.intellij.openapi.keymap.impl.ui.Group)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 SimpleActionGroup (com.intellij.tools.SimpleActionGroup)2