vcs: hide 'Incoming' widget when not available
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 23 Sep 2021 10:50:45 +0000 (13:50 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 29 Sep 2021 15:34:48 +0000 (15:34 +0000)
GitOrigin-RevId: 2537b9a69a0f90516e7bdd1e080d38b134c9b1b7

platform/vcs-api/vcs-api-core/resources/messages/VcsBundle.properties
platform/vcs-impl/resources/META-INF/VcsExtensions.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.kt

index 28b44862803702d141d8fc83a9cccf038e6134e6..6c8551d5e9a453b51217aa63b978f44559b445a1 100644 (file)
@@ -603,6 +603,7 @@ committed.changes.group.title=Group by
 committed.changes.regex.title=Re&gex
 changelist.details.committed.format=Committed by {0} {1}
 incoming.changes.indicator.tooltip={0} incoming changelists available
+incoming.changes.indicator.name=Incoming Changes
 # suppress inspection "UnusedProperty": used by 3-party plugins
 committed.changes.incorrect.regex.message=Regular expression used in the filter is invalid
 committed.changes.empty.message=There are no committed changes in the repository
index 7a5b75fc15bbed1372d7311cc4122c77dd0ec05d..b0201267ab5ca06e957f9cf7050f196531383334 100644 (file)
                         displayNameSupplierClassName="com.intellij.openapi.vcs.changes.ChangesViewManager$DisplayNameSupplier"
                         isInCommitToolWindow="true"/>
 
-    <statusBarWidgetProvider implementation="com.intellij.openapi.vcs.changes.committed.IncomingChangesIndicatorProvider"/>
+    <statusBarWidgetFactory id="IncomingChanges" implementation="com.intellij.openapi.vcs.changes.committed.IncomingChangesIndicatorFactory"/>
     <editorNotificationProvider implementation="com.intellij.openapi.vcs.changes.committed.OutdatedVersionNotifier"/>
     <editorTabTitleProvider implementation="com.intellij.openapi.vcs.vfs.VcsFileEditorTabTitleProvider"/>
 
               topic="com.intellij.openapi.vcs.VcsMappingListener"/>
     <listener class="com.intellij.openapi.vcs.changes.VcsIgnoreFilesChecker"
               topic="com.intellij.openapi.vcs.VcsMappingListener"/>
+    <listener class="com.intellij.openapi.vcs.changes.committed.IncomingChangesIndicatorFactory$Listener"
+              topic="com.intellij.openapi.vcs.VcsMappingListener"/>
   </projectListeners>
 </idea-plugin>
 
index 9111319fe96c7850184459c6c207cdc9053ec4b1..ed2e1a22102ef44054afdcb5d934e28e893ac9b8 100644 (file)
@@ -5,6 +5,7 @@ import com.intellij.icons.AllIcons
 import com.intellij.openapi.application.runInEdt
 import com.intellij.openapi.diagnostic.logger
 import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Disposer
 import com.intellij.openapi.util.IconLoader.getDisabledIcon
 import com.intellij.openapi.vcs.ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED
 import com.intellij.openapi.vcs.ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN
@@ -17,8 +18,9 @@ import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList
 import com.intellij.openapi.wm.StatusBar
 import com.intellij.openapi.wm.StatusBarWidget
 import com.intellij.openapi.wm.StatusBarWidget.WidgetPresentation
-import com.intellij.openapi.wm.StatusBarWidgetProvider
+import com.intellij.openapi.wm.StatusBarWidgetFactory
 import com.intellij.openapi.wm.ToolWindowManager
+import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
 import com.intellij.util.Consumer
 import java.awt.event.MouseEvent
 import javax.swing.Icon
@@ -26,8 +28,32 @@ import kotlin.properties.Delegates.observable
 
 private val LOG = logger<IncomingChangesIndicator>()
 
-class IncomingChangesIndicatorProvider : StatusBarWidgetProvider {
-  override fun getWidget(project: Project): StatusBarWidget = IncomingChangesIndicator(project)
+class IncomingChangesIndicatorFactory : StatusBarWidgetFactory {
+  companion object {
+    const val ID = "IncomingChanges"
+  }
+
+  override fun getId(): String = ID
+
+  override fun getDisplayName(): String = message("incoming.changes.indicator.name")
+
+  override fun isAvailable(project: Project): Boolean {
+    return IncomingChangesViewProvider.VisibilityPredicate().test(project)
+  }
+
+  override fun createWidget(project: Project): StatusBarWidget = IncomingChangesIndicator(project)
+
+  override fun disposeWidget(widget: StatusBarWidget) {
+    Disposer.dispose(widget)
+  }
+
+  override fun canBeEnabledOn(statusBar: StatusBar): Boolean = true
+
+  class Listener(private val project: Project) : VcsListener {
+    override fun directoryMappingChanged() {
+      project.getService(StatusBarWidgetsManager::class.java).updateWidget(IncomingChangesIndicatorFactory::class.java)
+    }
+  }
 }
 
 private class IncomingChangesIndicator(private val project: Project) : StatusBarWidget, StatusBarWidget.IconPresentation {
@@ -39,7 +65,7 @@ private class IncomingChangesIndicator(private val project: Project) : StatusBar
     statusBar?.updateWidget(ID())
   }
 
-  override fun ID(): String = "IncomingChanges"
+  override fun ID(): String = IncomingChangesIndicatorFactory.ID
 
   override fun getPresentation(): WidgetPresentation = this
 
@@ -72,6 +98,7 @@ private class IncomingChangesIndicator(private val project: Project) : StatusBar
     })
     busConnection.subscribe(VCS_CONFIGURATION_CHANGED, VcsListener { refresh() })
     busConnection.subscribe(VCS_CONFIGURATION_CHANGED_IN_PLUGIN, VcsListener { refresh() })
+    refresh()
   }
 
   override fun dispose() {