Search in sources :

Example 6 with Shortcut

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

the class ActionMacroConfigurationPanel method apply.

public void apply() {
    if (myRenamingList != null) {
        for (Couple<String> pair : myRenamingList) {
            Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
            for (Keymap keymap : allKeymaps) {
                keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond());
                for (Shortcut shortcut : keymap.getShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst())) {
                    keymap.addShortcut(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond(), shortcut);
                }
                keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst());
            }
        }
    }
    final ActionMacroManager manager = ActionMacroManager.getInstance();
    ActionMacro[] macros = manager.getAllMacros();
    HashSet<String> removedIds = new HashSet<>();
    for (ActionMacro macro1 : macros) {
        removedIds.add(macro1.getActionId());
    }
    manager.removeAllMacros();
    final Enumeration newMacros = myMacrosModel.elements();
    while (newMacros.hasMoreElements()) {
        ActionMacro macro = (ActionMacro) newMacros.nextElement();
        manager.addMacro(macro);
        removedIds.remove(macro.getActionId());
    }
    manager.registerActions();
    for (String id : removedIds) {
        Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
        for (Keymap keymap : allKeymaps) {
            keymap.removeAllActionShortcuts(id);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Shortcut(com.intellij.openapi.actionSystem.Shortcut) Keymap(com.intellij.openapi.keymap.Keymap) HashSet(com.intellij.util.containers.HashSet)

Example 7 with Shortcut

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

the class KeymapGenerator method main.

@Override
public void main(String[] args) {
    ActionManager actionManager = ActionManager.getInstance();
    StringBuilder xml = new StringBuilder();
    xml.append("<Keymaps>\n");
    for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
        xml.append("  <Keymap name=\"").append(keymap.getPresentableName()).append("\">\n");
        for (String id : keymap.getActionIdList()) {
            String shortcuts = KeymapUtil.getShortcutsText(keymap.getShortcuts(id));
            if (!StringUtil.isEmpty(shortcuts)) {
                AnAction action = actionManager.getAction(id);
                xml.append("    <Action id=\"").append(id).append("\">\n");
                Set<String> addedShortcuts = new THashSet<>();
                for (Shortcut shortcut : keymap.getShortcuts(id)) {
                    // Different shortcuts may have equal display strings (e.g. shift+minus and shift+subtract)
                    // We don't want them do be duplicated for users
                    String shortcutText = KeymapUtil.getShortcutText(shortcut);
                    if (addedShortcuts.add(shortcutText)) {
                        xml.append("      <Shortcut>").append(shortcutText).append("</Shortcut>\n");
                    }
                }
                if (action != null) {
                    String text = action.getTemplatePresentation().getText();
                    if (text != null) {
                        xml.append("      <Text>").append(StringUtil.escapeXml(text)).append("</Text>\n");
                    }
                }
                xml.append("    </Action>\n");
            }
        }
        xml.append("  </Keymap>\n");
    }
    xml.append("</Keymaps>");
    final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllKeymaps.xml";
    File out = new File(path);
    try {
        FileUtil.writeToFile(out, xml.toString());
        System.out.println("Saved to: " + out.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) Shortcut(com.intellij.openapi.actionSystem.Shortcut) IOException(java.io.IOException) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File) Keymap(com.intellij.openapi.keymap.Keymap) THashSet(gnu.trove.THashSet)

Example 8 with Shortcut

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

the class ShortcutDialog method showAndGet.

T showAndGet(String id, Keymap keymap, QuickList... lists) {
    myActionId = id;
    myKeymap = keymap;
    myGroup = ActionsTreeUtil.createMainGroup(myProject, keymap, lists, null, false, null);
    fill(myAction, id, getActionPath(id));
    T firstShortcut = null;
    for (Shortcut shortcut : keymap.getShortcuts(id)) {
        firstShortcut = toShortcut(shortcut);
        if (firstShortcut != null)
            break;
    }
    setShortcut(firstShortcut);
    return showAndGet() ? myShortcutPanel.getShortcut() : null;
}
Also used : Shortcut(com.intellij.openapi.actionSystem.Shortcut)

Example 9 with Shortcut

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

the class MarkerType method composeText.

@NotNull
private static String composeText(@NotNull PsiElement[] methods, @NotNull String start, @NotNull String pattern, @NotNull String actionId) {
    Shortcut[] shortcuts = ActionManager.getInstance().getAction(actionId).getShortcutSet().getShortcuts();
    Shortcut shortcut = ArrayUtil.getFirstElement(shortcuts);
    String postfix = "<br><div style='margin-top: 5px'><font size='2'>Click";
    if (shortcut != null)
        postfix += " or press " + KeymapUtil.getShortcutText(shortcut);
    postfix += " to navigate</font></div>";
    return GutterIconTooltipHelper.composeText(Arrays.asList(methods), start, pattern, postfix);
}
Also used : Shortcut(com.intellij.openapi.actionSystem.Shortcut) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with Shortcut

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

the class EditorFixture method invokeAction.

/** Invokes {@code editorAction} via its (first) keyboard shortcut in the active keymap. */
public EditorFixture invokeAction(@NotNull EditorAction editorAction) {
    AnAction anAction = ActionManager.getInstance().getAction(editorAction.id);
    assertTrue(editorAction.id + " is not enabled", anAction.getTemplatePresentation().isEnabled());
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut shortcut = keymap.getShortcuts(editorAction.id)[0];
    if (shortcut instanceof KeyboardShortcut) {
        KeyboardShortcut cs = (KeyboardShortcut) shortcut;
        KeyStroke firstKeyStroke = cs.getFirstKeyStroke();
        Component component = getFocusedEditor();
        if (component != null) {
            ComponentDriver driver = new ComponentDriver(robot);
            driver.pressAndReleaseKey(component, firstKeyStroke.getKeyCode(), new int[] { firstKeyStroke.getModifiers() });
            KeyStroke secondKeyStroke = cs.getSecondKeyStroke();
            if (secondKeyStroke != null) {
                driver.pressAndReleaseKey(component, secondKeyStroke.getKeyCode(), new int[] { secondKeyStroke.getModifiers() });
            }
        } else {
            fail("Editor not focused for action");
        }
    } else {
        fail("Unsupported shortcut type " + shortcut.getClass().getName());
    }
    return this;
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) ThemeEditorComponent(com.android.tools.idea.editors.theme.ThemeEditorComponent) AnAction(com.intellij.openapi.actionSystem.AnAction) 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