Search in sources :

Example 6 with ActionGroup

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

the class ActionUrl method readExternal.

@Override
public void readExternal(Element element) throws InvalidDataException {
    myGroupPath = new ArrayList<>();
    for (Object o : element.getChildren(PATH)) {
        myGroupPath.add(((Element) o).getAttributeValue(VALUE));
    }
    final String attributeValue = element.getAttributeValue(VALUE);
    if (element.getAttributeValue(IS_ACTION) != null) {
        myComponent = attributeValue;
    } else if (element.getAttributeValue(SEPARATOR) != null) {
        myComponent = Separator.getInstance();
    } else if (element.getAttributeValue(IS_GROUP) != null) {
        final AnAction action = ActionManager.getInstance().getAction(attributeValue);
        myComponent = action instanceof ActionGroup ? ActionsTreeUtil.createGroup((ActionGroup) action, true, null) : new Group(attributeValue, attributeValue, null);
    }
    myActionType = Integer.parseInt(element.getAttributeValue(ACTION_TYPE));
    myAbsolutePosition = Integer.parseInt(element.getAttributeValue(POSITION));
    DefaultJDOMExternalizer.readExternal(this, element);
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 7 with ActionGroup

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

the class NewRecentProjectPanel method createList.

@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
    final JBList list = super.createList(recentProjectActions, size);
    list.setBackground(FlatWelcomeFrame.getProjectsBackground());
    list.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            Object selected = list.getSelectedValue();
            final ProjectGroup group;
            if (selected instanceof ProjectGroupActionGroup) {
                group = ((ProjectGroupActionGroup) selected).getGroup();
            } else {
                group = null;
            }
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_RIGHT) {
                if (group != null) {
                    if (!group.isExpanded()) {
                        group.setExpanded(true);
                        ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                        int index = list.getSelectedIndex();
                        RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                        list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
                    }
                } else {
                    FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
                    if (frame != null) {
                        FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
                        if (policy != null) {
                            Component next = policy.getComponentAfter(frame, list);
                            if (next != null) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(next, true);
                                });
                            }
                        }
                    }
                }
            } else if (keyCode == KeyEvent.VK_LEFT) {
                if (group != null && group.isExpanded()) {
                    group.setExpanded(false);
                    int index = list.getSelectedIndex();
                    ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                    RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                    list.setSelectedIndex(index);
                }
            }
        }
    });
    list.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int index = list.locationToIndex(new Point(x, y));
            if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
                list.setSelectedIndex(index);
            }
            final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
            if (group != null) {
                ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
            }
        }
    });
    return list;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) JBList(com.intellij.ui.components.JBList)

Example 8 with ActionGroup

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

the class GitBranchPopupActions method createActions.

ActionGroup createActions(@Nullable DefaultActionGroup toInsert, @NotNull String repoInfo, boolean firstLevelGroup) {
    DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
    List<GitRepository> repositoryList = Collections.singletonList(myRepository);
    popupGroup.addAction(new GitNewBranchAction(myProject, repositoryList));
    popupGroup.addAction(new CheckoutRevisionActions(myProject, repositoryList));
    if (toInsert != null) {
        popupGroup.addAll(toInsert);
    }
    popupGroup.addSeparator("Local Branches" + repoInfo);
    List<BranchActionGroup> localBranchActions = myRepository.getBranches().getLocalBranches().stream().sorted().filter(branch -> !branch.equals(myRepository.getCurrentBranch())).map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository)).collect(toList());
    // if there are only a few local favorites -> show all;  for remotes it's better to show only favorites; 
    wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null, firstLevelGroup);
    popupGroup.addSeparator("Remote Branches" + repoInfo);
    List<BranchActionGroup> remoteBranchActions = myRepository.getBranches().getRemoteBranches().stream().sorted().map(remoteBranch -> new RemoteBranchActions(myProject, repositoryList, remoteBranch.getName(), myRepository)).collect(toList());
    wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(remoteBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(remoteBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_REMOTES_KEY : null);
    return popupGroup;
}
Also used : BranchActionGroupPopup.wrapWithMoreActionIfNeeded(com.intellij.dvcs.ui.BranchActionGroupPopup.wrapWithMoreActionIfNeeded) ContainerUtil(com.intellij.util.containers.ContainerUtil) GitBranchUtil(git4idea.branch.GitBranchUtil) GitNewBranchOptions(git4idea.branch.GitNewBranchOptions) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) GitStatisticsCollectorKt.reportUsage(git4idea.GitStatisticsCollectorKt.reportUsage) GitRepository(git4idea.repo.GitRepository) BranchActionGroup(com.intellij.dvcs.ui.BranchActionGroup) HEAD(git4idea.GitUtil.HEAD) PopupElementWithAdditionalInfo(com.intellij.dvcs.ui.PopupElementWithAdditionalInfo) GitBrancher(git4idea.branch.GitBrancher) AnAction(com.intellij.openapi.actionSystem.AnAction) BranchActionUtil.getNumOfTopShownBranches(com.intellij.dvcs.ui.BranchActionUtil.getNumOfTopShownBranches) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) GitNewBranchNameValidator(git4idea.validators.GitNewBranchNameValidator) LOCAL(git4idea.branch.GitBranchType.LOCAL) Nullable(org.jetbrains.annotations.Nullable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ServiceManager(com.intellij.openapi.components.ServiceManager) NewBranchAction(com.intellij.dvcs.ui.NewBranchAction) StreamEx(one.util.streamex.StreamEx) REMOTE(git4idea.branch.GitBranchType.REMOTE) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) NotNull(org.jetbrains.annotations.NotNull) FAVORITE_BRANCH_COMPARATOR(com.intellij.dvcs.ui.BranchActionUtil.FAVORITE_BRANCH_COMPARATOR) Collections(java.util.Collections) GitRepository(git4idea.repo.GitRepository) BranchActionGroup(com.intellij.dvcs.ui.BranchActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 9 with ActionGroup

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

the class GradleToolWindowPanel method initContent.

public void initContent() {
    final ActionManager actionManager = ActionManager.getInstance();
    final ActionGroup actionGroup = (ActionGroup) actionManager.getAction(TOOL_WINDOW_TOOLBAR_ID);
    ActionToolbar actionToolbar = actionManager.createActionToolbar(myPlace, actionGroup, true);
    JPanel toolbarControl = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.weightx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    toolbarControl.add(actionToolbar.getComponent(), constraints);
    for (JComponent component : getToolbarControls()) {
        component.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
        toolbarControl.add(component, constraints);
    }
    setToolbar(toolbarControl);
    final JComponent payloadControl = buildContent();
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(payloadControl);
    JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    myContent.add(scrollPane, CONTENT_CARD_NAME);
    RichTextControlBuilder builder = new RichTextControlBuilder();
    builder.setBackgroundColor(payloadControl.getBackground());
    builder.setForegroundColor(UIUtil.getInactiveTextColor());
    builder.setFont(payloadControl.getFont());
    builder.setText(GradleBundle.message("gradle.toolwindow.text.no.linked.project"));
    final JComponent noLinkedProjectControl = builder.build();
    myContent.add(noLinkedProjectControl, NON_LINKED_CARD_NAME);
    update();
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) RichTextControlBuilder(org.jetbrains.plugins.gradle.ui.RichTextControlBuilder) ActionToolbar(com.intellij.openapi.actionSystem.ActionToolbar)

Example 10 with ActionGroup

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

the class RunLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
    Icon icon = null;
    List<Info> infos = null;
    for (RunLineMarkerContributor contributor : contributors) {
        Info info = contributor.getInfo(element);
        if (info == null) {
            continue;
        }
        if (icon == null) {
            icon = info.icon;
        }
        if (infos == null) {
            infos = new SmartList<>();
        }
        infos.add(info);
    }
    if (icon == null)
        return null;
    if (infos.size() > 1) {
        Collections.sort(infos, COMPARATOR);
        final Info first = infos.get(0);
        for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
            Info info = it.next();
            if (info != first && first.shouldReplace(info)) {
                it.remove();
            }
        }
    }
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (Info info : infos) {
        for (AnAction action : info.actions) {
            actionGroup.add(new LineMarkerActionWrapper(element, action));
        }
        if (info != infos.get(infos.size() - 1)) {
            actionGroup.add(new Separator());
        }
    }
    List<Info> finalInfos = infos;
    Function<PsiElement, String> tooltipProvider = element1 -> {
        final StringBuilder tooltip = new StringBuilder();
        for (Info info : finalInfos) {
            if (info.tooltipProvider != null) {
                String string = info.tooltipProvider.apply(element1);
                if (string == null)
                    continue;
                if (tooltip.length() != 0) {
                    tooltip.append("\n");
                }
                tooltip.append(string);
            }
        }
        return tooltip.length() == 0 ? null : tooltip.toString();
    };
    return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {

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

                @Override
                public AnAction getClickAction() {
                    return null;
                }

                @Override
                public boolean isNavigateAction() {
                    return true;
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    return actionGroup;
                }
            };
        }
    };
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) LineMarkerProviderDescriptor(com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor) Nullable(org.jetbrains.annotations.Nullable) SmartList(com.intellij.util.SmartList) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) javax.swing(javax.swing) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)30 AnAction (com.intellij.openapi.actionSystem.AnAction)8 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)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 ArrayList (java.util.ArrayList)2