Access toolwindow from an action
Answered
I need to access my custom toolwindow from an action. In my case, the action triggers an update of the list displayed in the toolwindow. I tried two ways:
1) Make the toolwindow accessible via action-data. This did not work when assigning a shortcut to the action and the shortcut is used from some place outside of the toolwindow.
2) Make the toolwindow a singleton. This does not work when multiple IntelliJ projects / windows are open.
Related change (where I switched from method 1 to 2, but broke multipe IntelliJ window support: https://github.com/uwolfer/gerrit-intellij-plugin/commit/40189fa7745717be668b413f0a34c595451cb044
Any ideas how this could be solved in a clean way?
Please sign in to leave a comment.
You can use `ToolWindowManager.getInstance(project).getToolWindow(TOOLWINDOW_ID)`.
Or you can create projectService and store necessary data there.
Thanks Aleksey. I have fixed it by using a projectService:
https://github.com/uwolfer/gerrit-intellij-plugin/commit/400eda93bb849b8da828785b182ed3c6e0e574f4
Could you please provide some samples for the new API? I tried both ways but it seems they're not working as expected.
Could you explain what you tried and what went wrong? It is hard to guess what was "expected" from them in your case.