Search in sources :

Example 1 with KeymapGroup

use of com.intellij.openapi.keymap.KeymapGroup 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 KeymapGroup

use of com.intellij.openapi.keymap.KeymapGroup in project intellij-community by JetBrains.

the class ToolWindowKeymapExtension method createGroup.

@Nullable
@Override
public KeymapGroup createGroup(Condition<AnAction> filtered, Project project) {
    String title = UIUtil.removeMnemonic(ActionsBundle.message("group.ToolWindowsGroup.text"));
    List<ActivateToolWindowAction> windowActions = project != null ? ToolWindowsGroup.getToolWindowActions(project, false) : Collections.emptyList();
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(title);
    for (AnAction action : windowActions) {
        ActionsTreeUtil.addAction(result, action, filtered);
    }
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with KeymapGroup

use of com.intellij.openapi.keymap.KeymapGroup in project intellij-community by JetBrains.

the class AntKeymapExtension method createGroup.

public KeymapGroup createGroup(final Condition<AnAction> filtered, Project project) {
    final Map<AntBuildFile, KeymapGroup> buildFileToGroup = new HashMap<>();
    final KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(KeyMapBundle.message("ant.targets.group.title"), AllIcons.Nodes.KeymapAnt);
    final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final String[] ids = actionManager.getActionIds(project != null ? AntConfiguration.getActionIdPrefix(project) : AntConfiguration.ACTION_ID_PREFIX);
    Arrays.sort(ids);
    if (project != null) {
        final AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
        ApplicationManager.getApplication().runReadAction(() -> {
            for (final String id : ids) {
                if (filtered != null && !filtered.value(actionManager.getActionOrStub(id))) {
                    continue;
                }
                final AntBuildFile buildFile = antConfiguration.findBuildFileByActionId(id);
                if (buildFile != null) {
                    KeymapGroup subGroup = buildFileToGroup.get(buildFile);
                    if (subGroup == null) {
                        subGroup = KeymapGroupFactory.getInstance().createGroup(buildFile.getPresentableName());
                        buildFileToGroup.put(buildFile, subGroup);
                        result.addGroup(subGroup);
                    }
                    subGroup.addActionId(id);
                } else {
                    LOG.info("no buildfile found for actionId=" + id);
                }
            }
        });
    }
    return result;
}
Also used : AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) HashMap(com.intellij.util.containers.HashMap) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 4 with KeymapGroup

use of com.intellij.openapi.keymap.KeymapGroup in project intellij-community by JetBrains.

the class ExternalSystemKeymapExtension method createGroup.

public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup);
    AnAction[] externalSystemActions = ActionsTreeUtil.getActions("ExternalSystem.Actions");
    for (AnAction action : externalSystemActions) {
        ActionsTreeUtil.addAction(result, action, condition);
    }
    if (project == null)
        return result;
    MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create();
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList());
    }
    ActionManager actionManager = ActionManager.getInstance();
    if (actionManager != null) {
        for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
            AnAction eachAction = actionManager.getAction(eachId);
            if (!(eachAction instanceof MyExternalSystemAction))
                continue;
            if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
                continue;
            MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction;
            projectToActionsMapping.putValue(taskAction.getSystemId(), eachId);
        }
    }
    Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap();
    for (ProjectSystemId systemId : projectToActionsMapping.keySet()) {
        if (!keymapGroupMap.containsKey(systemId)) {
            final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon();
            KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon);
            keymapGroupMap.put(systemId, group);
        }
    }
    for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) {
        Collection<String> tasks = each.getValue();
        final ProjectSystemId systemId = each.getKey();
        final KeymapGroup systemGroup = keymapGroupMap.get(systemId);
        if (systemGroup == null)
            continue;
        for (String actionId : tasks) {
            systemGroup.addActionId(actionId);
        }
        if (systemGroup instanceof Group) {
            Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
            ((Group) systemGroup).addHyperlink(new Hyperlink(icon, "Choose a task to assign a shortcut") {

                @Override
                public void onClick(MouseEvent e) {
                    SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project);
                    if (dialog.showAndGet() && dialog.getResult() != null) {
                        TaskData taskData = dialog.getResult().second;
                        String ownerModuleName = dialog.getResult().first;
                        ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData);
                        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(externalSystemAction.myId);
                        }
                    }
                }
            });
        }
    }
    for (KeymapGroup keymapGroup : keymapGroupMap.values()) {
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) {
        KeymapGroup keymapGroup = extension.createGroup(condition, project);
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) Settings(com.intellij.openapi.options.ex.Settings) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MouseEvent(java.awt.event.MouseEvent) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) SelectExternalTaskDialog(com.intellij.openapi.externalSystem.service.ui.SelectExternalTaskDialog) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 5 with KeymapGroup

use of com.intellij.openapi.keymap.KeymapGroup in project intellij-community by JetBrains.

the class BaseToolKeymapExtension method createGroup.

@Override
public KeymapGroup createGroup(final Condition<AnAction> filtered, final Project project) {
    final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    String[] ids = actionManager.getActionIds(getActionIdPrefix());
    Arrays.sort(ids);
    Group group = new Group(getGroupName(), AllIcons.Nodes.KeymapTools);
    HashMap<String, Group> toolGroupNameToGroup = new HashMap<>();
    for (String id : ids) {
        if (filtered != null && !filtered.value(actionManager.getActionOrStub(id)))
            continue;
        String groupName = getGroupByActionId(id);
        if (groupName != null && groupName.trim().length() == 0) {
            groupName = null;
        }
        Group subGroup = toolGroupNameToGroup.get(groupName);
        if (subGroup == null) {
            subGroup = new Group(groupName, null, null);
            toolGroupNameToGroup.put(groupName, subGroup);
            if (groupName != null) {
                group.addGroup(subGroup);
            }
        }
        subGroup.addActionId(id);
    }
    Group subGroup = toolGroupNameToGroup.get(null);
    if (subGroup != null) {
        group.addAll(subGroup);
    }
    return group;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) HashMap(com.intellij.util.containers.HashMap) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Aggregations

KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)8 Group (com.intellij.openapi.keymap.impl.ui.Group)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)2 Settings (com.intellij.openapi.options.ex.Settings)2 HashMap (com.intellij.util.containers.HashMap)2 MouseEvent (java.awt.event.MouseEvent)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 AllIcons (com.intellij.icons.AllIcons)1 DataManager (com.intellij.ide.DataManager)1 AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)1 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1 ExternalSystemKeymapExtension (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemKeymapExtension)1 SelectExternalTaskDialog (com.intellij.openapi.externalSystem.service.ui.SelectExternalTaskDialog)1 KeymapGroupFactory (com.intellij.openapi.keymap.KeymapGroupFactory)1 Hyperlink (com.intellij.openapi.keymap.impl.ui.Hyperlink)1