IJPL-165423 SECONDARY_ICON attribute does not work for action UI in a popup menu

(cherry picked from commit bb728aedc9a4bf03a762ae1a46b2ce3859910be3)

IJ-CR-147964

GitOrigin-RevId: 38b68080ab4b610a493da30ae36ca1015bc050d3
This commit is contained in:
Alexey Utkin
2024-10-28 21:11:32 +04:00
committed by intellij-monorepo-bot
parent cbeba03f99
commit 0fe21b6057
4 changed files with 43 additions and 3 deletions

View File

@@ -285,6 +285,8 @@ internal class RunConfigurationsActionGroupPopup(actionGroup: ActionGroup,
override fun getListElementRenderer(): PopupListElementRenderer<PopupFactoryImpl.ActionItem> {
return object : PopupListElementRenderer<PopupFactoryImpl.ActionItem>(this) {
override fun isShowSecondaryText(): Boolean = mySpeedSearch.isHoldingFilter
override fun isShowSecondaryIcon(): Boolean = mySpeedSearch.isHoldingFilter
}
}

View File

@@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon;
import java.awt.event.InputEvent;
public interface ListPopupStepEx<T> extends ListPopupStep<T> {
@@ -29,4 +30,6 @@ public interface ListPopupStepEx<T> extends ListPopupStep<T> {
void setEmptyText(@NotNull StatusText emptyText);
default @Nls @Nullable String getSecondaryTextFor(T t) { return null; }
default @Nls @Nullable Icon getSecondaryIconFor(T t) { return null; }
}

View File

@@ -216,6 +216,11 @@ public class ActionPopupStep implements ListPopupStepEx<PopupFactoryImpl.ActionI
return item.getClientProperty(ActionUtil.SECONDARY_TEXT);
}
@Override
public @Nullable Icon getSecondaryIconFor(PopupFactoryImpl.@NotNull ActionItem item) {
return item.getClientProperty(ActionUtil.SECONDARY_ICON);
}
@Override
public ListSeparator getSeparatorAbove(final PopupFactoryImpl.ActionItem value) {
return value.isPrependWithSeparator() ? new ListSeparator(value.getSeparatorText()) : null;

View File

@@ -34,6 +34,7 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
protected final ListPopupImpl myPopup;
private @Nullable JLabel myShortcutLabel;
private @Nullable JLabel mySecondaryIconLabel;
private @Nullable JLabel mySecondaryTextLabel;
protected JLabel myMnemonicLabel;
protected JLabel myIconLabel;
@@ -126,12 +127,22 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
};
panel.add(myTextLabel, BorderLayout.WEST);
JPanel secondary = new JPanel(new BorderLayout());
JBEmptyBorder secondaryBorder = ExperimentalUI.isNewUI() ? JBUI.Borders.empty() : JBUI.Borders.empty(0, 8, 1, 0);
secondary.setBorder(secondaryBorder);
mySecondaryTextLabel = new JLabel();
mySecondaryTextLabel.setEnabled(false);
JBEmptyBorder valueBorder = ExperimentalUI.isNewUI() ? JBUI.Borders.empty() : JBUI.Borders.empty(0, 8, 1, 0);
mySecondaryTextLabel.setBorder(valueBorder);
mySecondaryTextLabel.setForeground(UIManager.getColor("MenuItem.acceleratorForeground"));
panel.add(mySecondaryTextLabel, BorderLayout.CENTER);
secondary.add(mySecondaryTextLabel, BorderLayout.EAST);
mySecondaryIconLabel = new JLabel();
JBEmptyBorder secondaryIconBorder = JBUI.Borders.emptyLeft(JBUI.CurrentTheme.ActionsList.elementIconGap() - 2);
mySecondaryIconLabel.setBorder(secondaryIconBorder);
mySecondaryIconLabel.setVisible(false);
secondary.add(mySecondaryIconLabel, BorderLayout.WEST);
panel.add(secondary, BorderLayout.CENTER);
myShortcutLabel = new JLabel();
JBEmptyBorder shortcutBorder = ExperimentalUI.isNewUI() ? JBUI.Borders.empty() : JBUI.Borders.empty(0,0,1,3);
@@ -387,6 +398,21 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
setForegroundSelected(mySecondaryTextLabel, selected);
}
if (mySecondaryIconLabel != null) {
Icon icon = isShowSecondaryIcon() && step instanceof ListPopupStepEx<Object> o ?
o.getSecondaryIconFor(value) : null;
if (icon != null) {
mySecondaryIconLabel.setIcon(icon);
boolean selected = isSelected && isSelectable && !nextStepButtonSelected;
setForegroundSelected(mySecondaryIconLabel, selected);
mySecondaryIconLabel.setVisible(true);
}
else {
mySecondaryIconLabel.setVisible(false);
}
}
if (ExperimentalUI.isNewUI() && getItemComponent() instanceof SelectablePanel selectablePanel) {
selectablePanel.setSelectionColor(isSelected && isSelectable ? UIUtil.getListSelectionBackground(true) : null);
setSelected(myMainPane, isSelected && isSelectable);
@@ -397,6 +423,10 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
return true;
}
protected boolean isShowSecondaryIcon() {
return true;
}
private boolean updateExtraButtons(JList<? extends E> list, E value, ListPopupStep<Object> step, boolean isSelected, boolean hasNextIcon) {
myButtonPane.removeAll();
GridBag gb = new GridBag().setDefaultFill(GridBagConstraints.BOTH)