Select module in Project Tree from a Module instance?

Answered

Hello,

Given that I have an instance of a com.intellij.openapi.module.Module, how would I go about focusing and expanding the respective module in the Project Tree?

Thanks!

0
2 comments

Try with:

ProjectView.getInstance(project).getCurrentProjectViewPane().selectModule(module, requestFocus);
0

Hi Jakub,

For some reason when I use the code below, the module passed is not selected. The project view gets focused, but is is the current module that shows up.

ProjectView.getInstance(project).getCurrentProjectViewPane().selectModule(module, requestFocus);

However, the following did the trick, not sure why:

val virtualFile = ModuleRootManager.getInstance(module).contentRoots[0]
val context = FileSelectInContext(module.project, virtualFile)
SelectInManager.findSelectInTarget(SelectInManager.PROJECT, module.project).selectIn(context, true)

Took the virtual file example from here: https://www.programcreek.com/java-api-examples/?api=com.intellij.ide.projectView.impl.nodes.ProjectViewModuleNode 

0

Please sign in to leave a comment.