From 0fe21b6057abb509ba8f75ebbc9ea05ad1afb99c Mon Sep 17 00:00:00 2001 From: Alexey Utkin Date: Mon, 28 Oct 2024 21:11:32 +0400 Subject: [PATCH] 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 --- .../intellij/execution/ui/RunToolbarPopup.kt | 2 ++ .../openapi/ui/popup/ListPopupStepEx.java | 3 ++ .../intellij/ui/popup/ActionPopupStep.java | 5 +++ .../popup/list/PopupListElementRenderer.java | 36 +++++++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/ui/RunToolbarPopup.kt b/platform/execution-impl/src/com/intellij/execution/ui/RunToolbarPopup.kt index 3e86abeaa5df..b17ced79d789 100644 --- a/platform/execution-impl/src/com/intellij/execution/ui/RunToolbarPopup.kt +++ b/platform/execution-impl/src/com/intellij/execution/ui/RunToolbarPopup.kt @@ -285,6 +285,8 @@ internal class RunConfigurationsActionGroupPopup(actionGroup: ActionGroup, override fun getListElementRenderer(): PopupListElementRenderer { return object : PopupListElementRenderer(this) { override fun isShowSecondaryText(): Boolean = mySpeedSearch.isHoldingFilter + + override fun isShowSecondaryIcon(): Boolean = mySpeedSearch.isHoldingFilter } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStepEx.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStepEx.java index 23950a48f0ee..784f9fad759e 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStepEx.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/ListPopupStepEx.java @@ -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 extends ListPopupStep { @@ -29,4 +30,6 @@ public interface ListPopupStepEx extends ListPopupStep { void setEmptyText(@NotNull StatusText emptyText); default @Nls @Nullable String getSecondaryTextFor(T t) { return null; } + + default @Nls @Nullable Icon getSecondaryIconFor(T t) { return null; } } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java b/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java index a75bfc3df0df..48e63bfcf4d6 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java @@ -216,6 +216,11 @@ public class ActionPopupStep implements ListPopupStepEx extends GroupedItemsListRenderer { 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 extends GroupedItemsListRenderer { }; 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 extends GroupedItemsListRenderer { setForegroundSelected(mySecondaryTextLabel, selected); } + if (mySecondaryIconLabel != null) { + Icon icon = isShowSecondaryIcon() && step instanceof ListPopupStepEx 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 extends GroupedItemsListRenderer { return true; } + protected boolean isShowSecondaryIcon() { + return true; + } + private boolean updateExtraButtons(JList list, E value, ListPopupStep step, boolean isSelected, boolean hasNextIcon) { myButtonPane.removeAll(); GridBag gb = new GridBag().setDefaultFill(GridBagConstraints.BOTH)