Project View - Expand node/path toward a PsiElement without altering selection Follow
I've been searching for hours in the SDK's source but cannot find any "easy" way to expand the Project View's tree to a given PsiElement without also selecting it.
The only thing working is this:
but it also selects the associated node in the tree, whereas I'd like the previous selection to remain.
which don't work consistently depending on the tree's state, and even:
JTree.scrollPathToVisible(new TreePath(treeUI.getNodeForElement(psiElement, false)))
but AbstractTreeUI.getNodeForElement returns null most of the time.
Any help would be greatly appreciated,
Thank you very much in advance.
Please sign in to leave a comment.
Have you tried AbstractTreeUi.select(element)? It should scroll to this node, but should not add it to selection.
Thank you Sergey, unfortunately that doesn't seem to do anything, at least in my case.
In the end, the only solution I found is copying the source code from BaseProjectTreeBuilder into my own class (as the interesting stuff is unfortunately private) and make it a bit simpler. For anyone who's interested, it can be found here:
Just copy that in your project and call it like this:
It's a bit ugly to have to do this, especially considering it might break in a future platform update, but it's working really well for now.
If anyone has a better suggestion, I'd be very happy to hear it.