1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.vcs.changes
4 import com.intellij.ide.projectView.ProjectView
5 import com.intellij.ide.scopeView.ScopeViewPane
6 import com.intellij.openapi.application.ApplicationManager
7 import com.intellij.openapi.components.serviceIfCreated
8 import com.intellij.openapi.project.Project
9 import com.intellij.openapi.vcs.changes.ChangeList
10 import com.intellij.openapi.vcs.changes.ChangeListAdapter
11 import com.intellij.openapi.vcs.changes.LocalChangeList
12 import com.intellij.openapi.vcs.changes.LocalChangeListsLoadedListener
13 import com.intellij.packageDependencies.DependencyValidationManager
15 class ChangeListScopeViewUpdater(private val project: Project) : ChangeListAdapter() {
16 class InitialRefresh(private val project: Project) : LocalChangeListsLoadedListener {
17 override fun processLoadedLists(lists: MutableList<LocalChangeList>) {
18 updateAvailableScopesList(project)
22 override fun changeListAdded(list: ChangeList) {
23 updateAvailableScopesList(project)
26 override fun changeListRemoved(list: ChangeList) {
27 updateAvailableScopesList(project)
30 override fun changeListRenamed(list: ChangeList, oldName: String) {
31 updateAvailableScopesList(project)
34 override fun changeListAvailabilityChanged() {
35 updateAvailableScopesList(project)
38 override fun changeListsChanged() {
39 updateActiveScope(project)
43 private fun updateActiveScope(project: Project) {
44 ApplicationManager.getApplication().invokeLater {
45 if (project.isDisposed) return@invokeLater
46 val projectView = project.serviceIfCreated<ProjectView>() ?: return@invokeLater
47 val pane = projectView.getProjectViewPaneById(ScopeViewPane.ID) as? ScopeViewPane ?: return@invokeLater
48 if (pane.selectedScope is ChangeListScope) {
49 pane.updateSelectedScope()
54 private fun updateAvailableScopesList(project: Project) {
55 ApplicationManager.getApplication().invokeLater {
56 if (project.isDisposed) return@invokeLater
57 DependencyValidationManager.getInstance(project).fireScopeListeners()