Search in sources :

Example 16 with Shortcut

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

the class PopupListElementRenderer method customizeComponent.

@Override
protected void customizeComponent(JList<? extends E> list, E value, boolean isSelected) {
    ListPopupStep<Object> step = myPopup.getListStep();
    boolean isSelectable = step.isSelectable(value);
    myTextLabel.setEnabled(isSelectable);
    if (!isSelected && step instanceof BaseListPopupStep) {
        Color bg = ((BaseListPopupStep) step).getBackgroundFor(value);
        Color fg = ((BaseListPopupStep) step).getForegroundFor(value);
        if (fg != null)
            myTextLabel.setForeground(fg);
        if (bg != null)
            UIUtil.setBackgroundRecursively(myComponent, bg);
    }
    if (step.isMnemonicsNavigationEnabled()) {
        final int pos = step.getMnemonicNavigationFilter().getMnemonicPos(value);
        if (pos != -1) {
            String text = myTextLabel.getText();
            text = text.substring(0, pos) + text.substring(pos + 1);
            myTextLabel.setText(text);
            myTextLabel.setDisplayedMnemonicIndex(pos);
        }
    } else {
        myTextLabel.setDisplayedMnemonicIndex(-1);
    }
    if (step.hasSubstep(value) && isSelectable) {
        myNextStepLabel.setVisible(true);
        final boolean isDark = ColorUtil.isDark(UIUtil.getListSelectionBackground());
        myNextStepLabel.setIcon(isSelected ? isDark ? AllIcons.Icons.Ide.NextStepInverted : AllIcons.Icons.Ide.NextStep : AllIcons.Icons.Ide.NextStepGrayed);
    } else {
        myNextStepLabel.setVisible(false);
    //myNextStepLabel.setIcon(PopupIcons.EMPTY_ICON);
    }
    setSelected(myNextStepLabel, isSelected);
    if (myShortcutLabel != null) {
        myShortcutLabel.setText("");
        if (value instanceof ShortcutProvider) {
            ShortcutSet set = ((ShortcutProvider) value).getShortcut();
            if (set != null) {
                Shortcut shortcut = ArrayUtil.getFirstElement(set.getShortcuts());
                if (shortcut != null) {
                    myShortcutLabel.setText("     " + KeymapUtil.getShortcutText(shortcut));
                }
            }
        }
        setSelected(myShortcutLabel, isSelected);
        myShortcutLabel.setForeground(isSelected ? UIManager.getColor("MenuItem.acceleratorSelectionForeground") : UIManager.getColor("MenuItem.acceleratorForeground"));
    }
}
Also used : ShortcutProvider(com.intellij.openapi.actionSystem.ShortcutProvider) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) Shortcut(com.intellij.openapi.actionSystem.Shortcut) ShortcutSet(com.intellij.openapi.actionSystem.ShortcutSet)

Example 17 with Shortcut

use of com.intellij.openapi.actionSystem.Shortcut 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 18 with Shortcut

use of com.intellij.openapi.actionSystem.Shortcut 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 19 with Shortcut

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

the class JavaVariableInplaceIntroducer method getAdvertisementText.

@Nullable
private static String getAdvertisementText(final PsiDeclarationStatement declaration, final PsiType type, final boolean hasTypeSuggestion) {
    final VariablesProcessor processor = ReassignVariableUtil.findVariablesOfType(declaration, type);
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    if (processor.size() > 0) {
        final Shortcut[] shortcuts = keymap.getShortcuts("IntroduceVariable");
        if (shortcuts.length > 0) {
            return "Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to reassign existing variable";
        }
    }
    if (hasTypeSuggestion) {
        final Shortcut[] shortcuts = keymap.getShortcuts("PreviousTemplateVariable");
        if (shortcuts.length > 0) {
            return "Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to change type";
        }
    }
    return null;
}
Also used : VariablesProcessor(com.intellij.psi.scope.processor.VariablesProcessor) Shortcut(com.intellij.openapi.actionSystem.Shortcut) Keymap(com.intellij.openapi.keymap.Keymap) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with Shortcut

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

the class InplaceRefactoring method showDialogAdvertisement.

protected void showDialogAdvertisement(final String actionId) {
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    final Shortcut[] shortcuts = keymap.getShortcuts(actionId);
    if (shortcuts.length > 0) {
        setAdvertisementText("Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to show dialog with more options");
    }
}
Also used : Shortcut(com.intellij.openapi.actionSystem.Shortcut) 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