[IFT] Add utility method to close find tabs
[idea/contrib.git] / ide-features-trainer / src / training / learn / lesson / kimpl / LessonUtil.kt
index d8c6396babe8a279a6cf4d9edd6e7f49bfecdd50..bb85c25aa280ac920e65e5ec6436c29660b06df2 100644 (file)
@@ -12,6 +12,8 @@ import com.intellij.openapi.util.SystemInfo
 import com.intellij.openapi.util.text.TextWithMnemonic
 import com.intellij.openapi.wm.ToolWindow
 import com.intellij.openapi.wm.ex.ToolWindowManagerListener
+import com.intellij.ui.content.Content
+import com.intellij.usageView.UsageViewContentManager
 import com.intellij.util.messages.Topic
 import com.intellij.xdebugger.XDebuggerManager
 import training.commands.kotlin.TaskContext
@@ -144,6 +146,14 @@ fun TaskContext.restoreAfterStateBecomeFalse(restoreId: TaskContext.TaskId? = nu
   }
 }
 
+fun TaskRuntimeContext.closeAllFindTabs() {
+  val usageViewManager = UsageViewContentManager.getInstance(project)
+  var selectedContent: Content?
+  while (usageViewManager.selectedContent.also { selectedContent = it } != null) {
+    usageViewManager.closeContent(selectedContent!!)
+  }
+}
+
 fun String.dropMnemonic(): String {
   return TextWithMnemonic.parse(this).dropMnemonic(true).text
 }
\ No newline at end of file