IDEA-250477 vcs: fix VCS scopes not being visible after project opening
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Tue, 2 Feb 2021 14:58:14 +0000 (17:58 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 2 Feb 2021 15:20:40 +0000 (15:20 +0000)
Refresh available scopes if ChangeListManager is initialized after ProjectView.

GitOrigin-RevId: f9b2043b8ec9de1b11d5aaaf753efa45448d8c5c

platform/vcs-impl/resources/META-INF/VcsExtensions.xml
platform/vcs-impl/src/com/intellij/vcs/changes/ChangeListScopeViewUpdater.kt

index df5f59af6da1d0c56132ad18c68f632a82f31d57..11d93e7d7984bd07a17e92d293892ce6b3f34c6f 100644 (file)
               topic="com.intellij.platform.ModuleAttachListener"/>
     <listener class="com.intellij.vcs.changes.ChangeListScopeViewUpdater"
               topic="com.intellij.openapi.vcs.changes.ChangeListListener"/>
+    <listener class="com.intellij.vcs.changes.ChangeListScopeViewUpdater$InitialRefresh"
+              topic="com.intellij.openapi.vcs.changes.LocalChangeListsLoadedListener"/>
   </projectListeners>
 </idea-plugin>
 
index 3161b28615c34d7c5a8b69f6c700d9102b1d1a2a..5552e366ec21c4a87cae1ae368070850103bd2e6 100644 (file)
@@ -3,13 +3,22 @@ package com.intellij.vcs.changes
 
 import com.intellij.ide.projectView.ProjectView
 import com.intellij.ide.scopeView.ScopeViewPane
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.components.serviceIfCreated
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.vcs.changes.ChangeList
 import com.intellij.openapi.vcs.changes.ChangeListAdapter
+import com.intellij.openapi.vcs.changes.LocalChangeList
+import com.intellij.openapi.vcs.changes.LocalChangeListsLoadedListener
 import com.intellij.packageDependencies.DependencyValidationManager
-import com.intellij.util.ui.UIUtil
 
 class ChangeListScopeViewUpdater(private val project: Project) : ChangeListAdapter() {
+  class InitialRefresh(private val project: Project) : LocalChangeListsLoadedListener {
+    override fun processLoadedLists(lists: MutableList<LocalChangeList>) {
+      updateAvailableScopesList(project)
+    }
+  }
+
   override fun changeListAdded(list: ChangeList) {
     updateAvailableScopesList(project)
   }
@@ -32,9 +41,10 @@ class ChangeListScopeViewUpdater(private val project: Project) : ChangeListAdapt
 
   companion object {
     private fun updateActiveScope(project: Project) {
-      UIUtil.invokeLaterIfNeeded {
-        if (project.isDisposed) return@invokeLaterIfNeeded
-        val pane = ProjectView.getInstance(project).getProjectViewPaneById(ScopeViewPane.ID) as? ScopeViewPane ?: return@invokeLaterIfNeeded
+      ApplicationManager.getApplication().invokeLater {
+        if (project.isDisposed) return@invokeLater
+        val projectView = project.serviceIfCreated<ProjectView>() ?: return@invokeLater
+        val pane = projectView.getProjectViewPaneById(ScopeViewPane.ID) as? ScopeViewPane ?: return@invokeLater
         if (pane.selectedScope is ChangeListScope) {
           pane.updateSelectedScope()
         }
@@ -42,8 +52,8 @@ class ChangeListScopeViewUpdater(private val project: Project) : ChangeListAdapt
     }
 
     private fun updateAvailableScopesList(project: Project) {
-      UIUtil.invokeLaterIfNeeded {
-        if (project.isDisposed) return@invokeLaterIfNeeded
+      ApplicationManager.getApplication().invokeLater {
+        if (project.isDisposed) return@invokeLater
         DependencyValidationManager.getInstance(project).fireScopeListeners()
       }
     }