How to Subscribe for Modules changes

Hi,

I'm trying to subscribe for modules changes (added, removed,...) but couldn't find how, whith poject I did the following:

1.cleate class that implements com.intellij.openapi.project.ProjectManagerListener
2.subcribe using the ProjectManager:
        ProjectManager.getInstance().removeProjectManagerListener(this);


I tried to do the same with the Module and implemented com.intellij.openapi.project.ModuleListener, but i couldn't find a way to set it from the ModuleManager.

When i searched i found that there was method Subscribe to com.intellij.ProjectTopics.MODULES on project bus or lower.

any idea how to use ProjectToopics to subscribe for modules changes?
2 comments
Comment actions Permalink

Thanks Dmitry,

I used the following in the ProjectManagerListener.projectOpened

@Override
    public void projectOpened(Project project) {
        // Subscribe for module changes
        project.getMessageBus().connect().subscribe(ProjectTopics.MODULES, new ModuleListener());
    }


And here is the ModuleListener


public class ModuleListener implements com.intellij.openapi.project.ModuleListener{


    @Override
    public void moduleAdded(final Project project, final Module module) {


    }


    @Override
    public void beforeModuleRemoved(final Project project, final Module module) {


    }


    @Override
    public void moduleRemoved(final Project project, final Module module) {


    }


    @Override
    public void modulesRenamed(final Project project, final List<Module> modules) {


    }
}

0

Please sign in to leave a comment.