Dynamic tool windows - project and file listeners
Hello, I have a usecase which I cannot figure out how to implement.
I have a tool window, which should only be available on a certain project state (aka certain files exist)
So for now I have an index on those files so that I can query that they exist efficiently.
I have a statically registered tool window over a ToolWindowFactory, which works.
But I cannot connect those together to make the appearance of the tool window dynamic because I cannot see find point where I can add some kind of project or file listener on project open.
The idea is to have some kind of listener which checks the index for the files existence and then adds the tool window or removes it on the fly.
So what I need is some kind of project listener and some kind of index listener which are triggered and an entry point which registers everything before the project is opened.
So where are the extension points where I can achieve this behavior?
Please sign in to leave a comment.
>point where I can add some kind of project or file listener on project open.
You can register ProjectComponent and do it in `projectOpened()` method.
https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html
>some kind of index listener
Not sure if you need an index in this case. Won't `VirtualFileListener` be sufficient ?
https://www.jetbrains.org/intellij/sdk/docs/basics/virtual_file_system.html
https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/virtual_file.html
Also, you probably do not want to use `ToolWindowFactory` - but rather manually register/unregister ToolWindow in your listener with `ToolWindowManager`.
https://www.jetbrains.org/intellij/sdk/docs/user_interface_components/tool_windows.html