Search in sources :

Example 1 with Shortcut

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

the class GrInplaceVariableIntroducer method getAdvertisementText.

@Nullable
private static String getAdvertisementText() {
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    final Shortcut[] shortcuts = keymap.getShortcuts("PreviousTemplateVariable");
    if (shortcuts.length > 0) {
        return "Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to change type";
    }
    return null;
}
Also used : Shortcut(com.intellij.openapi.actionSystem.Shortcut) Keymap(com.intellij.openapi.keymap.Keymap) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Shortcut

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

the class KeymapsTestCase method checkLinuxKeymap.

private static void checkLinuxKeymap(final Keymap keymap) {
    for (String actionId : keymap.getActionIdList()) {
        for (Shortcut shortcut : keymap.getShortcuts(actionId)) {
            if (shortcut instanceof KeyboardShortcut) {
                checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut) shortcut).getFirstKeyStroke());
                checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut) shortcut).getSecondKeyStroke());
            }
        }
    }
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut)

Example 3 with Shortcut

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

the class KeymapsTestCase method testIdsListIsConsistent.

@SuppressWarnings({ "HardCodedStringLiteral" })
public void testIdsListIsConsistent() {
    Map<String, Map<String, List<String>>> duplicates = getKnownDuplicates();
    Set<String> allMaps = new THashSet<>(ContainerUtil.map(KeymapManagerEx.getInstanceEx().getAllKeymaps(), keymap -> keymap.getName()));
    assertThat(ContainerUtil.subtract(allMaps, duplicates.keySet())).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were added: %s", ContainerUtil.subtract(allMaps, duplicates.keySet())).isEmpty();
    assertThat(ContainerUtil.subtract(duplicates.keySet(), allMaps)).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were removed: %s", ContainerUtil.subtract(duplicates.keySet(), allMaps)).isEmpty();
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Map<Keymap, List<Shortcut>> reassignedShortcuts = new FactoryMap<Keymap, List<Shortcut>>() {

        @Override
        protected Map<Keymap, List<Shortcut>> createMap() {
            return new LinkedHashMap<>();
        }

        @Nullable
        @Override
        protected List<Shortcut> create(Keymap key) {
            return new ArrayList<>();
        }
    };
    for (String name : duplicates.keySet()) {
        Keymap keymap = KeymapManagerEx.getInstanceEx().getKeymap(name);
        assertThat(keymap).overridingErrorMessage("KeyMap %s not found", name).isNotNull();
        Map<String, List<String>> duplicateIdsList = duplicates.get(name);
        Set<String> mentionedShortcuts = new THashSet<>();
        for (Map.Entry<String, List<String>> shortcutMappings : duplicateIdsList.entrySet()) {
            String shortcutString = shortcutMappings.getKey();
            if (!mentionedShortcuts.add(shortcutString)) {
                TestCase.fail("Shortcut '" + shortcutString + "' duplicate in keymap '" + keymap + "'. Please modify 'known duplicates list'");
            }
            Shortcut shortcut = parse(shortcutString);
            String[] ids = keymap.getActionIds(shortcut);
            Set<String> actualSc = new HashSet<>(Arrays.asList(ids));
            removeBoundActionIds(actualSc);
            Set<String> expectedSc = new HashSet<>(shortcutMappings.getValue());
            for (String s : actualSc) {
                if (!expectedSc.contains(s)) {
                    reassignedShortcuts.get(keymap).add(shortcut);
                }
            }
            for (String s : expectedSc) {
                if (!actualSc.contains(s)) {
                    System.out.println("Expected action '" + s + "' does not reassign shortcut " + getText(shortcut) + " in keymap " + keymap + " or is not registered");
                }
            }
        }
    }
    if (!reassignedShortcuts.isEmpty()) {
        StringBuilder message = new StringBuilder();
        for (Map.Entry<Keymap, List<Shortcut>> keymapToShortcuts : reassignedShortcuts.entrySet()) {
            Keymap keymap = keymapToShortcuts.getKey();
            message.append("The following shortcuts was reassigned in keymap ").append(keymap.getName()).append(". Please modify known duplicates list:\n");
            for (Shortcut eachShortcut : keymapToShortcuts.getValue()) {
                message.append(" { ").append(StringUtil.wrapWithDoubleQuote(getText(eachShortcut))).append(",\t").append(StringUtil.join(keymap.getActionIds(eachShortcut), s -> StringUtil.wrapWithDoubleQuote(s), ", ")).append("},\n");
            }
        }
        TestCase.fail("\n" + message.toString());
    }
}
Also used : InputEvent(java.awt.event.InputEvent) MacOSDefaultKeymap(com.intellij.openapi.keymap.impl.MacOSDefaultKeymap) java.util(java.util) Assertions.assertThat(com.intellij.testFramework.assertions.Assertions.assertThat) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) Keymap(com.intellij.openapi.keymap.Keymap) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) ActionManager(com.intellij.openapi.actionSystem.ActionManager) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) TestCase(junit.framework.TestCase) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) StringUtil(com.intellij.openapi.util.text.StringUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) FactoryMap(com.intellij.util.containers.FactoryMap) AnAction(com.intellij.openapi.actionSystem.AnAction) KeyEvent(java.awt.event.KeyEvent) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) KeyStrokeAdapter(com.intellij.ui.KeyStrokeAdapter) Nullable(org.jetbrains.annotations.Nullable) Shortcut(com.intellij.openapi.actionSystem.Shortcut) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) FactoryMap(com.intellij.util.containers.FactoryMap) THashSet(gnu.trove.THashSet) 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) THashSet(gnu.trove.THashSet)

Example 4 with Shortcut

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

the class AntTargetNodeDescriptor method addShortcutText.

public static boolean addShortcutText(String actionId, CompositeAppearance appearance) {
    Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = activeKeymap.getShortcuts(actionId);
    if (shortcuts != null && shortcuts.length > 0) {
        appearance.getEnding().addText(" (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        return true;
    } else
        return false;
}
Also used : Shortcut(com.intellij.openapi.actionSystem.Shortcut) Keymap(com.intellij.openapi.keymap.Keymap)

Example 5 with Shortcut

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

the class OverrideImplementUtil method registerHandlerForComplementaryAction.

private static void registerHandlerForComplementaryAction(final Project project, final Editor editor, final PsiElement aClass, final boolean toImplement, final MemberChooser<PsiMethodMember> chooser) {
    final JComponent preferredFocusedComponent = chooser.getPreferredFocusedComponent();
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    @NonNls final String s = toImplement ? "OverrideMethods" : "ImplementMethods";
    final Shortcut[] shortcuts = keymap.getShortcuts(s);
    if (shortcuts.length > 0 && shortcuts[0] instanceof KeyboardShortcut) {
        preferredFocusedComponent.getInputMap().put(((KeyboardShortcut) shortcuts[0]).getFirstKeyStroke(), s);
        preferredFocusedComponent.getActionMap().put(s, new AbstractAction() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
                // invoke later in order to close previous modal dialog
                TransactionGuard.getInstance().submitTransactionLater(project, () -> {
                    CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler() : new ImplementMethodsHandler();
                    handler.invoke(project, editor, aClass.getContainingFile());
                });
            }
        });
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) ActionEvent(java.awt.event.ActionEvent) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Keymap(com.intellij.openapi.keymap.Keymap)

Aggregations

Shortcut (com.intellij.openapi.actionSystem.Shortcut)20 Keymap (com.intellij.openapi.keymap.Keymap)14 KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)9 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 THashSet (gnu.trove.THashSet)3 ActionManager (com.intellij.openapi.actionSystem.ActionManager)2 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)2 MacOSDefaultKeymap (com.intellij.openapi.keymap.impl.MacOSDefaultKeymap)2 FactoryMap (com.intellij.util.containers.FactoryMap)2 THashMap (gnu.trove.THashMap)2 java.util (java.util)2 NonNls (org.jetbrains.annotations.NonNls)2 ThemeEditorComponent (com.android.tools.idea.editors.theme.ThemeEditorComponent)1 CodeInsightActionHandler (com.intellij.codeInsight.CodeInsightActionHandler)1 MouseShortcut (com.intellij.openapi.actionSystem.MouseShortcut)1 ShortcutProvider (com.intellij.openapi.actionSystem.ShortcutProvider)1 ShortcutSet (com.intellij.openapi.actionSystem.ShortcutSet)1 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)1