allow action popup to show tooltip; show tooltip for select root actions in structure popup in log

(cherry picked from commit 2ffef237d585ee3748aa963bd7e28bb50778379a)
This commit is contained in:
Julia Beliaeva
2015-08-25 17:08:50 +03:00
parent e62d8e8ea0
commit b853373a6d
5 changed files with 39 additions and 4 deletions
@@ -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<T> extends ListPopupStep<T> {
PopupStep onChosen(T selectedValue, boolean finalChoice, @MagicConstant(flagsFromClass = InputEvent.class) int eventModifiers);
@Nullable
String getTooltipTextFor(T value);
}
@@ -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);
@@ -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<ActionItem>, MnemonicNavigationFilter<ActionItem>, SpeedSearchFilter<ActionItem> {
@@ -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;
}
@@ -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<Object> listStep = aPopup.getListStep();
if (!(listStep instanceof ListPopupStepEx)) return null;
return ((ListPopupStepEx)listStep).getTooltipTextFor(value);
}
});
myPopup = aPopup;
}
@@ -261,6 +261,7 @@ class StructureFilterPopupComponent extends FilterPopupComponent<VcsLogFileFilte
updateIcon();
e.getPresentation().setIcon(myIcon);
e.getPresentation().putClientProperty(TOOL_TIP_TEXT_KEY, "Ctrl+Click to see only \"" + e.getPresentation().getText() + "\"");
}
private void updateIcon() {