Search in sources :

Example 6 with KeymapManagerEx

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

the class ActionsTreeUtil method createOtherGroup.

@NotNull
private static Group createOtherGroup(@Nullable Condition<AnAction> filtered, Group addedActions, @Nullable Keymap keymap) {
    addedActions.initIds();
    Set<String> result = new THashSet<>();
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (keymap != null) {
        for (String id : keymap.getActionIdList()) {
            if (id.startsWith(EDITOR_PREFIX) && actionManager.getActionOrStub("$" + id.substring(6)) != null) {
                continue;
            }
            if (!id.startsWith(QuickList.QUICK_LIST_PREFIX) && !addedActions.containsId(id)) {
                result.add(id);
            }
        }
    }
    // add all registered actions
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    String[] registeredActionIds = actionManager.getActionIds("");
    for (String id : registeredActionIds) {
        final AnAction actionOrStub = actionManager.getActionOrStub(id);
        if (actionOrStub instanceof ActionGroup && !((ActionGroup) actionOrStub).canBePerformed(DataManager.getInstance().getDataContext())) {
            continue;
        }
        if (id.startsWith(QuickList.QUICK_LIST_PREFIX) || addedActions.containsId(id) || result.contains(id) || keymapManager.getBoundActions().contains(id)) {
            continue;
        }
        result.add(id);
    }
    filterOtherActionsGroup(result);
    Group group = new Group(KeyMapBundle.message("other.group.title"), AllIcons.Nodes.KeymapOther);
    AnAction[] groupedActions = getActions("Other.KeymapGroup");
    for (AnAction action : groupedActions) {
        addAction(group, action, filtered);
    }
    result.removeAll(group.initIds());
    for (String id : ContainerUtil.sorted(result, (id1, id2) -> getTextToCompare(id1).compareToIgnoreCase(getTextToCompare(id2)))) {
        if (filtered == null || filtered.value(actionManager.getActionOrStub(id)))
            group.addActionId(id);
    }
    return group;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) THashSet(gnu.trove.THashSet) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with KeymapManagerEx

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

the class KeymapsTestCase method removeBoundActionIds.

private static void removeBoundActionIds(@NotNull Set<String> aids) {
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    // explicitly bound to another action
    for (Iterator<String> it = aids.iterator(); it.hasNext(); ) {
        String id = it.next();
        String sourceId = keymapManager.getActionBinding(id);
        if (sourceId != null) {
            it.remove();
        }
    }
}
Also used : KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx)

Example 8 with KeymapManagerEx

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

the class AntToolwindowRegistrar method projectOpened.

@Override
public void projectOpened() {
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    final String prefix = AntConfiguration.getActionIdPrefix(myProject);
    final ActionManager actionManager = ActionManager.getInstance();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        for (String id : keymap.getActionIdList()) {
            if (id.startsWith(prefix) && actionManager.getAction(id) == null) {
                actionManager.registerAction(id, new TargetActionStub(id, myProject));
            }
        }
    }
    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    compilerManager.addBeforeTask(new CompileTask() {

        @Override
        public boolean execute(CompileContext context) {
            final AntConfiguration config = AntConfiguration.getInstance(myProject);
            ((AntConfigurationBase) config).ensureInitialized();
            return config.executeTargetBeforeCompile(createDataContext(context));
        }
    });
    compilerManager.addAfterTask(new CompileTask() {

        @Override
        public boolean execute(CompileContext context) {
            final AntConfigurationBase config = (AntConfigurationBase) AntConfiguration.getInstance(myProject);
            config.ensureInitialized();
            if (context.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
                final AntBuildTarget target = config.getTargetForEvent(ExecuteAfterCompilationEvent.getInstance());
                if (target != null) {
                    context.addMessage(CompilerMessageCategory.INFORMATION, "Skipping ant target \"" + target.getDisplayName() + "\" because of compilation errors", null, -1, -1);
                }
                return true;
            }
            return config.executeTargetAfterCompile(createDataContext(context));
        }
    });
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) TargetActionStub(com.intellij.lang.ant.config.actions.TargetActionStub) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget) Keymap(com.intellij.openapi.keymap.Keymap) AntConfigurationBase(com.intellij.lang.ant.config.AntConfigurationBase)

Example 9 with KeymapManagerEx

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

the class QuickChangeKeymapAction method fillActions.

@Override
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
    KeymapManagerEx manager = (KeymapManagerEx) KeymapManager.getInstance();
    Keymap current = manager.getActiveKeymap();
    for (Keymap keymap : manager.getAllKeymaps()) {
        addKeymapAction(group, manager, current, keymap, false);
    }
}
Also used : KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap)

Example 10 with KeymapManagerEx

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

the class ActionsTreeUtil method createPluginsActionsGroup.

private static Group createPluginsActionsGroup(Condition<AnAction> filtered) {
    Group pluginsGroup = new Group(KeyMapBundle.message("plugins.group.title"), null, null);
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    ActionManagerEx managerEx = ActionManagerEx.getInstanceEx();
    final List<IdeaPluginDescriptor> plugins = new ArrayList<>();
    Collections.addAll(plugins, PluginManagerCore.getPlugins());
    Collections.sort(plugins, Comparator.comparing(IdeaPluginDescriptor::getName));
    List<PluginId> collected = new ArrayList<>();
    for (IdeaPluginDescriptor plugin : plugins) {
        collected.add(plugin.getPluginId());
        Group pluginGroup;
        if (plugin.getName().equals("IDEA CORE")) {
            continue;
        } else {
            pluginGroup = new Group(plugin.getName(), null, null);
        }
        final String[] pluginActions = managerEx.getPluginActions(plugin.getPluginId());
        if (pluginActions.length == 0) {
            continue;
        }
        Arrays.sort(pluginActions, Comparator.comparing(ActionsTreeUtil::getTextToCompare));
        for (String pluginAction : pluginActions) {
            if (keymapManager.getBoundActions().contains(pluginAction))
                continue;
            final AnAction anAction = managerEx.getActionOrStub(pluginAction);
            if (filtered == null || filtered.value(anAction)) {
                pluginGroup.addActionId(pluginAction);
            }
        }
        if (pluginGroup.getSize() > 0) {
            pluginsGroup.addGroup(pluginGroup);
        }
    }
    for (PluginId pluginId : PluginId.getRegisteredIds().values()) {
        if (collected.contains(pluginId))
            continue;
        Group pluginGroup = new Group(pluginId.getIdString(), null, null);
        final String[] pluginActions = managerEx.getPluginActions(pluginId);
        if (pluginActions.length == 0) {
            continue;
        }
        for (String pluginAction : pluginActions) {
            if (keymapManager.getBoundActions().contains(pluginAction))
                continue;
            final AnAction anAction = managerEx.getActionOrStub(pluginAction);
            if (filtered == null || filtered.value(anAction)) {
                pluginGroup.addActionId(pluginAction);
            }
        }
        if (pluginGroup.getSize() > 0) {
            pluginsGroup.addGroup(pluginGroup);
        }
    }
    return pluginsGroup;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Aggregations

KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)12 Keymap (com.intellij.openapi.keymap.Keymap)9 Pair (com.intellij.openapi.util.Pair)4 NotNull (org.jetbrains.annotations.NotNull)3 KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)2 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)2 KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)2 ToolWindow (com.intellij.openapi.wm.ToolWindow)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 AntBuildTarget (com.intellij.lang.ant.config.AntBuildTarget)1 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)1 AntConfigurationBase (com.intellij.lang.ant.config.AntConfigurationBase)1 TargetActionStub (com.intellij.lang.ant.config.actions.TargetActionStub)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 Shortcut (com.intellij.openapi.actionSystem.Shortcut)1 EditorFactoryAdapter (com.intellij.openapi.editor.event.EditorFactoryAdapter)1 PluginId (com.intellij.openapi.extensions.PluginId)1 DefaultKeymap (com.intellij.openapi.keymap.impl.DefaultKeymap)1 KeymapImpl (com.intellij.openapi.keymap.impl.KeymapImpl)1 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)1