Search in sources :

Example 1 with KeymapImpl

use of com.intellij.openapi.keymap.impl.KeymapImpl 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 2 with KeymapImpl

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

the class ActionsTreeTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // create dummy actions
    myActionWithoutTextAndDescription = new MyAction(null, null);
    myActionWithTextOnly = new MyAction("some text", null);
    myActionWithTextAndDescription = new MyAction("text", "description");
    myActionExistent = new MyAction("text", "description");
    myActionWithUseShortcutOfExistent = new MyAction("text", "description");
    myActionWithUseShortcutOfExistentRedefined = new MyAction("text", "description");
    myActionWithUseShortcutOfExistentRedefinedInParent = new MyAction("text", "description");
    myActionWithUseShortcutOfNonExistent = new MyAction("text", "description");
    myActionWithFixedShortcuts = new MyAction("text", "description");
    ActionManager actionManager = ActionManager.getInstance();
    actionManager.registerAction(ACTION_WITHOUT_TEXT_AND_DESCRIPTION, myActionWithoutTextAndDescription);
    actionManager.registerAction(ACTION_WITH_TEXT_ONLY, myActionWithTextOnly);
    actionManager.registerAction(ACTION_WITH_TEXT_AND_DESCRIPTION, myActionWithTextAndDescription);
    actionManager.registerAction(EXISTENT_ACTION, myActionExistent);
    actionManager.registerAction(ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION, myActionWithUseShortcutOfExistent);
    actionManager.registerAction(ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED, myActionWithUseShortcutOfExistentRedefined);
    actionManager.registerAction(ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED_IN_PARENT, myActionWithUseShortcutOfExistentRedefinedInParent);
    actionManager.registerAction(ACTION_WITH_USE_SHORTCUT_OF_NON_EXISTENT_ACTION, myActionWithUseShortcutOfNonExistent);
    actionManager.registerAction(ACTION_WITH_FIXED_SHORTCUTS, myActionWithFixedShortcuts);
    KeymapManagerEx.getInstanceEx().bindShortcuts(EXISTENT_ACTION, ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION);
    KeymapManagerEx.getInstanceEx().bindShortcuts(EXISTENT_ACTION, ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED);
    KeymapManagerEx.getInstanceEx().bindShortcuts(EXISTENT_ACTION, ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED_IN_PARENT);
    KeymapManagerEx.getInstanceEx().bindShortcuts(NON_EXISTENT_ACTION, ACTION_WITH_USE_SHORTCUT_OF_NON_EXISTENT_ACTION);
    mySavedRestrictions = ActionShortcutRestrictions.getInstance();
    setRestrictions(new ActionShortcutRestrictions() {

        @NotNull
        @Override
        public ShortcutRestrictions getForActionId(String actionId) {
            return ACTION_WITH_FIXED_SHORTCUTS.equals(actionId) ? new ShortcutRestrictions(false, false, false, false, false, false) : ShortcutRestrictions.NO_RESTRICTIONS;
        }
    });
    assertEquals("$Delete", KeymapManagerEx.getInstanceEx().getActionBinding(ACTION_EDITOR_DELETE_WITH_SHORTCUT));
    assertEquals("$Cut", KeymapManagerEx.getInstanceEx().getActionBinding(ACTION_EDITOR_CUT_WITHOUT_SHORTCUT));
    assertNotNull(actionManager.getAction(ACTION_EDITOR_DELETE_WITH_SHORTCUT));
    assertNotNull(actionManager.getAction(ACTION_EDITOR_CUT_WITHOUT_SHORTCUT));
    DefaultActionGroup group = (DefaultActionGroup) actionManager.getAction(IdeActions.GROUP_EDITOR);
    group.addAll(myActionWithoutTextAndDescription, myActionWithTextOnly, myActionWithTextAndDescription, myActionExistent, myActionWithUseShortcutOfExistent, myActionWithUseShortcutOfExistentRedefined, myActionWithUseShortcutOfExistentRedefinedInParent, myActionWithUseShortcutOfNonExistent, myActionWithFixedShortcuts);
    // populate action tree
    myActionsTree = new ActionsTree();
    KeyboardShortcut shortcut1 = new KeyboardShortcut(KeyStroke.getKeyStroke('1'), null);
    KeyboardShortcut shortcut2 = new KeyboardShortcut(KeyStroke.getKeyStroke('2'), null);
    KeymapImpl parent = new KeymapImpl();
    parent.addShortcut(ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED_IN_PARENT, shortcut1);
    parent.setName("parent");
    parent.setCanModify(false);
    KeymapImpl child = parent.deriveKeymap("child");
    child.addShortcut(ACTION_WITH_USE_SHORTCUT_OF_EXISTENT_ACTION_REDEFINED, shortcut2);
    child.addShortcut(ACTION_EDITOR_DELETE_WITH_SHORTCUT, shortcut2);
    myActionsTree.reset(child, new QuickList[0]);
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) ActionShortcutRestrictions(com.intellij.openapi.keymap.impl.ActionShortcutRestrictions) ShortcutRestrictions(com.intellij.openapi.keymap.impl.ShortcutRestrictions) NotNull(org.jetbrains.annotations.NotNull) ActionShortcutRestrictions(com.intellij.openapi.keymap.impl.ActionShortcutRestrictions)

Example 3 with KeymapImpl

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

the class KeymapPanel method createEditActionGroup.

@NotNull
private DefaultActionGroup createEditActionGroup(@NotNull final String actionId) {
    DefaultActionGroup group = new DefaultActionGroup();
    final ShortcutRestrictions restrictions = ActionShortcutRestrictions.getInstance().getForActionId(actionId);
    if (restrictions.allowKeyboardShortcut) {
        group.add(new DumbAwareAction("Add Keyboard Shortcut") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymapSelected = myEditor.getModel().getSelected();
                assert keymapSelected != null;
                addKeyboardShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (restrictions.allowMouseShortcut) {
        group.add(new DumbAwareAction("Add Mouse Shortcut") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymapSelected = myEditor.getModel().getSelected();
                assert keymapSelected != null;
                addMouseShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (Registry.is("actionSystem.enableAbbreviations") && restrictions.allowAbbreviation) {
        group.add(new DumbAwareAction("Add Abbreviation") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                String abbr = Messages.showInputDialog("Enter new abbreviation:", "Abbreviation", null);
                if (abbr != null) {
                    AbbreviationManager.getInstance().register(abbr, myActionsTree.getSelectedActionId());
                    repaintLists();
                }
            }

            @Override
            public void update(@NotNull AnActionEvent e) {
                e.getPresentation().setEnabledAndVisible(myActionsTree.getSelectedActionId() != null);
            }
        });
    }
    group.addSeparator();
    Keymap keymap = myEditor.getModel().getSelected();
    assert keymap != null;
    for (final Shortcut shortcut : keymap.getShortcuts(actionId)) {
        group.add(new DumbAwareAction("Remove " + KeymapUtil.getShortcutText(shortcut)) {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymap = createKeymapCopyIfNeeded();
                keymap.removeShortcut(actionId, shortcut);
                if (StringUtil.startsWithChar(actionId, '$')) {
                    keymap.removeShortcut(KeyMapBundle.message("editor.shortcut", actionId.substring(1)), shortcut);
                }
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (Registry.is("actionSystem.enableAbbreviations")) {
        for (final String abbreviation : AbbreviationManager.getInstance().getAbbreviations(actionId)) {
            group.addAction(new DumbAwareAction("Remove Abbreviation '" + abbreviation + "'") {

                @Override
                public void actionPerformed(@NotNull AnActionEvent e) {
                    AbbreviationManager.getInstance().remove(abbreviation, actionId);
                    repaintLists();
                }
            });
        }
    }
    group.add(new Separator());
    group.add(new DumbAwareAction("Reset Shortcuts") {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            ((KeymapImpl) createKeymapCopyIfNeeded()).clearOwnActionsId(actionId);
            currentKeymapChanged();
            repaintLists();
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setVisible(((KeymapImpl) myEditor.getModel().getSelected()).hasOwnActionId(actionId));
        }
    });
    return group;
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) ActionShortcutRestrictions(com.intellij.openapi.keymap.impl.ActionShortcutRestrictions) ShortcutRestrictions(com.intellij.openapi.keymap.impl.ShortcutRestrictions) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with KeymapImpl

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

the class KeymapPanel method copyKeymap.

private void copyKeymap() {
    Keymap keymap = myEditor.getModel().getSelected();
    if (keymap == null) {
        return;
    }
    String newKeymapName = KeyMapBundle.message("new.keymap.name", keymap.getPresentableName());
    if (!tryNewKeymapName(newKeymapName)) {
        for (int i = 0; ; i++) {
            newKeymapName = KeyMapBundle.message("new.indexed.keymap.name", keymap.getPresentableName(), i);
            if (tryNewKeymapName(newKeymapName)) {
                break;
            }
        }
    }
    KeymapImpl newKeymap = ((KeymapImpl) keymap).deriveKeymap(newKeymapName);
    newKeymap.setCanModify(true);
    myEditor.getModel().add(newKeymap);
    myEditor.getModel().setSelectedItem(newKeymap);
    myEditor.getComboBox().getEditor().selectAll();
    currentKeymapChanged();
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 5 with KeymapImpl

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

the class KeymapPanel method reset.

@Override
public void reset() {
    if (myNonEnglishKeyboardSupportOption != null) {
        myNonEnglishKeyboardSupportOption.setSelected(KeyboardSettingsExternalizable.getInstance().isNonEnglishKeyboardSupportEnabled());
    }
    Keymap activeKeymap = KeymapManagerEx.getInstanceEx().getActiveKeymap();
    Keymap selectedKeymap = null;
    List<Keymap> list = getManagerKeymaps();
    for (Keymap keymap : list) {
        if (activeKeymap == keymap) {
            // select active keymap if it is present
            selectedKeymap = keymap;
            break;
        }
        if (selectedKeymap == null || KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP.equals(keymap.getName())) {
            // select MacOS X keymap if default keymap is filtered out
            // select first keymap if MacOS X keymap is not present
            selectedKeymap = keymap;
        }
    }
    myEditor.reset(list);
    if (myEditor.getModel().isEmpty()) {
        KeymapImpl keymap = new KeymapImpl();
        keymap.setName(KeyMapBundle.message("keymap.no.name"));
        myEditor.getModel().add(keymap);
        selectedKeymap = keymap;
    }
    myEditor.getModel().setSelectedItem(selectedKeymap);
    currentKeymapChanged();
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl)

Aggregations

KeymapImpl (com.intellij.openapi.keymap.impl.KeymapImpl)7 NotNull (org.jetbrains.annotations.NotNull)3 ActionShortcutRestrictions (com.intellij.openapi.keymap.impl.ActionShortcutRestrictions)2 ShortcutRestrictions (com.intellij.openapi.keymap.impl.ShortcutRestrictions)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 Keymap (com.intellij.openapi.keymap.Keymap)1 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1