Search in sources :

Example 1 with KeyboardShortcut

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

the class StudyProjectComponent method addShortcut.

private void addShortcut(@NotNull final String actionIdString, @NotNull final String[] shortcuts) {
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    for (Keymap keymap : keymapManager.getAllKeymaps()) {
        List<Pair<String, String>> pairs = deletedShortcuts.computeIfAbsent(keymap, k -> new ArrayList<>());
        for (String shortcutString : shortcuts) {
            Shortcut studyActionShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
            String[] actionsIds = keymap.getActionIds(studyActionShortcut);
            for (String actionId : actionsIds) {
                pairs.add(Pair.create(actionId, shortcutString));
                keymap.removeShortcut(actionId, studyActionShortcut);
            }
            keymap.addShortcut(actionIdString, studyActionShortcut);
        }
    }
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) StudyActionWithShortcut(org.stepik.core.actions.StudyActionWithShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) Pair(com.intellij.openapi.util.Pair)

Example 2 with KeyboardShortcut

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

the class GrTypeComboBox method registerUpDownHint.

public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) {
    final AnAction arrow = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo);
            }
        }
    };
    final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null);
    final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null);
    arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}
Also used : KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 3 with KeyboardShortcut

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

the class PyStudyInstructionPainter method advertiseActions.

@Override
protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) {
    String shortcut = KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(StudyNextWindowAction.SHORTCUT2), null));
    appendAction(painter, "Navigate to the next answer placeholder", shortcut);
    appendAction(painter, "Navigate between answer placeholders", getActionShortcutText(StudyPrevWindowAction.ACTION_ID) + separator + getActionShortcutText(StudyNextWindowAction.ACTION_ID));
    appendAction(painter, "Navigate between tasks", getActionShortcutText(StudyPreviousTaskAction.ACTION_ID) + separator + getActionShortcutText(StudyNextTaskAction.ACTION_ID));
    appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID));
    appendAction(painter, "Check task", getActionShortcutText(PyStudyCheckAction.ACTION_ID));
    appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID));
}
Also used : KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut)

Example 4 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 5 with KeyboardShortcut

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

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