vcs: Show "Commit" tool window on explicit action for projects without vcs mappings...
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Tue, 19 Oct 2021 02:13:56 +0000 (05:13 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 19 Oct 2021 03:13:57 +0000 (03:13 +0000)
GitOrigin-RevId: 97ed9b3819032a784ef83a620651bb433dbe7942

platform/vcs-api/vcs-api-core/resources/messages/VcsBundle.properties
platform/vcs-impl/resources/META-INF/VcsActions.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewToolWindowFactory.kt
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsToolWindowEmptyState.kt

index 0c2696be924df1a5d407a0ed9a385a2e7acc6a8e..5e295b3d9fa3baaff35144c43571d4dd1b35c94a 100644 (file)
@@ -1209,3 +1209,8 @@ status.text.vcs.toolwindow=To track changes to code:
 status.text.vcs.toolwindow.create.repository=Create Git repository\u2026
 status.text.vcs.toolwindow.local.history=Use Local History\u2026
 status.text.vcs.toolwindow.help=Version control integration
+
+status.text.commit.toolwindow.create.repository.prefix=To commit changes,
+status.text.commit.toolwindow.create.repository=Create Git repository\u2026
+status.text.commit.toolwindow.local.history.prefix=For recent changes, see
+status.text.commit.toolwindow.local.history=Local History\u2026
\ No newline at end of file
index 64ace0159334c984371d22d376d2351e373d9233..a36161897eec2f14d767f71f1cdf39ed1ba0b095 100644 (file)
 
     <group id="Vcs.ToolWindow.CreateRepository" searchable="false"/>
 
+    <action id="ActivateCommitToolWindow" class="com.intellij.openapi.vcs.changes.ui.ActivateCommitToolWindowAction">
+      <add-to-group group-id="ActivateToolWindowActions"/>
+    </action>
+
     <group id="CommitView.GearActions">
       <action id="CommitView.SwitchToCommitDialog" class="com.intellij.vcs.commit.SwitchToCommitDialogAction"/>
       <group id="CommitView.ShowOnDoubleClick" popup="true" searchable="false">
index e276914157f95f1df4558df3cd376ec26fdf3517..f8d32a0c415f4c8aa7fba4760487484fe24503d2 100644 (file)
@@ -12,7 +12,6 @@ import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.C
 import com.intellij.openapi.wm.ToolWindow
 import com.intellij.openapi.wm.ToolWindowManager
 import com.intellij.openapi.wm.ex.ToolWindowEx
-import com.intellij.openapi.wm.impl.content.ToolWindowContentUi.HIDE_ID_LABEL
 
 private class ChangesViewToolWindowFactory : VcsToolWindowFactory() {
   override fun init(window: ToolWindow) {
@@ -43,14 +42,19 @@ private class CommitToolWindowFactory : VcsToolWindowFactory() {
 
     window as ToolWindowEx
     window.setAdditionalGearActions(ActionManager.getInstance().getAction("CommitView.GearActions") as ActionGroup)
+
+    setEmptyStateBackground(window)
+    window.emptyText?.setCommitViewEmptyState(window.project)
+    window.hideIdLabelIfNotEmptyState()
   }
 
   override fun shouldBeAvailable(project: Project): Boolean =
     project.vcsManager.hasAnyMappings() && project.isCommitToolWindowShown
 
   override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
-    toolWindow.component.putClientProperty(HIDE_ID_LABEL, "true")
     super.createToolWindowContent(project, toolWindow)
+
+    if (toolWindow.contentManager.isEmpty) rebuildContentUi(toolWindow) // to show id label
   }
 }
 
index 514e3904624664ef62ca3235a039b5202d625dc8..4fd77ee45b9b913fc9f36548848c8e6a1c5a1923 100644 (file)
@@ -2,6 +2,8 @@
 package com.intellij.openapi.vcs.changes.ui
 
 import com.intellij.icons.AllIcons
+import com.intellij.ide.IdeBundle
+import com.intellij.ide.actions.ActivateToolWindowAction
 import com.intellij.openapi.actionSystem.*
 import com.intellij.openapi.actionSystem.CommonDataKeys.PROJECT
 import com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE
@@ -12,7 +14,15 @@ import com.intellij.openapi.actionSystem.impl.SimpleDataContext
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.project.guessProjectDir
 import com.intellij.openapi.vcs.VcsBundle.message
+import com.intellij.openapi.wm.ToolWindow
+import com.intellij.openapi.wm.ToolWindowId
+import com.intellij.openapi.wm.impl.content.ToolWindowContentUi
+import com.intellij.openapi.wm.impl.content.ToolWindowContentUi.HIDE_ID_LABEL
 import com.intellij.ui.SimpleTextAttributes.LINK_PLAIN_ATTRIBUTES
+import com.intellij.ui.content.ContentManager
+import com.intellij.ui.content.ContentManagerEvent
+import com.intellij.ui.content.ContentManagerListener
+import com.intellij.ui.content.impl.ContentManagerImpl
 import com.intellij.util.ui.StatusText
 import java.awt.event.InputEvent
 
@@ -34,6 +44,34 @@ internal fun StatusText.setChangesViewEmptyState(project: Project) {
   }
 }
 
+internal fun StatusText.setCommitViewEmptyState(project: Project) {
+  findCreateRepositoryAction()?.let { action ->
+    appendLine(message("status.text.commit.toolwindow.create.repository.prefix"))
+      .appendText(" ")
+      .appendText(message("status.text.commit.toolwindow.create.repository"), LINK_PLAIN_ATTRIBUTES) {
+        invokeAction(project, it.source, action)
+      }
+  }
+  appendLine(message("status.text.commit.toolwindow.local.history.prefix"))
+    .appendText(" ")
+    .appendText(message("status.text.commit.toolwindow.local.history"), LINK_PLAIN_ATTRIBUTES) {
+      invokeAction(project, it.source, ACTION_LOCAL_HISTORY)
+    }
+  appendLine("")
+  appendLine(AllIcons.General.ContextHelp, message("status.text.vcs.toolwindow.help"), LINK_PLAIN_ATTRIBUTES) {
+    invokeAction(project, it.source, ACTION_CONTEXT_HELP)
+  }
+}
+
+internal class ActivateCommitToolWindowAction : ActivateToolWindowAction(ToolWindowId.COMMIT) {
+  init {
+    templatePresentation.setText(IdeBundle.messagePointer("toolwindow.stripe.Commit"))
+    templatePresentation.icon = AllIcons.Toolwindows.ToolWindowCommit
+  }
+
+  override fun hasEmptyState(): Boolean = true
+}
+
 private fun findCreateRepositoryAction(): AnAction? {
   val group = ActionManager.getInstance().getAction("Vcs.ToolWindow.CreateRepository") as? ActionGroup
   return group?.getChildren(null)?.firstOrNull()
@@ -52,4 +90,28 @@ private fun createDataContext(project: Project): DataContext =
     .add(PROJECT, project)
     .add(VIRTUAL_FILE, project.guessProjectDir())
     .add(HELP_ID, "version.control.empty.state")
-    .build()
\ No newline at end of file
+    .build()
+
+
+internal fun ToolWindow.hideIdLabelIfNotEmptyState() =
+  contentManager.addContentManagerListener(object : ContentManagerListener {
+    override fun contentAdded(event: ContentManagerEvent) {
+      if (contentManager.contentCount != 1) return
+
+      component.putClientProperty(HIDE_ID_LABEL, "true")
+      contentManager.updateContentUi()
+    }
+
+    override fun contentRemoved(event: ContentManagerEvent) {
+      if (!contentManager.isEmpty) return
+
+      component.putClientProperty(HIDE_ID_LABEL, null)
+      contentManager.updateContentUi()
+    }
+  })
+
+private fun ContentManager.updateContentUi() {
+  if (this !is ContentManagerImpl) return
+
+  (ui as? ToolWindowContentUi)?.update()
+}
\ No newline at end of file