Allow to hide 'dropdown' icon for popup action group

This commit is contained in:
Vassiliy.Kudryashov
2019-03-21 22:48:34 +03:00
parent d5fc080211
commit d6955119ab
5 changed files with 36 additions and 42 deletions
@@ -111,6 +111,8 @@ public interface ActionToolbar {
void setSecondaryActionsIcon(Icon icon);
void setSecondaryActionsIcon(Icon icon, boolean hideDropdownIcon);
@NotNull
List<AnAction> getActions();
@@ -15,6 +15,7 @@ import com.intellij.ide.ui.UISettings
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.impl.ActionButton
import com.intellij.openapi.actionSystem.impl.ActionMenuItem
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.TooltipAction
import com.intellij.openapi.keymap.KeymapManager
@@ -262,14 +263,14 @@ internal class DaemonTooltipWithActionRenderer(text: String?,
hasMore: Boolean): JComponent {
val presentation = Presentation()
presentation.icon = AllIcons.Actions.More
presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, true)
val actions = mutableListOf<AnAction>()
actions.add(ShowActionsAction(reloader, tooltipAction != null))
val docAction = ShowDocAction(reloader, hasMore)
actions.add(docAction)
val actionGroup = SettingsActionGroup(actions)
val settingsButton = ActionButton.Transparent(actionGroup, presentation, ActionPlaces.UNKNOWN,
Dimension(18, 18))
val settingsButton = ActionButton(actionGroup, presentation, ActionPlaces.UNKNOWN, Dimension(18, 18))
settingsButton.setNoIconsInPopup(true)
settingsButton.border = JBUI.Borders.empty()
settingsButton.isOpaque = false
@@ -470,16 +470,8 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
}
super.processMouseMotionEvent(e);
}
@NotNull
@Override
protected ActionButton createSecondaryButton(DefaultActionGroup secondaryActions,
Presentation presentation,
String place, final Dimension minimumSize) {
return new ActionButton.Transparent(secondaryActions, presentation, place, minimumSize);
}
};
myToolBar.setSecondaryActionsIcon(AllIcons.Actions.More);
myToolBar.setSecondaryActionsIcon(AllIcons.Actions.More, true);
JLayeredPane layeredPane = new JBLayeredPane() {
@Override
@@ -520,7 +512,8 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
gearActions.addAll(actions);
Presentation presentation = new Presentation();
presentation.setIcon(AllIcons.Actions.More);
myCorner = new ActionButton.Transparent(gearActions, presentation, ActionPlaces.UNKNOWN, new Dimension(20, 20));
presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);
myCorner = new ActionButton(gearActions, presentation, ActionPlaces.UNKNOWN, new Dimension(20, 20));
myCorner.setNoIconsInPopup(true);
layeredPane.add(myCorner);
layeredPane.setLayer(myCorner, JLayeredPane.POPUP_LAYER);
@@ -19,6 +19,7 @@ import com.intellij.openapi.ui.popup.JBPopupAdapter;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.ui.popup.StackingPopupDispatcher;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ui.*;
@@ -35,6 +36,13 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
public class ActionButton extends JComponent implements ActionButtonComponent, AnActionHolder, Accessible {
/**
* By default button representing popup action group displays 'dropdown' icon.
* This key allows to avoid 'dropdown' icon painting, just put it in ActionButton's presentation or template presentation of ActionGroup like this:
* <code>presentaion.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE)</code>
*/
public static final Key<Boolean> HIDE_DROPDOWN_ICON = Key.create("HIDE_DROPDOWN_ICON");
private JBDimension myMinimumButtonSize;
private PropertyChangeListener myPresentationListener;
private Icon myDisabledIcon;
@@ -361,6 +369,8 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A
private void paintDownArrowIfGroup(Graphics g) {
if (!(myAction instanceof ActionGroup && ((ActionGroup)myAction).isPopup())) return;
if (Boolean.TRUE == myAction.getTemplatePresentation().getClientProperty(HIDE_DROPDOWN_ICON)) return;
if (Boolean.TRUE == myPresentation.getClientProperty(HIDE_DROPDOWN_ICON)) return;
Container parent = getParent();
boolean horizontal = !(parent instanceof ActionToolbarImpl) ||
((ActionToolbarImpl)parent).getOrientation() == SwingConstants.HORIZONTAL;
@@ -595,15 +605,4 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A
return false;
}
}
public static class Transparent extends ActionButton {
public Transparent(@NotNull AnAction action, Presentation presentation, String place, @NotNull Dimension minimumSize) {
super(action, presentation, place, minimumSize);
}
@Override
public void paintComponent(Graphics g) {
paintButtonLook(g);
}
}
}
@@ -330,8 +330,16 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct
}
if (mySecondaryActions.getChildrenCount() > 0) {
mySecondaryActionsButton = createSecondaryButton(mySecondaryActions, myPresentationFactory.getPresentation(mySecondaryActions),
myPlace, getMinimumButtonSize());
mySecondaryActionsButton =
new ActionButton(mySecondaryActions, myPresentationFactory.getPresentation(mySecondaryActions), myPlace, getMinimumButtonSize()) {
@Override
@ButtonState
public int getPopState() {
return mySecondaryButtonPopupStateModifier != null && mySecondaryButtonPopupStateModifier.willModify()
? mySecondaryButtonPopupStateModifier.getModifiedPopupState()
: super.getPopState();
}
};
mySecondaryActionsButton.setNoIconsInPopup(true);
add(mySecondaryActionsButton);
}
@@ -345,22 +353,6 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct
}
}
@NotNull
protected ActionButton createSecondaryButton(final DefaultActionGroup secondaryActions,
final Presentation presentation,
final String place,
final Dimension minimumSize) {
return new ActionButton(secondaryActions, presentation, place, minimumSize) {
@Override
@ButtonState
public int getPopState() {
return mySecondaryButtonPopupStateModifier != null && mySecondaryButtonPopupStateModifier.willModify()
? mySecondaryButtonPopupStateModifier.getModifiedPopupState()
: super.getPopState();
}
};
}
@NotNull
private JComponent getCustomComponent(@NotNull AnAction action) {
Presentation presentation = myPresentationFactory.getPresentation(action);
@@ -1403,7 +1395,14 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct
@Override
public void setSecondaryActionsIcon(Icon icon) {
mySecondaryActions.getTemplatePresentation().setIcon(icon);
setSecondaryActionsIcon(icon, false);
}
@Override
public void setSecondaryActionsIcon(Icon icon, boolean hideDropdownIcon) {
Presentation presentation = mySecondaryActions.getTemplatePresentation();
presentation.setIcon(icon);
presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, hideDropdownIcon ? Boolean.TRUE : null);
}
@NotNull