Search in sources :

Example 1 with KeymapManagerEx

use of com.intellij.openapi.keymap.ex.KeymapManagerEx in project intellij-plugins by StepicOrg.

the class StudyProjectComponent method addShortcut.

private void addShortcut(@NotNull final String actionIdString, @NotNull final String[] shortcuts) {
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        List<Pair<String, String>> pairs = deletedShortcuts.computeIfAbsent(keymap, k -> new ArrayList<>());
        for (String shortcutString : shortcuts) {
            Shortcut studyActionShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
            String[] actionsIds = keymap.getActionIds(studyActionShortcut);
            for (String actionId : actionsIds) {
                pairs.add(Pair.create(actionId, shortcutString));
                keymap.removeShortcut(actionId, studyActionShortcut);
            }
            keymap.addShortcut(actionIdString, studyActionShortcut);
        }
    }
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) StudyActionWithShortcut(org.stepik.core.actions.StudyActionWithShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) Pair(com.intellij.openapi.util.Pair)

Example 2 with KeymapManagerEx

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

the class StudyProjectComponent method addShortcut.

private void addShortcut(@NotNull final String actionIdString, @NotNull final String[] shortcuts) {
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        List<Pair<String, String>> pairs = myDeletedShortcuts.get(keymap);
        if (pairs == null) {
            pairs = new ArrayList<>();
            myDeletedShortcuts.put(keymap, pairs);
        }
        for (String shortcutString : shortcuts) {
            Shortcut studyActionShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
            String[] actionsIds = keymap.getActionIds(studyActionShortcut);
            for (String actionId : actionsIds) {
                pairs.add(Pair.create(actionId, shortcutString));
                keymap.removeShortcut(actionId, studyActionShortcut);
            }
            keymap.addShortcut(actionIdString, studyActionShortcut);
        }
    }
}
Also used : StudyActionWithShortcut(com.jetbrains.edu.learning.actions.StudyActionWithShortcut) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) Pair(com.intellij.openapi.util.Pair)

Example 3 with KeymapManagerEx

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

the class PyCharmEduInitialConfigurator method patchKeymap.

private static void patchKeymap() {
    Set<String> droppedActions = ContainerUtil.newHashSet("AddToFavoritesPopup", "DatabaseView.ImportDataSources", "CompileDirty", "Compile", // hidden
    "AddNewFavoritesList", "EditFavorites", "RenameFavoritesList", "RemoveFavoritesList");
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        if (keymap.canModify())
            continue;
        KeymapImpl keymapImpl = (KeymapImpl) keymap;
        for (String id : keymapImpl.getOwnActionIds()) {
            if (droppedActions.contains(id))
                keymapImpl.clearOwnActionsId(id);
        }
    }
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap)

Example 4 with KeymapManagerEx

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

the class KeyGroup method getKeymapConflicts.

@NotNull
public List<AnAction> getKeymapConflicts(@NotNull KeyStroke keyStroke) {
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    final Keymap keymap = keymapManager.getActiveKeymap();
    final KeyboardShortcut shortcut = new KeyboardShortcut(keyStroke, null);
    final Map<String, ? extends List<KeyboardShortcut>> conflicts = keymap.getConflicts("", shortcut);
    final List<AnAction> actions = new ArrayList<AnAction>();
    for (String actionId : conflicts.keySet()) {
        final AnAction action = ActionManagerEx.getInstanceEx().getAction(actionId);
        if (action != null) {
            actions.add(action);
        }
    }
    return actions;
}
Also used : KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with KeymapManagerEx

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

the class VimPlugin method updateState.

private void updateState() {
    if (isEnabled() && !ApplicationManager.getApplication().isUnitTestMode()) {
        if (SystemInfo.isMac) {
            final MacKeyRepeat keyRepeat = MacKeyRepeat.getInstance();
            final Boolean enabled = keyRepeat.isEnabled();
            final Boolean isKeyRepeat = editor.isKeyRepeat();
            if ((enabled == null || !enabled) && (isKeyRepeat == null || isKeyRepeat)) {
                if (Messages.showYesNoDialog("Do you want to enable repeating keys in Mac OS X on press and hold?\n\n" + "(You can do it manually by running 'defaults write -g " + "ApplePressAndHoldEnabled 0' in the console).", IDEAVIM_NOTIFICATION_TITLE, Messages.getQuestionIcon()) == Messages.YES) {
                    editor.setKeyRepeat(true);
                    keyRepeat.setEnabled(true);
                } else {
                    editor.setKeyRepeat(false);
                }
            }
        }
        if (previousStateVersion > 0 && previousStateVersion < 3) {
            final KeymapManagerEx manager = KeymapManagerEx.getInstanceEx();
            Keymap keymap = null;
            if (previousKeyMap != null) {
                keymap = manager.getKeymap(previousKeyMap);
            }
            if (keymap == null) {
                keymap = manager.getKeymap(DefaultKeymap.getInstance().getDefaultKeymapName());
            }
            assert keymap != null : "Default keymap not found";
            new Notification(VimPlugin.IDEAVIM_STICKY_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, String.format("IdeaVim plugin doesn't use the special \"Vim\" keymap any longer. " + "Switching to \"%s\" keymap.<br/><br/>" + "Now it is possible to set up:<br/>" + "<ul>" + "<li>Vim keys in your ~/.ideavimrc file using key mapping commands</li>" + "<li>IDE action shortcuts in \"File | Settings | Keymap\"</li>" + "<li>Vim or IDE handlers for conflicting shortcuts in <a href='#settings'>Vim Emulation</a> settings</li>" + "</ul>", keymap.getPresentableName()), NotificationType.INFORMATION, new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().editConfigurable((Project) null, new VimEmulationConfigurable());
                }
            }).notify(null);
            manager.setActiveKeymap(keymap);
        }
        if (previousStateVersion > 0 && previousStateVersion < 4) {
            new Notification(VimPlugin.IDEAVIM_STICKY_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, "The ~/.vimrc file is no longer read by default, use ~/.ideavimrc instead. You can read it from your " + "~/.ideavimrc using this command:<br/><br/>" + "<code>source ~/.vimrc</code>", NotificationType.INFORMATION).notify(null);
        }
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MacKeyRepeat(com.maddyhome.idea.vim.helper.MacKeyRepeat) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) VimEmulationConfigurable(com.maddyhome.idea.vim.ui.VimEmulationConfigurable) NotNull(org.jetbrains.annotations.NotNull) Keymap(com.intellij.openapi.keymap.Keymap) DefaultKeymap(com.intellij.openapi.keymap.impl.DefaultKeymap)

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