Search in sources :

Example 1 with ShortcutProvider

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

Aggregations

Shortcut (com.intellij.openapi.actionSystem.Shortcut)1 ShortcutProvider (com.intellij.openapi.actionSystem.ShortcutProvider)1 ShortcutSet (com.intellij.openapi.actionSystem.ShortcutSet)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1