ToolWindow open close callback.

Answered

Hi.

 

I'm developing a plugin and would like to know if do we have a callback to know when the ToolWindow is open or closed by the user.

 

Thanks.

0
4 comments

You can register the ToolWindowManagerListener listener and implement the stateChanged method, which may check:

ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID).isActive

Keep in mind, that this method doesn't distinguish, which TW has changed the state (registering/deregistering TW, focus/blur events) - so it's quite verbose.

However, you can get the isActive state of your particular TW and fire another action when this flag has changed to throttle these events.

1

Thanks Jakub.

With

(ToolWindowManager.getInstance(project) as ToolWindowManagerEx).addToolWindowManagerListener(object :
ToolWindowManagerListener {
override fun stateChanged() {
super.stateChanged()
println("# " + toolWindow.isActive)
}
})

I've managed to achieve what I what although `addToolWindowManagerListener` is marked as deprecated and I didn't find out what is the non-deprecated approach.

 

 

0

You can register such listener within plugin.xml file. Check out our documentation about Plugin Listeners.

3

Please sign in to leave a comment.