From d90a554ea6f4f5a6991733ab50fbafcf1f242924 Mon Sep 17 00:00:00 2001 From: Pavel Gromov Date: Thu, 16 Jun 2022 18:47:40 +0300 Subject: [PATCH] [welcome screen] Fix tooltip problem with custom tree UI (IDEA-296134) GitOrigin-RevId: 9c102b02e5da18c930f8a315f4d7385623739104 --- .../RecentProjectFilteringTree.kt | 38 ++++++++++++++++++- .../intellij/ui/tree/ui/DefaultTreeUI.java | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/recentProjects/RecentProjectFilteringTree.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/recentProjects/RecentProjectFilteringTree.kt index 4e36b012c16e..e404f54cc49b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/recentProjects/RecentProjectFilteringTree.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/recentProjects/RecentProjectFilteringTree.kt @@ -10,7 +10,6 @@ import com.intellij.ide.RecentProjectsManagerBase import com.intellij.ide.ui.laf.darcula.ui.DarculaProgressBarUI import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.* -import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.ui.Messages import com.intellij.openapi.ui.addKeyboardAction import com.intellij.openapi.util.Condition @@ -29,6 +28,7 @@ import com.intellij.ui.render.RenderingUtil import com.intellij.ui.scale.JBUIScale import com.intellij.ui.speedSearch.SpeedSearchSupply import com.intellij.ui.tree.ui.Control +import com.intellij.ui.tree.ui.DefaultTreeUI import com.intellij.ui.treeStructure.Tree import com.intellij.util.IconUtil import com.intellij.util.PathUtil @@ -88,6 +88,7 @@ class RecentProjectFilteringTree( background = WelcomeScreenUIManager.getProjectsBackground() toggleClickCount = 0 + setUI(FullRendererComponentTreeUI()) setExpandableItemsEnabled(false) UIUtil.setCursor(this, Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)) } @@ -576,6 +577,41 @@ class RecentProjectFilteringTree( } } + private class FullRendererComponentTreeUI : DefaultTreeUI() { + override fun getPathBounds(tree: JTree, path: TreePath?): Rectangle? { + val bounds = super.getPathBounds(tree, path) + if (bounds != null) { + bounds.width = bounds.width.coerceAtLeast(tree.width - bounds.x) + } + + return bounds + } + + override fun paintRow(g: Graphics, clipBounds: Rectangle, + insets: Insets, bounds: Rectangle, + path: TreePath, row: Int, + isExpanded: Boolean, hasBeenExpanded: Boolean, isLeaf: Boolean) { + if (tree != null) { + bounds.width = tree.width + val viewport = ComponentUtil.getViewport(tree) + if (viewport != null) { + bounds.width = viewport.width - viewport.viewPosition.x - insets.right / 2 + } + bounds.width -= bounds.x + } + + super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf) + } + + override fun getRowX(row: Int, depth: Int): Int { + return JBUIScale.scale(getLeftMargin(depth - 1)) + } + + private fun getLeftMargin(level: Int): Int { + return 3 + level * (11 + 5) + } + } + companion object { private fun createActionEvent(tree: Tree, inputEvent: InputEvent? = null): AnActionEvent { val dataContext = DataManager.getInstance().getDataContext(tree) diff --git a/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java b/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java index 762b91e8defa..f2ada6758b84 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java @@ -46,7 +46,7 @@ import static com.intellij.util.ReflectionUtil.getMethod; import static com.intellij.util.containers.ContainerUtil.createWeakSet; @DirtyUI -public final class DefaultTreeUI extends BasicTreeUI { +public class DefaultTreeUI extends BasicTreeUI { @ApiStatus.Internal public static final Key LARGE_MODEL_ALLOWED = Key.create("allows to use large model (only for synchronous tree models)"); @ApiStatus.Internal