@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project
2222import com.intellij.openapi.util.Disposer
2323import com.intellij.openapi.wm.RegisterToolWindowTask
2424import com.intellij.openapi.wm.ToolWindowManager
25+ import com.intellij.openapi.wm.ex.ToolWindowManagerListener
2526import com.intellij.ui.content.ContentFactory
2627import com.intellij.ui.content.ContentManagerEvent
2728import com.intellij.ui.content.ContentManagerListener
@@ -47,7 +48,9 @@ import spp.protocol.instrument.event.LiveInstrumentEvent
4748 * @since 0.7.7
4849 * @author [Brandon Fergerson](mailto:bfergerson@apache.org)
4950 */
50- class InstrumentEventWindowService (val project : Project ) : Disposable {
51+ class InstrumentEventWindowService (
52+ val project : Project
53+ ) : Disposable, ContentManagerListener {
5154
5255 companion object {
5356 fun getInstance (project : Project ): InstrumentEventWindowService {
@@ -63,7 +66,10 @@ class InstrumentEventWindowService(val project: Project) : Disposable {
6366 private lateinit var breakpointHitTab: BreakpointHitTab
6467 private lateinit var overviewTab: InstrumentOverviewTab
6568 val selectedTab: Disposable ?
66- get() = contentManager.selectedContent?.disposer
69+ get() {
70+ if (! toolWindow.isVisible) return null
71+ return contentManager.selectedContent?.disposer
72+ }
6773 val selectedInstrumentOverview: InstrumentOverview ?
6874 get() {
6975 return when (val selectedTab = selectedTab) {
@@ -85,16 +91,16 @@ class InstrumentEventWindowService(val project: Project) : Disposable {
8591 }
8692 }
8793 })
88- contentManager.addContentManagerListener(object : ContentManagerListener {
89- override fun selectionChanged (event : ContentManagerEvent ) {
90- val disposable = event.content.disposer
91- if (disposable is BreakpointHitTab ) {
92- if (event.operation == ContentManagerEvent .ContentOperation .add) {
93- disposable.showExecutionLine()
94- }
94+ contentManager.addContentManagerListener(this )
95+
96+ project.messageBus.connect().subscribe(ToolWindowManagerListener .TOPIC , object : ToolWindowManagerListener {
97+ override fun stateChanged (toolWindowManager : ToolWindowManager ) {
98+ if (! toolWindow.isVisible) {
99+ executionPointHighlighter.hide()
95100 }
96101 }
97102 })
103+
98104 Disposer .register(this , contentManager)
99105
100106 toolWindow.setTitleActions(
@@ -105,6 +111,15 @@ class InstrumentEventWindowService(val project: Project) : Disposable {
105111 )
106112 }
107113
114+ override fun selectionChanged (event : ContentManagerEvent ) {
115+ val disposable = event.content.disposer
116+ if (disposable is BreakpointHitTab ) {
117+ if (event.operation == ContentManagerEvent .ContentOperation .add) {
118+ disposable.showExecutionLine()
119+ }
120+ }
121+ }
122+
108123 fun makeOverviewTab () {
109124 overviewTab = InstrumentOverviewTab (project)
110125 val content = contentFactory.createContent(overviewTab.component, " Overview" , true )
@@ -196,7 +211,7 @@ class InstrumentEventWindowService(val project: Project) : Disposable {
196211 }
197212
198213 fun showBreakpointHit (hit : LiveBreakpointHit ) {
199- removeExecutionShower ()
214+ executionPointHighlighter.hide ()
200215 breakpointHitTab = BreakpointHitTab (project, executionPointHighlighter)
201216
202217 // grab first non-skywalking frame and add real variables from skywalking frame
@@ -241,9 +256,5 @@ class InstrumentEventWindowService(val project: Project) : Disposable {
241256 }
242257 }
243258
244- private fun removeExecutionShower () {
245- executionPointHighlighter.hide()
246- }
247-
248259 override fun dispose () = Unit
249260}
0 commit comments