mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git-branches-dashboard: use TreeState to persist tree's state between refreshes or rebuilds of the tree
In particular this will fix selection reset on branch checkout. GitOrigin-RevId: 030fc15bfddb7da602d13504925c89bd065f4728
This commit is contained in:
committed by
intellij-monorepo-bot
parent
be9fbb7c41
commit
b06b11b051
@@ -5,6 +5,7 @@ import com.intellij.dvcs.DvcsUtil
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ide.dnd.TransferableList
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree
|
||||
import com.intellij.ide.util.treeView.TreeState
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.application.runInEdt
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -125,6 +126,7 @@ internal class FilteringBranchesTree(project: Project,
|
||||
: FilteringTree<BranchTreeNode, BranchNodeDescriptor>(project, component, rootNode) {
|
||||
|
||||
private val expandedPaths = SmartHashSet<TreePath>()
|
||||
private var treeState: TreeState? = null
|
||||
|
||||
private val localBranchesNode = BranchTreeNode(BranchNodeDescriptor(NodeType.LOCAL_ROOT))
|
||||
private val remoteBranchesNode = BranchTreeNode(BranchNodeDescriptor(NodeType.REMOTE_ROOT))
|
||||
@@ -194,25 +196,25 @@ internal class FilteringBranchesTree(project: Project,
|
||||
|
||||
override fun rebuildTree(initial: Boolean): Boolean {
|
||||
val rebuilded = buildTreeNodesIfNeeded()
|
||||
expandedPaths.addAll(TreeUtil.collectExpandedPaths(tree))
|
||||
if (!initial) {
|
||||
treeState = TreeState.createOn(tree, root)
|
||||
}
|
||||
searchModel.updateStructure()
|
||||
if (initial) {
|
||||
TreeUtil.expand(tree, 2)
|
||||
}
|
||||
else {
|
||||
restorePreviouslyExpandedPaths()
|
||||
treeState?.applyTo(tree)
|
||||
}
|
||||
|
||||
return rebuilded
|
||||
}
|
||||
|
||||
fun refreshTree() {
|
||||
expandedPaths.addAll(TreeUtil.collectExpandedPaths(tree))
|
||||
val selectionPaths = tree.selectionModel.selectionPaths
|
||||
treeState = TreeState.createOn(tree, root)
|
||||
refreshTreeNodesFromModel()
|
||||
searchModel.updateStructure()
|
||||
restorePreviouslyExpandedPaths()
|
||||
tree.selectionModel.selectionPaths = selectionPaths
|
||||
treeState?.applyTo(tree)
|
||||
}
|
||||
|
||||
private fun buildTreeNodesIfNeeded(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user