VirtualFile's Children order doesn't match Project Explorer's order
Answered
I need to get exact same order of files as is in Project Explorer.
When using VirtualFile's children property, its sorting order is from shortest path to longest, and I don't see any option to get it sorted in a way it is in Project Explorer.
How could this be done?
Please sign in to leave a comment.
Hi Jarek,
VirtualFile.getChildren()
API doesn't guarantee any file order, and there is no method that allows for controlling that.Regarding the Project View order, it can be configured via Tree Appearance | Sort by …. To get the configured sorting type, you can use
ProjectView.getInstance(project).getSortKey(panelId)
. Please note that the ProjectView and related classes are UI-specific and this API is incompatible with VirtualFiles, so you will need to implement your own comparators specifically for VirtualFiles and use them depending on what is selected in the Project View.Hi Karol,
thank you for looking into this.
Is there any specific code in the IntelliJ source where this is applied? I am looking for a point where you are building list of files for a folder in that TreeView, where the SortKey gets applied, I was looking for it but couldnt find anything, I was thinking I will use same approach as the TreeView does.
Sorry, I don't know the exact place where the elements are populated. I suggest debugging
com.intellij.ide.projectView.impl.ProjectViewImpl.refresh()
.