diff options
author | Jens Ole Lauridsen <jlauridsen@google.com> | 2021-11-19 09:24:24 -0800 |
---|---|---|
committer | Jens Ole Lauridsen <jlauridsen@google.com> | 2021-12-03 20:11:34 +0000 |
commit | 860300d1b5501f2dcda78a5e1f950686e806ea0f (patch) | |
tree | a22a2b9597052c21c502d936e3618eac1b286109 /layout-inspector/src | |
parent | 87864200ebf6c00a4d5e0c24634784eb88441cc3 (diff) | |
download | idea-860300d1b5501f2dcda78a5e1f950686e806ea0f.tar.gz |
Refactor expand all and collapse all actions
This is a preparation for implementing a tree table component tree
implementation. The Tree instance used in a TreeTable is not in the
Swing component hierarchy - so the tree expand and collapse all
would not work (the tree is not tecnically visible).
After this change these actions will work for both tree
implementations.
Bug: N/A
Test: N/A
Change-Id: Ie1cfb4a2112e413195d610a5605ebe5911c16606
Diffstat (limited to 'layout-inspector/src')
-rw-r--r-- | layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt | 12 |
1 files changed, 10 insertions, 2 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 87f8100f10d..0eab2c5874c 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 @@ -33,6 +33,7 @@ import com.android.tools.idea.layoutinspector.model.ViewNode.Companion.readAcces import com.android.tools.idea.layoutinspector.ui.LINES import com.google.common.annotations.VisibleForTesting import com.intellij.ide.CommonActionsManager +import com.intellij.ide.DefaultTreeExpander import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.AnAction @@ -50,6 +51,7 @@ import javax.swing.AbstractAction import javax.swing.Action import javax.swing.Icon import javax.swing.JComponent +import javax.swing.JTree import kotlin.math.max fun AnActionEvent.treePanel(): LayoutInspectorTreePanel? = @@ -123,11 +125,17 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou } } }) + + val treeExpander = object : DefaultTreeExpander({ tree }) { + override fun isEnabled(tree: JTree): Boolean { + return componentTreePanel.isShowing && tree.rowCount > 0 + } + } val commonActionManager = CommonActionsManager.getInstance() additionalActions = listOf( FilterGroupAction, - commonActionManager.createExpandAllHeaderAction(tree), - commonActionManager.createCollapseAllHeaderAction(tree) + commonActionManager.createExpandAllAction(treeExpander, tree), + commonActionManager.createCollapseAllAction(treeExpander, tree) ) } |