From b853373a6d2ddc6809a0911212a110b73aaa0fdf Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sun, 19 Jul 2015 23:00:20 +0300 Subject: [PATCH] allow action popup to show tooltip; show tooltip for select root actions in structure popup in log (cherry picked from commit 2ffef237d585ee3748aa963bd7e28bb50778379a) --- .../openapi/ui/popup/ListPopupStepEx.java | 4 +++ .../intellij/ui/GroupedElementsRenderer.java | 2 +- .../intellij/ui/popup/PopupFactoryImpl.java | 26 ++++++++++++++++--- .../popup/list/PopupListElementRenderer.java | 10 +++++++ .../filter/StructureFilterPopupComponent.java | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) 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 f3ea978b87e5..75dd6e84fbe4 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 @@ -1,9 +1,13 @@ package com.intellij.openapi.ui.popup; import org.intellij.lang.annotations.MagicConstant; +import org.jetbrains.annotations.Nullable; import java.awt.event.InputEvent; public interface ListPopupStepEx extends ListPopupStep { PopupStep onChosen(T selectedValue, boolean finalChoice, @MagicConstant(flagsFromClass = InputEvent.class) int eventModifiers); + + @Nullable + String getTooltipTextFor(T value); } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ui/GroupedElementsRenderer.java b/platform/platform-api/src/com/intellij/ui/GroupedElementsRenderer.java index a7bdb9f1bb62..9f828799422e 100644 --- a/platform/platform-api/src/com/intellij/ui/GroupedElementsRenderer.java +++ b/platform/platform-api/src/com/intellij/ui/GroupedElementsRenderer.java @@ -58,7 +58,7 @@ public abstract class GroupedElementsRenderer { mySeparatorComponent.setMinimumWidth(preferredForcedWidth); myTextLabel.setText(text); - myTextLabel.setToolTipText(tooltip); + myRendererComponent.setToolTipText(tooltip); myTextLabel.setIcon(icon); myTextLabel.setDisabledIcon(disabledIcon); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index ee30c2b8288c..2f3bdd8eba96 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -671,14 +671,22 @@ public class PopupFactoryImpl extends JBPopupFactory { private final Icon myIcon; private final boolean myPrependWithSeparator; private final String mySeparatorText; + private final String myDescription; - private ActionItem(@NotNull AnAction action, @NotNull String text, boolean enabled, Icon icon, final boolean prependWithSeparator, String separatorText) { + private ActionItem(@NotNull AnAction action, + @NotNull String text, + @Nullable String description, + boolean enabled, + Icon icon, + final boolean prependWithSeparator, + String separatorText) { myAction = action; myText = text; myIsEnabled = enabled; myIcon = icon; myPrependWithSeparator = prependWithSeparator; mySeparatorText = separatorText; + myDescription = description; } @NotNull @@ -704,6 +712,10 @@ public class PopupFactoryImpl extends JBPopupFactory { } public boolean isEnabled() { return myIsEnabled; } + + public String getDescription() { + return myDescription; + } } private static class ActionPopupStep implements ListPopupStepEx, MnemonicNavigationFilter, SpeedSearchFilter { @@ -779,6 +791,12 @@ public class PopupFactoryImpl extends JBPopupFactory { return value.getText(); } + @Nullable + @Override + public String getTooltipTextFor(ActionItem value) { + return value.getDescription(); + } + @Override public ListSeparator getSeparatorAbove(final ActionItem value) { return value.isPrependWithSeparator() ? new ListSeparator(value.getSeparatorText()) : null; @@ -942,7 +960,7 @@ public class PopupFactoryImpl extends JBPopupFactory { appendActionsFromGroup(actionGroup); if (myListModel.isEmpty()) { - myListModel.add(new ActionItem(Utils.EMPTY_MENU_FILLER, Utils.NOTHING_HERE, false, null, false, null)); + myListModel.add(new ActionItem(Utils.EMPTY_MENU_FILLER, Utils.NOTHING_HERE, null, false, null, false, null)); } } @@ -1051,7 +1069,9 @@ public class PopupFactoryImpl extends JBPopupFactory { } boolean prependSeparator = (!myListModel.isEmpty() || mySeparatorText != null) && myPrependWithSeparator; assert text != null : action + " has no presentation"; - myListModel.add(new ActionItem(action, text, presentation.isEnabled(), icon, prependSeparator, mySeparatorText)); + myListModel.add( + new ActionItem(action, text, (String)presentation.getClientProperty(JComponent.TOOL_TIP_TEXT_KEY), presentation.isEnabled(), icon, + prependSeparator, mySeparatorText)); myPrependWithSeparator = false; mySeparatorText = null; } 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 0431d39c1ff0..aa973cd8ee88 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 @@ -18,9 +18,11 @@ package com.intellij.ui.popup.list; import com.intellij.icons.AllIcons; import com.intellij.openapi.ui.popup.ListItemDescriptorAdapter; import com.intellij.openapi.ui.popup.ListPopupStep; +import com.intellij.openapi.ui.popup.ListPopupStepEx; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.ui.ColorUtil; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -49,6 +51,14 @@ public class PopupListElementRenderer extends GroupedItemsListRenderer { public String getCaptionAboveOf(Object value) { return aPopup.getListModel().getCaptionAboveOf(value); } + + @Nullable + @Override + public String getTooltipFor(Object value) { + ListPopupStep listStep = aPopup.getListStep(); + if (!(listStep instanceof ListPopupStepEx)) return null; + return ((ListPopupStepEx)listStep).getTooltipTextFor(value); + } }); myPopup = aPopup; } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/StructureFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/StructureFilterPopupComponent.java index 13b03e28410e..df20ae5d642d 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/StructureFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/StructureFilterPopupComponent.java @@ -261,6 +261,7 @@ class StructureFilterPopupComponent extends FilterPopupComponent