[IFT] Add utility method to close find tabs
authorAlexey Merkulov <alexey.merkulov@jetbrains.com>
Fri, 18 Sep 2020 13:09:48 +0000 (16:09 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 23 Sep 2020 09:21:49 +0000 (09:21 +0000)
GitOrigin-RevId: c13b11472f1f915ab1f978ad71f25d21dd5f2420

ide-features-trainer/src/training/learn/lesson/general/navigation/DeclarationAndUsagesLesson.kt
ide-features-trainer/src/training/learn/lesson/kimpl/LessonUtil.kt

index c2511e0294a90239501b0ec8cda2fcd610b08d35..0b50e239f98bd4688266b2f9a6aa9c859028ff85 100644 (file)
@@ -18,6 +18,7 @@ import training.learn.LessonsBundle
 import training.learn.interfaces.Module
 import training.learn.lesson.kimpl.KLesson
 import training.learn.lesson.kimpl.LessonContext
+import training.learn.lesson.kimpl.closeAllFindTabs
 
 abstract class DeclarationAndUsagesLesson(module: Module, lang: String)
   : KLesson("Declaration and usages", LessonsBundle.message("declaration.and.usages.lesson.name"), module, lang) {
@@ -59,6 +60,9 @@ abstract class DeclarationAndUsagesLesson(module: Module, lang: String)
       }
 
       task("FindUsages") {
+        before {
+          closeAllFindTabs()
+        }
         text(LessonsBundle.message("declaration.and.usages.find.usages", action(it)))
 
         triggerByUiComponentAndHighlight { ui: BaseLabel ->
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