[vcs] correctly identify toolwindow by tab name before toolwindow content initialization master
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Tue, 24 Nov 2020 11:05:34 +0000 (14:05 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 24 Nov 2020 11:22:09 +0000 (11:22 +0000)
After the introduction of the new api for specifying whether to use "Commit" toolwindow for the tab, it is impossible to identify the correct toolwindow just by the tab name. ChangesViewContentManager keeps track of tabs that should be placed in the "Commit" toolwindow, but only after "Commit" toolwindow content was initialized. Before that moment toolwindow for tabs were identified incorrectly, which broke navigation actions.

 This commit adds looking through ChangesViewContentEP implementations to identify the correct toolwindow before initialization.

 follow-up: c3aa1441d627dbf535a56314322d27abc3d37e3c

GitOrigin-RevId: 0ca86e9e842737f5ed9971fac17558cb50e872df

platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsToolWindowFactory.kt

index a79b9bfb2671a5a4fd4176e293f5ad4ccc0d8392..11c31c6fc29101331aafe1bbbdf2587f18521247 100644 (file)
@@ -49,9 +49,7 @@ class ChangesViewContentManager(private val project: Project) : ChangesViewConte
     return if (isCommitToolWindow && shouldUseCommitToolWindow) COMMIT_TOOLWINDOW_ID else TOOLWINDOW_ID
   }
 
-  private fun getToolWindowIdFor(contentName: String): String {
-    return getToolWindowId(commitToolWindowTabs.contains(contentName))
-  }
+  private fun isInCommitToolWindow(contentName: String): Boolean = commitToolWindowTabs.contains(contentName)
 
   private fun Content.isInCommitToolWindow() = IS_IN_COMMIT_TOOLWINDOW_KEY.get(this) == true
 
@@ -230,8 +228,11 @@ class ChangesViewContentManager(private val project: Project) : ChangesViewConte
     fun isCommitToolWindow(project: Project): Boolean = getInstanceImpl(project)?.isCommitToolWindow == true
 
     @JvmStatic
-    fun getToolWindowIdFor(project: Project, contentName: String): String? =
-      getInstanceImpl(project)?.getToolWindowIdFor(contentName)
+    fun getToolWindowIdFor(project: Project, contentName: String): String? {
+      val shouldUseCommitToolWindow = getInstanceImpl(project)?.isInCommitToolWindow(contentName) == true ||
+                                      VcsToolWindowFactory.isInCommitToolWindow(project, contentName)
+      return getInstanceImpl(project)?.getToolWindowId(shouldUseCommitToolWindow)
+    }
 
     @JvmStatic
     fun getToolWindowFor(project: Project, contentName: String): ToolWindow? =
index a7898642171096579ae2842e060f7586c34cfbcf..7eaa0fc7d39e3018979408d755df5dcf97e08d89 100644 (file)
@@ -148,5 +148,8 @@ abstract class VcsToolWindowFactory : ToolWindowFactory, DumbAware {
   companion object {
     internal val Project.vcsManager: ProjectLevelVcsManager
       get() = ProjectLevelVcsManager.getInstance(this)
+
+    internal fun isInCommitToolWindow(project: Project, tabName: String) =
+      ChangesViewContentEP.EP_NAME.getExtensions(project).firstOrNull { it.tabName == tabName }?.isInCommitToolWindow == true
   }
 }
\ No newline at end of file