From 2e52716ac8161603d602aec283068b3c6f32182b Mon Sep 17 00:00:00 2001 From: Mikhail Sokolov Date: Mon, 5 Apr 2021 16:00:19 +0500 Subject: [PATCH] IDEA-263715 Popup Lists: place mnemonics between icon and text (cherry picked from commit e442dd73416c37681658cf1e813b647bf1cab635) IJ-CR-7890 GitOrigin-RevId: 4bfc5d55710b3a05288dc352a470bdda40b09be3 --- .../actions/ChooseRunConfigurationPopup.java | 16 +++++++----- .../RunAnythingChooseContextAction.kt | 7 ++++++ .../ui/popup/StateActionGroupPopup.kt | 10 ++++++++ .../popup/list/PopupListElementRenderer.java | 25 ++++++++++--------- .../ui/PopupListElementRendererWithIcon.java | 2 +- .../GrazieLanguagesPopupElementRenderer.kt | 1 + 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/actions/ChooseRunConfigurationPopup.java b/platform/execution-impl/src/com/intellij/execution/actions/ChooseRunConfigurationPopup.java index 8a128c9c16ce..12b319b4e574 100644 --- a/platform/execution-impl/src/com/intellij/execution/actions/ChooseRunConfigurationPopup.java +++ b/platform/execution-impl/src/com/intellij/execution/actions/ChooseRunConfigurationPopup.java @@ -765,11 +765,17 @@ public final class ChooseRunConfigurationPopup implements ExecutorProvider { protected ListCellRenderer getListElementRenderer() { return new PopupListElementRenderer<>(this){ @Override - protected JComponent createIconBar(JList list, Object value, boolean selected) { + protected JComponent createIconBar() { JPanel res = new JPanel(new GridBagLayout()); res.setOpaque(false); res.setBorder(JBUI.Borders.emptyRight(JBUI.CurrentTheme.ActionsList.elementIconGap())); + return res; + } + + @Override + protected void customizeComponent(JList list, Object value, boolean isSelected) { + super.customizeComponent(list, value, isSelected); GridBag gbc = new GridBag() .setDefaultAnchor(GridBagConstraints.CENTER) .setDefaultWeightX(1) @@ -777,12 +783,10 @@ public final class ChooseRunConfigurationPopup implements ExecutorProvider { .setDefaultFill(GridBagConstraints.BOTH); if (value instanceof NumericMnemonicItem && ((NumericMnemonicItem)value).digitMnemonicsEnabled()) { - res.add(myMnemonicLabel, gbc.next().weightx(0)); - res.add(Box.createHorizontalStrut(JBUI.CurrentTheme.ActionsList.mnemonicIconGap()), gbc.next()); + myIconBar.add(myMnemonicLabel, gbc.next().weightx(0)); + myIconBar.add(Box.createHorizontalStrut(JBUI.CurrentTheme.ActionsList.mnemonicIconGap()), gbc.next()); } - res.add(myIconLabel, gbc.next()); - - return res; + myIconBar.add(myIconLabel, gbc.next()); } }; } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingChooseContextAction.kt b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingChooseContextAction.kt index 49b6d455001a..9ae388f6757d 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingChooseContextAction.kt +++ b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingChooseContextAction.kt @@ -152,16 +152,23 @@ abstract class RunAnythingChooseContextAction(private val containingPanel: JPane private lateinit var myInfoLabel: JLabel override fun createItemComponent(): JComponent { + myIconLabel = JLabel() myTextLabel = ErrorLabel() myInfoLabel = JLabel() myTextLabel.border = JBUI.Borders.emptyRight(10) + myIconBar = createIconBar() + val textPanel = JPanel(BorderLayout()) textPanel.add(myTextLabel, BorderLayout.WEST) textPanel.add(myInfoLabel, BorderLayout.CENTER) return layoutComponent(textPanel) } + override fun createIconBar(): JComponent { + return myIconLabel + } + override fun customizeComponent(list: JList, actionItem: PopupFactoryImpl.ActionItem, isSelected: Boolean) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/StateActionGroupPopup.kt b/platform/platform-impl/src/com/intellij/ui/popup/StateActionGroupPopup.kt index 1c2504b2a238..4582ba2a12b1 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/StateActionGroupPopup.kt +++ b/platform/platform-impl/src/com/intellij/ui/popup/StateActionGroupPopup.kt @@ -63,6 +63,7 @@ open class StateActionGroupPopup(@NlsContexts.PopupTitle title: String?, createLabel() panel.add(myTextLabel, BorderLayout.CENTER) myTextLabel.border = JBUI.Borders.emptyTop(1) + myIconBar = createIconBar() val bt = createButton() rightPane.add(bt, BorderLayout.CENTER) @@ -78,6 +79,15 @@ open class StateActionGroupPopup(@NlsContexts.PopupTitle title: String?, return layoutComponent(panel) } + override fun createLabel() { + super.createLabel() + myIconLabel.border = JBUI.Borders.empty(1, 0, 0, JBUI.CurrentTheme.ActionsList.elementIconGap()) + } + + override fun createIconBar(): JComponent { + return myIconLabel + } + private fun createButton(): JComponent { val pane = JPanel(MigLayout("ins 0, gap 0")).apply { isOpaque = false diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java index 855cf80bee33..2259e48df996 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java @@ -119,6 +119,8 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { myMnemonicLabel.setBorder(new JBEmptyBorder(insets)); myMnemonicLabel.setFont(JBUI.CurrentTheme.ActionsList.applyStylesForNumberMnemonic(myMnemonicLabel.getFont())); + myIconBar = createIconBar(); + return layoutComponent(panel); } @@ -143,6 +145,10 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { myNextStepButtonSeparator = createNextStepButtonSeparator(); left.add(myNextStepButtonSeparator, BorderLayout.EAST); + if (myIconBar != null) { + left.add(myIconBar, BorderLayout.WEST); + } + JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); result.setBorder(JBUI.Borders.empty()); @@ -173,6 +179,7 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { @Override protected void setComponentIcon(Icon icon, Icon disabledIcon) { + if (myIconLabel == null) return; myIconLabel.setIcon(icon); myIconLabel.setDisabledIcon(disabledIcon); } @@ -255,6 +262,9 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { myMnemonicLabel.setText(mnemonic != null ? String.valueOf(mnemonic) : ""); myMnemonicLabel.setForeground(isSelected && isSelectable && !nextStepButtonSelected ? getSelectionForeground() : JBUI.CurrentTheme.ActionsList.MNEMONIC_FOREGROUND); } + else if (myMnemonicLabel != null) { + myMnemonicLabel.setVisible(false); + } if (step.isMnemonicsNavigationEnabled()) { MnemonicNavigationFilter filter = step.getMnemonicNavigationFilter(); @@ -300,22 +310,13 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { myValueLabel.setText(step instanceof ListPopupStepEx ? ((ListPopupStepEx)step).getValueFor(value) : null); setSelected(myValueLabel, isSelected && isSelectable && !nextStepButtonSelected, isSelected); } - - if (myIconBar != null) myMainPane.remove(myIconBar); - myIconBar = createIconBar(list, value, isSelected); - if (myIconBar != null) myMainPane.add(myIconBar, BorderLayout.WEST); } - @Nullable - protected JComponent createIconBar(JList list, E value, boolean selected) { - boolean mnemonicShown = value instanceof NumericMnemonicItem && ((NumericMnemonicItem)value).digitMnemonicsEnabled(); - boolean iconShown = myIconLabel.getIcon() != null; - if (!mnemonicShown && !iconShown) return null; - + protected JComponent createIconBar() { Box res = Box.createHorizontalBox(); res.setBorder(JBUI.Borders.emptyRight(JBUI.CurrentTheme.ActionsList.elementIconGap())); - if (iconShown) res.add(myIconLabel); - if (mnemonicShown) res.add(myMnemonicLabel); + res.add(myIconLabel); + res.add(myMnemonicLabel); return res; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/PopupListElementRendererWithIcon.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/PopupListElementRendererWithIcon.java index d3e6d6615155..2df8a87071f8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/PopupListElementRendererWithIcon.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/PopupListElementRendererWithIcon.java @@ -48,7 +48,7 @@ public class PopupListElementRendererWithIcon extends PopupListElementRenderer list, Object value, boolean selected) { + protected @Nullable JComponent createIconBar() { return myIconLabel; } diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/ide/ui/proofreading/component/list/GrazieLanguagesPopupElementRenderer.kt b/plugins/grazie/src/main/kotlin/com/intellij/grazie/ide/ui/proofreading/component/list/GrazieLanguagesPopupElementRenderer.kt index 2f9341d2af09..b573296a665b 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/ide/ui/proofreading/component/list/GrazieLanguagesPopupElementRenderer.kt +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/ide/ui/proofreading/component/list/GrazieLanguagesPopupElementRenderer.kt @@ -21,6 +21,7 @@ class GrazieLanguagesPopupElementRenderer(list: ListPopupImpl) : PopupListElemen override fun createItemComponent(): JComponent { createLabel() createSizeLabel() + myIconBar = createIconBar() val panel = panel(BorderLayout()) { add(myTextLabel, BorderLayout.CENTER)