diff --git a/platform/platform-api/src/com/intellij/ui/components/labels/DropDownLink.java b/platform/platform-api/src/com/intellij/ui/components/labels/DropDownLink.java index 7adb5f560c1b..5290687e3839 100644 --- a/platform/platform-api/src/com/intellij/ui/components/labels/DropDownLink.java +++ b/platform/platform-api/src/com/intellij/ui/components/labels/DropDownLink.java @@ -3,9 +3,11 @@ package com.intellij.ui.components.labels; import com.intellij.icons.AllIcons; import com.intellij.openapi.ui.popup.IPopupChooserBuilder; +import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Consumer; +import com.intellij.util.containers.Convertor; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,30 +26,37 @@ public class DropDownLink extends LinkLabel { init(); } - public DropDownLink(@NotNull T initialItem, @NotNull List items, @Nullable Consumer itemChosenAction, boolean updateLabel) { - super(initialItem.toString(), AllIcons.General.LinkDropTriangle); - chosenItem = initialItem; - IPopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createPopupChooserBuilder(items). - setRenderer(new LinkCellRenderer<>(this)). - setItemChosenCallback(t -> { - chosenItem = t; - if (updateLabel) { - setText(t.toString()); - } + public DropDownLink(@NotNull T value, @NotNull Convertor popupBuilder) { + super(value.toString(), AllIcons.General.LinkDropTriangle); + chosenItem = value; - if (itemChosenAction != null) { - itemChosenAction.consume(t); - } - }); - - setListener((s, d) -> { + setListener((linkLabel, d) -> { + JBPopup popup = popupBuilder.convert((DropDownLink)linkLabel); Point showPoint = new Point(0, getHeight() + JBUI.scale(4)); - popupBuilder.createPopup().show(new RelativePoint(this, showPoint)); + popup.show(new RelativePoint(this, showPoint)); }, null); init(); } + public DropDownLink(@NotNull T initialItem, @NotNull List items, @Nullable Consumer itemChosenAction, boolean updateLabel) { + this(initialItem, (linkLabel) -> { + IPopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createPopupChooserBuilder(items). + setRenderer(new LinkCellRenderer<>(linkLabel)). + setItemChosenCallback(t -> { + linkLabel.chosenItem = t; + if (updateLabel) { + linkLabel.setText(t.toString()); + } + + if (itemChosenAction != null) { + itemChosenAction.consume(t); + } + }); + return popupBuilder.createPopup(); + }); + } + private void init() { setIconTextGap(JBUI.scale(1)); setHorizontalAlignment(SwingConstants.LEADING); diff --git a/platform/platform-impl/src/com/intellij/ui/components/labels/ActionGroupLink.java b/platform/platform-impl/src/com/intellij/ui/components/labels/ActionGroupLink.java deleted file mode 100644 index 26d53f8d831f..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/components/labels/ActionGroupLink.java +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ui.components.labels; - -import com.intellij.icons.AllIcons; -import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.ui.ClickListener; -import com.intellij.ui.popup.PopupFactoryImpl; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.MouseEventAdapter; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseEvent; - -public class ActionGroupLink extends JPanel { - private final MyLinkLabel myLinkLabel; - - public ActionGroupLink(@NotNull String text, @Nullable Icon icon, @NotNull ActionGroup actionGroup) { - setOpaque(false); - - myLinkLabel = new MyLinkLabel(text, icon); - myLinkLabel.setListener(new LinkListener() { - @Override - public void linkSelected(LinkLabel aSource, Object aLinkData) { - DataContext dataContext = DataManager.getInstance().getDataContext(myLinkLabel); - ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, actionGroup, dataContext, - JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false, - ActionPlaces.UNKNOWN); - ((PopupFactoryImpl.ActionGroupPopup)popup).showUnderneathOfLabel(myLinkLabel); - } - }, null); - - - JLabel arrow = new JLabel(AllIcons.General.LinkDropTriangle); - arrow.setVerticalAlignment(SwingConstants.BOTTOM); - arrow.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - new ClickListener() { - @Override - public boolean onClick(@NotNull MouseEvent e, int clickCount) { - final MouseEvent newEvent = MouseEventAdapter.convert(e, myLinkLabel, e.getX(), e.getY()); - myLinkLabel.doClick(newEvent); - return true; - } - }.installOn(arrow); - - setLayout(new GridBagLayout()); - add(JBUI.Panels.simplePanel(myLinkLabel).addToRight(arrow), new GridBagConstraints()); - } - - public LinkLabel getLinkLabel() { - return myLinkLabel; - } - - private static class MyLinkLabel extends LinkLabel implements DataProvider { - MyLinkLabel(String text, @Nullable Icon icon) { - super(text, icon); - } - - @Override - public Object getData(@NotNull @NonNls String dataId) { - if (PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE.is(dataId)) { - final Point p = SwingUtilities.getRoot(this).getLocationOnScreen(); - return new Rectangle(p.x, p.y + getHeight(), 0, 0); - } - if (PlatformDataKeys.CONTEXT_MENU_POINT.is(dataId)) { - return SwingUtilities.convertPoint(this, 0, getHeight(), UIUtil.getRootPane(this)); - } - - return null; - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt index 4b0e37d6ae1f..7966adf683e7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt @@ -2,6 +2,7 @@ package com.intellij.openapi.vcs.ex import com.intellij.diff.util.Side +import com.intellij.ide.DataManager import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.AnActionEvent @@ -19,6 +20,7 @@ import com.intellij.openapi.editor.event.DocumentListener import com.intellij.openapi.keymap.KeymapUtil import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.text.StringUtil @@ -29,7 +31,7 @@ import com.intellij.openapi.vcs.changes.LocalChangeList import com.intellij.openapi.vcs.ex.DocumentTracker.Block import com.intellij.openapi.vcs.impl.LineStatusTrackerManager import com.intellij.openapi.vfs.VirtualFile -import com.intellij.ui.components.labels.ActionGroupLink +import com.intellij.ui.components.labels.DropDownLink import com.intellij.util.EventDispatcher import com.intellij.util.containers.ContainerUtil import com.intellij.util.containers.WeakList @@ -564,18 +566,22 @@ class ChangelistsLocalLineStatusTracker(project: Project, group.add(MoveToAnotherChangeListAction(editor, range, mousePosition)) - val link = ActionGroupLink(rangeList.name, null, group) + val link = DropDownLink(rangeList.name) { linkLabel -> + val dataContext = DataManager.getInstance().getDataContext(linkLabel) + JBPopupFactory.getInstance() + .createActionGroupPopup(null, group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false) + } val moveChangesShortcutSet = ActionManager.getInstance().getAction("Vcs.MoveChangedLinesToChangelist").shortcutSet object : DumbAwareAction() { override fun actionPerformed(e: AnActionEvent) { - link.linkLabel.doClick() + link.doClick() } }.registerCustomShortcutSet(moveChangesShortcutSet, editor.component, disposable) val shortcuts = moveChangesShortcutSet.shortcuts if (shortcuts.isNotEmpty()) { - link.linkLabel.toolTipText = "Move lines to another changelist (${KeymapUtil.getShortcutText(shortcuts.first())})" + link.toolTipText = "Move lines to another changelist (${KeymapUtil.getShortcutText(shortcuts.first())})" } val panel = JPanel(BorderLayout())