Questions about TreeStructureProvider
I want to implement plugin, which should be able to update Project View structure.
From:
-
my_project
- project1_file1.xml
- project1_file2.xml
- project2_file1.xml
- project2_file2.xml
To:
-
my_project
-
project1
- file1.xml
- file2.xml
-
project2
- file1.xml
- file2.xml
-
project1
User should be able to switch back and forth. Note folders `project1` and `project2` should not be created on file system, also `xml` files should not be re-named on file system.
Questions:
- Is it possible?
- As I undesrtood I need to use `com.intellij.ide.projectView.TreeStructureProvider` and return my `Collection<AbstractTreeNode>` inside `modify` method, right?
- How to create `PsiDirectoryNode` for `project1` and `project2`? How to rename `project1_file1.xml` to `file1.xml`?
Code
// for creating folder
Project project = ProjectManager.getInstance().getOpenProjects()[0];
PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file); <= I am stuck with creating VirtualFile
AbstractTreeNode node = new PsiDirectoryNode(project, psiDirectory, viewSettings);
// for re-naming PsiFile
for (AbstractTreeNode child : children) {
if(child.getValue() instanceof PsiFile) {
PsiFile file = (PsiFile) child.getValue();
file.setName("new name"); // this will re-name my file physically, and I need only for Project View
}
}
Thanks in advance.
Please sign in to leave a comment.
1. Yes, this is possible.
2. Yes, this is correct.
3. A PsiDirectoryNode represents an actual directory on disk. Since in your case there is no such directory, you need to create a different type of node representing your group of files. See FormNode for an example of such node class. To change the name shown for a file, you can create a node class extending PsiFileNode and override the updateImpl() method to customize the presentation.
Can you help me with one more thing. My plugin is working with `com.intellij.ide.projectView.TreeStructureProvider` but in Android Studio user can switch project structure view to Android:

Method `modify` of my `TreeStructureProvider ` is never called.
I think this is because I declared my `TreeStructureProvider` as below:
How I need to declare `TreeStructureProvider` to make it work with Android project structure view?
You can't. The Android view defines its own structure and does not allow modifying the structure through any extensions.