Search in sources :

Example 1 with Group

use of com.intellij.openapi.keymap.impl.ui.Group in project intellij-community by JetBrains.

the class MavenKeymapExtension method createGroup.

@Override
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(TasksBundle.message("maven.tasks.action.group.name"), MavenIcons.MavenLogo);
    if (project == null)
        return result;
    Comparator<MavenProject> projectComparator = (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
    Map<MavenProject, Set<Pair<String, String>>> projectToActionsMapping = new TreeMap<>(projectComparator);
    ActionManager actionManager = ActionManager.getInstance();
    //noinspection TestOnlyProblems
    for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
        AnAction eachAction = actionManager.getAction(eachId);
        if (!(eachAction instanceof MavenGoalAction))
            continue;
        if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
            continue;
        MavenGoalAction mavenAction = (MavenGoalAction) eachAction;
        MavenProject mavenProject = mavenAction.getMavenProject();
        Set<Pair<String, String>> actions = projectToActionsMapping.get(mavenProject);
        if (actions == null) {
            final List<String> projectGoals = collectGoals(mavenProject);
            actions = new TreeSet<>((o1, o2) -> {
                String goal1 = o1.getFirst();
                String goal2 = o2.getFirst();
                int index1 = projectGoals.indexOf(goal1);
                int index2 = projectGoals.indexOf(goal2);
                if (index1 == index2)
                    return goal1.compareToIgnoreCase(goal2);
                return (index1 < index2 ? -1 : 1);
            });
            projectToActionsMapping.put(mavenProject, actions);
        }
        actions.add(Pair.create(mavenAction.getGoal(), eachId));
    }
    for (Map.Entry<MavenProject, Set<Pair<String, String>>> each : projectToActionsMapping.entrySet()) {
        Set<Pair<String, String>> goalsToActionIds = each.getValue();
        for (Pair<String, String> eachGoalToActionId : goalsToActionIds) {
            result.addActionId(eachGoalToActionId.getSecond());
        }
    }
    Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
    ((Group) result).addHyperlink(new Hyperlink(icon, "Choose a phase/goal to assign a shortcut") {

        @Override
        public void onClick(MouseEvent e) {
            SelectMavenGoalDialog dialog = new SelectMavenGoalDialog(project);
            if (dialog.showAndGet() && dialog.getResult() != null) {
                MavenProjectsStructure.GoalNode goalNode = dialog.getResult();
                String goal = goalNode.getGoal();
                String actionId = MavenShortcutsManager.getInstance(project).getActionId(goalNode.getProjectPath(), goal);
                getOrRegisterAction(goalNode.getMavenProject(), actionId, goal);
                ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
                Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
                KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
                if (keymapPanel != null) {
                    // clear actions filter
                    keymapPanel.showOption("");
                    keymapPanel.selectAction(actionId);
                }
            }
        }
    });
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Settings(com.intellij.openapi.options.ex.Settings) KeymapGroupFactory(com.intellij.openapi.keymap.KeymapGroupFactory) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) SystemInfoRt(com.intellij.openapi.util.SystemInfoRt) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) KeymapListener(com.intellij.openapi.keymap.impl.ui.KeymapListener) MavenActionUtil(org.jetbrains.idea.maven.utils.actions.MavenActionUtil) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink) MavenRunConfigurationType(org.jetbrains.idea.maven.execution.MavenRunConfigurationType) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenPluginInfo(org.jetbrains.idea.maven.utils.MavenPluginInfo) ExternalSystemKeymapExtension(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemKeymapExtension) Project(com.intellij.openapi.project.Project) MavenConstants(org.jetbrains.idea.maven.model.MavenConstants) MavenProjectsStructure(org.jetbrains.idea.maven.navigator.MavenProjectsStructure) MavenIcons(icons.MavenIcons) DataManager(com.intellij.ide.DataManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters) MavenAction(org.jetbrains.idea.maven.utils.actions.MavenAction) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenArtifactUtil(org.jetbrains.idea.maven.utils.MavenArtifactUtil) TestOnly(org.jetbrains.annotations.TestOnly) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Settings(com.intellij.openapi.options.ex.Settings) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink)

Example 2 with Group

use of com.intellij.openapi.keymap.impl.ui.Group in project intellij-community by JetBrains.

the class PyCharmEduInitialConfigurator method patchMainMenu.

private static void patchMainMenu() {
    final CustomActionsSchema schema = new CustomActionsSchema();
    final JTree actionsTree = new Tree();
    Group rootGroup = new Group("root", null, null);
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup);
    DefaultTreeModel model = new DefaultTreeModel(root);
    actionsTree.setModel(model);
    schema.fillActionGroups(root);
    for (int i = 0; i < root.getChildCount(); i++) {
        final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) root.getChildAt(i);
        if ("Main menu".equals(getItemId(treeNode))) {
            hideActionFromMainMenu(root, schema, treeNode);
        }
        hideActions(schema, root, treeNode, HIDDEN_ACTIONS);
    }
    CustomActionsSchema.getInstance().copyFrom(schema);
}
Also used : DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CustomActionsSchema(com.intellij.ide.ui.customization.CustomActionsSchema) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint)

Example 3 with Group

use of com.intellij.openapi.keymap.impl.ui.Group 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)

Example 4 with Group

use of com.intellij.openapi.keymap.impl.ui.Group in project intellij-community by JetBrains.

the class CustomizableActionsPanel method findActionsUnderSelection.

private List<ActionUrl> findActionsUnderSelection() {
    final ArrayList<ActionUrl> actions = new ArrayList<>();
    final TreePath[] selectionPaths = myActionsTree.getSelectionPaths();
    if (selectionPaths != null) {
        for (TreePath path : selectionPaths) {
            final ActionUrl selectedUrl = CustomizationUtil.getActionUrl(path, ActionUrl.MOVE);
            final ArrayList<String> selectedGroupPath = new ArrayList<>(selectedUrl.getGroupPath());
            final Object component = selectedUrl.getComponent();
            if (component instanceof Group) {
                selectedGroupPath.add(((Group) component).getName());
                for (ActionUrl action : mySelectedSchema.getActions()) {
                    final ArrayList<String> groupPath = action.getGroupPath();
                    final int idx = Collections.indexOfSubList(groupPath, selectedGroupPath);
                    if (idx > -1) {
                        actions.add(action);
                    }
                }
            }
        }
    }
    return actions;
}
Also used : Group(com.intellij.openapi.keymap.impl.ui.Group) TreePath(javax.swing.tree.TreePath)

Example 5 with Group

use of com.intellij.openapi.keymap.impl.ui.Group in project intellij-community by JetBrains.

the class CustomizationUtil method getTreePath.

@Nullable
private static TreePath getTreePath(final int positionInPath, final List<String> path, final Object root) {
    if (!(root instanceof DefaultMutableTreeNode))
        return null;
    final DefaultMutableTreeNode treeNode = ((DefaultMutableTreeNode) root);
    final Object userObject = treeNode.getUserObject();
    final String pathElement;
    if (path.size() > positionInPath) {
        pathElement = path.get(positionInPath);
    } else {
        return null;
    }
    if (pathElement == null)
        return null;
    if (!(userObject instanceof Group))
        return null;
    if (!pathElement.equals(((Group) userObject).getName()))
        return null;
    TreePath currentPath = new TreePath(treeNode.getPath());
    if (positionInPath == path.size() - 1) {
        return currentPath;
    }
    for (int j = 0; j < treeNode.getChildCount(); j++) {
        final TreeNode child = treeNode.getChildAt(j);
        currentPath = getTreePath(positionInPath + 1, path, child);
        if (currentPath != null) {
            break;
        }
    }
    return currentPath;
}
Also used : Group(com.intellij.openapi.keymap.impl.ui.Group) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Group (com.intellij.openapi.keymap.impl.ui.Group)13 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)4 KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)4 TreePath (javax.swing.tree.TreePath)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Tree (com.intellij.ui.treeStructure.Tree)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 TreeNode (javax.swing.tree.TreeNode)2 AllIcons (com.intellij.icons.AllIcons)1 DataManager (com.intellij.ide.DataManager)1 CustomActionsSchema (com.intellij.ide.ui.customization.CustomActionsSchema)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Separator (com.intellij.openapi.actionSystem.Separator)1 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ExtensionPoint (com.intellij.openapi.extensions.ExtensionPoint)1 ExternalSystemKeymapExtension (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemKeymapExtension)1 KeymapGroupFactory (com.intellij.openapi.keymap.KeymapGroupFactory)1