Skip to content

Commit

Permalink
Handle AlreadyDisposedException when hiding tool windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
pderakhshanfar committed Oct 13, 2024
1 parent c0373d7 commit a631791
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.serviceContainer.AlreadyDisposedException
import com.intellij.ui.content.ContentManager
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
import org.jetbrains.research.testspark.bundles.plugin.PluginMessagesBundle
Expand Down Expand Up @@ -94,7 +95,8 @@ class TestSparkDisplayManager {
}
}
}

toolWindow?.hide()
try {
toolWindow?.hide()
} catch (_: AlreadyDisposedException) {} // Make sure the process continues if the tool window is already closed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.research.testspark.display.generatedTests
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.serviceContainer.AlreadyDisposedException
import com.intellij.ui.content.ContentFactory
import com.intellij.ui.content.ContentManager
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
Expand Down Expand Up @@ -233,9 +234,11 @@ class GeneratedTestsTabBuilder(
* Closes the tool window by removing the content and hiding the window.
*/
private fun closeToolWindow() {
generatedTestsTabData.contentManager?.removeContent(generatedTestsTabData.content!!, true)
ToolWindowManager.getInstance(project).getToolWindow("TestSpark")?.hide()
coverageVisualisationTabBuilder.closeToolWindowTab()
try {
generatedTestsTabData.contentManager?.removeContent(generatedTestsTabData.content!!, true)
ToolWindowManager.getInstance(project).getToolWindow("TestSpark")?.hide()
coverageVisualisationTabBuilder.closeToolWindowTab()
} catch (_: AlreadyDisposedException) {} // Make sure the process continues if the tool window is already closed
}

/**
Expand Down

0 comments on commit a631791

Please sign in to comment.