Search in sources :

Example 6 with KeyboardShortcut

use of com.intellij.openapi.actionSystem.KeyboardShortcut 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)

Example 7 with KeyboardShortcut

use of com.intellij.openapi.actionSystem.KeyboardShortcut 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)

Example 8 with KeyboardShortcut

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

the class JBTerminalSystemSettingsProviderBase method getKeyStrokesByActionId.

private KeyStroke[] getKeyStrokesByActionId(String actionId) {
    java.util.List<KeyStroke> keyStrokes = new ArrayList<>();
    Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
    for (Shortcut sc : shortcuts) {
        if (sc instanceof KeyboardShortcut) {
            KeyStroke ks = ((KeyboardShortcut) sc).getFirstKeyStroke();
            keyStrokes.add(ks);
        }
    }
    return keyStrokes.toArray(new KeyStroke[keyStrokes.size()]);
}
Also used : java.util(java.util) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut)

Example 9 with KeyboardShortcut

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

the class ToolWindowManagerImpl method getActivateToolWindowVKs.

@NotNull
private static Set<Integer> getActivateToolWindowVKs() {
    if (ApplicationManager.getApplication() == null)
        return new HashSet<>();
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] baseShortcut = keymap.getShortcuts("ActivateProjectToolWindow");
    int baseModifiers = SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.ALT_MASK;
    for (Shortcut each : baseShortcut) {
        if (each instanceof KeyboardShortcut) {
            KeyStroke keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
            baseModifiers = keyStroke.getModifiers();
            if (baseModifiers > 0) {
                break;
            }
        }
    }
    return getModifiersVKs(baseModifiers);
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Keymap(com.intellij.openapi.keymap.Keymap) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with KeyboardShortcut

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

the class GuiTestUtil method invokeAction.

public static void invokeAction(@NotNull Robot robot, @NotNull String actionId) {
    KeyboardShortcut keyboardShortcut = ActionManager.getInstance().getKeyboardShortcut(actionId);
    assert keyboardShortcut != null;
    KeyStroke keyStroke = keyboardShortcut.getFirstKeyStroke();
    LOG.info("Invoking action \"" + actionId + "\" via shortcut " + keyboardShortcut.toString());
    robot.pressAndReleaseKey(keyStroke.getKeyCode(), new int[] { keyStroke.getModifiers() });
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut)

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