clearing tool window on project change

Answered

I would like to clear the content of my plugin's tool window when I change the project. If I change my project, my plugin tool window still holds the content of previous project's tool window. How do I clear this content? I tried to use removeAllContents() method, but it's not working. Should I use this before registering too window or before creating content of the tool window?

toolWindow.getContentManager().removeAllContents(true);
0
8 comments

By "change the project" do you mean to load a new project in the same window or a new project in a new window?

For the same window, I imagine this would work:

ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {
@Override
public void projectClosed(@NotNull Project project) {
toolwindow.blahblah
}
});
0
Avatar
Permanently deleted user

I mean open another project in another window.

0

You have to listen for a project opening then run the code.

MessageBus messageBus = project.getMessageBus();
messageBus.connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void projectOpened(@NotNull Project project) {
toolwindow.dostuff
}
});
1
Avatar
Permanently deleted user

Brian Faris, thanks for your reply. But I have another question. What is difference between ApplicationManager.getApplication().getMessageBus() and project.getMessageBus()? 
My project is already using the first one. So, I want to have clear idea about the difference.



0

Message bus can be provided on different levels, both Application and Project-level. See https://www.jetbrains.org/intellij/sdk/docs/reference_guide/messaging_infrastructure.html

0
Avatar
Permanently deleted user

Yann Cebron I am not sure about what you are suggesting. I want to clear my tool window when a new project window/instance opened.

0

AFAIU your plugin displays Project-related data, so how would it work if user has more than one project open? So the data/UI should be Project-specific, just like e.g. builtin TODO toolwindow in IDE.

0

Please sign in to leave a comment.