Search in sources :

Example 11 with KeyboardShortcut

use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.

the class KeymapsTestCase method checkDuplicatesInKeymap.

@NotNull
@SuppressWarnings({ "HardCodedStringLiteral" })
private static String checkDuplicatesInKeymap(@NotNull KeymapImpl keymap, @NotNull Map<String, Map<String, List<String>>> allKnownDuplicates) {
    Set<String> aids = keymap.getActionIdList();
    removeBoundActionIds(aids);
    Set<Shortcut> shortcuts = new THashSet<>();
    nextId: for (String id : aids) {
        Map<String, List<String>> knownDuplicates = allKnownDuplicates.get(keymap.getName());
        if (knownDuplicates != null) {
            for (List<String> actionsMapping : knownDuplicates.values()) {
                if (actionsMapping.contains(id)) {
                    continue nextId;
                }
            }
        }
        for (Shortcut shortcut : keymap.getShortcuts(id)) {
            if (shortcut instanceof KeyboardShortcut) {
                shortcuts.add(shortcut);
            }
        }
    }
    List<Shortcut> sorted = new ArrayList<>(shortcuts);
    Collections.sort(sorted, Comparator.comparing(KeymapsTestCase::getText));
    if (OUTPUT_TEST_DATA) {
        System.out.println("put(\"" + keymap.getName() + "\", new String[][] {");
    } else {
        System.out.println(keymap.getName());
    }
    StringBuilder failMessage = new StringBuilder();
    for (Shortcut shortcut : sorted) {
        if (!(shortcut instanceof KeyboardShortcut)) {
            continue;
        }
        Set<String> ids = new THashSet<>(Arrays.asList(keymap.getActionIds(shortcut)));
        removeBoundActionIds(ids);
        if (ids.size() == 1) {
            continue;
        }
        Keymap parent = keymap.getParent();
        if (parent != null) {
            // ignore duplicates from default keymap
            boolean differFromParent = false;
            for (String id : ids) {
                Shortcut[] here = keymap.getShortcuts(id);
                Shortcut[] there = parent.getShortcuts(id);
                if (keymap.getName().startsWith("Mac")) {
                    convertMac(there);
                }
                if (!new THashSet<>(Arrays.asList(here)).equals(new THashSet<>(Arrays.asList(there)))) {
                    differFromParent = true;
                    break;
                }
            }
            if (!differFromParent)
                continue;
        }
        String def = "{ " + "\"" + getText(shortcut) + "\"," + StringUtil.repeatSymbol(' ', 25 - getText(shortcut).length()) + StringUtil.join(ids, StringUtil.QUOTER, ", ") + "},";
        if (OUTPUT_TEST_DATA) {
            System.out.println(def);
        } else {
            if (failMessage.length() == 0) {
                failMessage.append("Shortcut '").append(getText(shortcut)).append("' conflicts found in keymap '").append(keymap.getName()).append("':\n");
            }
            failMessage.append(def).append("\n");
        }
    }
    if (OUTPUT_TEST_DATA) {
        System.out.println("});");
    }
    return failMessage.toString();
}
Also used : THashSet(gnu.trove.THashSet) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) THashMap(gnu.trove.THashMap) FactoryMap(com.intellij.util.containers.FactoryMap) MacOSDefaultKeymap(com.intellij.openapi.keymap.impl.MacOSDefaultKeymap) Keymap(com.intellij.openapi.keymap.Keymap) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with KeyboardShortcut

use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-plugins by StepicOrg.

the class StudyProjectComponent method projectClosed.

@Override
public void projectClosed() {
    if (!StepikProjectManager.isStepikProject(project)) {
        return;
    }
    final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
    if (toolWindow != null) {
        toolWindow.getContentManager().removeAllContents(false);
    }
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        List<Pair<String, String>> pairs = deletedShortcuts.get(keymap);
        if (pairs != null && !pairs.isEmpty()) {
            for (Pair<String, String> actionShortcut : pairs) {
                keymap.addShortcut(actionShortcut.first, new KeyboardShortcut(KeyStroke.getKeyStroke(actionShortcut.second), null));
            }
        }
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) StudyToolWindow(org.stepik.core.ui.StudyToolWindow) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) Pair(com.intellij.openapi.util.Pair)

Aggregations

KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)12 Shortcut (com.intellij.openapi.actionSystem.Shortcut)7 Keymap (com.intellij.openapi.keymap.Keymap)6 NotNull (org.jetbrains.annotations.NotNull)3 AnAction (com.intellij.openapi.actionSystem.AnAction)2 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)2 Pair (com.intellij.openapi.util.Pair)2 ThemeEditorComponent (com.android.tools.idea.editors.theme.ThemeEditorComponent)1 CodeInsightActionHandler (com.intellij.codeInsight.CodeInsightActionHandler)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 MacOSDefaultKeymap (com.intellij.openapi.keymap.impl.MacOSDefaultKeymap)1 ToolWindow (com.intellij.openapi.wm.ToolWindow)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 ActionEvent (java.awt.event.ActionEvent)1 KeyEvent (java.awt.event.KeyEvent)1 java.util (java.util)1