diff options
author | Jens Ole Lauridsen <jlauridsen@google.com> | 2021-11-17 12:21:35 -0800 |
---|---|---|
committer | Jens Ole Lauridsen <jlauridsen@google.com> | 2021-12-03 20:11:34 +0000 |
commit | ce1ef169caed6a46aa74cd4dc38de9aee187d66a (patch) | |
tree | 606c5c8ff500585a1fcbbd3abae204a5499cc33e /layout-inspector/src | |
parent | c7905122cb8afb6b148ad1f294dc423db36e9210 (diff) | |
download | idea-ce1ef169caed6a46aa74cd4dc38de9aee187d66a.tar.gz |
Add option for using a TreeTable for the component tree
- Add a flag to Studio flags to hide this feature.
- ComponentTreeBuilder can now optional use a TreeTable.
- Implement existing features using a TreeTable including badges.
- TODO: add support for arbitrary extra columns
Bug: 172894679
Test: Tests migrated from tree impl to treetable impl
Change-Id: Ia93ca40fbd28ff511c7bace7bc3786c8e8fa12ec
Diffstat (limited to 'layout-inspector/src')
2 files changed, 16 insertions, 9 deletions
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt index 0eab2c5874c..c7b3c6871cc 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt @@ -42,6 +42,7 @@ import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.application.ApplicationManager import com.intellij.ui.SpeedSearchComparator +import com.intellij.ui.TableActions import com.intellij.ui.TreeActions import com.intellij.ui.treeStructure.Tree import java.awt.event.ActionEvent @@ -63,6 +64,8 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou private var layoutInspector: LayoutInspector? = null @VisibleForTesting val tree: Tree + @VisibleForTesting + val focusComponent: JComponent private val componentTreePanel: JComponent private val componentTreeModel: ComponentTreeModel private val nodeType = InspectorViewNodeType() @@ -106,6 +109,7 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou val result = builder.build() componentTreePanel = result.component tree = result.tree + focusComponent = result.focusComponent componentTreeModel = result.model componentTreeSelectionModel = result.selectionModel ActionManager.getInstance()?.getAction(IdeActions.ACTION_GOTO_DECLARATION)?.shortcutSet @@ -118,7 +122,7 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou } } layoutInspector?.layoutInspectorModel?.modificationListeners?.add { _, _, _ -> componentTreePanel.repaint() } - tree.addKeyListener(object : KeyAdapter() { + focusComponent.addKeyListener(object : KeyAdapter() { override fun keyTyped(event: KeyEvent) { if (Character.isAlphabetic(event.keyChar.toInt())) { toolWindowCallback?.startFiltering(event.keyChar.toString()) @@ -139,14 +143,16 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou ) } - private fun installKeyboardActions(tree: JComponent) { + private fun installKeyboardActions(focusedComponent: JComponent) { + val (down, up) = + if (focusedComponent is JTree) Pair(TreeActions.Down.ID, TreeActions.Up.ID) else Pair(TableActions.Down.ID, TableActions.Up.ID) if (downAction == null) { // Save the default up and down actions: - downAction = tree.actionMap.get(TreeActions.Down.ID) - upAction = tree.actionMap.get(TreeActions.Up.ID) + downAction = focusedComponent.actionMap.get(down) + upAction = focusedComponent.actionMap.get(up) } - tree.actionMap.put(TreeActions.Down.ID, TreeAction(::nextMatch)) - tree.actionMap.put(TreeActions.Up.ID, TreeAction(::previousMatch)) + focusedComponent.actionMap.put(down, TreeAction(::nextMatch)) + focusedComponent.actionMap.put(up, TreeAction(::previousMatch)) } private fun showPopup(component: JComponent, x: Int, y: Int) { @@ -193,10 +199,11 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou for (i in 0 until nodeCount) { // Select the next matching node, wrapping at the last node, and starting with the current selection: if (matchAndSelectNode(nodes[Math.floorMod(startIndex + i, nodeCount)])) { + componentTreePanel.repaint() return } } - tree.repaint() + componentTreePanel.repaint() } override fun isFilteringActive(): Boolean { @@ -300,7 +307,7 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou event.consume() } KeyEvent.VK_ENTER -> { - tree.requestFocusInWindow() + focusComponent.requestFocusInWindow() toolWindowCallback?.stopFiltering() event.consume() } diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt index b5f654dc440..ed7e36ceed6 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt @@ -119,7 +119,7 @@ object SupportLines : ToggleAction("Show Support Lines", null, null) { override fun setSelected(event: AnActionEvent, state: Boolean) { LayoutInspector.get(event)?.treeSettings?.supportLines = state - event.tree()?.repaint() + event.treePanel()?.component?.repaint() } } |