From 2da2caf3dbc2c84004171d2635867da9a26cebf5 Mon Sep 17 00:00:00 2001 From: Aleksandr Krasilnikov Date: Tue, 20 May 2025 12:30:50 +0200 Subject: [PATCH] IJPL-187180 vcs: Automatically close the commit tool window after commit in window/float mode (cherry picked from commit e45f9bfccfd77d38a4bb26630aacb69fcb8aee0d) IJ-MR-163526 GitOrigin-RevId: 8c76c28621310bb5ece25dcd117bcde537fae54d --- .../changes/ui/ChangesViewContentManager.kt | 24 +++++++++++++++++++ .../commit/NonModalCommitWorkflowHandler.kt | 2 ++ 2 files changed, 26 insertions(+) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt index 590e48f3dde5..df38a17d7ba6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt @@ -22,6 +22,7 @@ import com.intellij.ui.content.ContentManagerEvent import com.intellij.ui.content.ContentManagerListener import com.intellij.util.IJSwingUtilities import com.intellij.util.ObjectUtils.tryCast +import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.messages.MessageBusConnection import com.intellij.vcs.commit.CommitMode import com.intellij.vcs.commit.CommitModeManager @@ -367,3 +368,26 @@ fun MessageBusConnection.subscribeOnVcsToolWindowLayoutChanges(updateLayout: Run override fun stateChanged(toolWindowManager: ToolWindowManager) = updateLayout.run() }) } + +/** + * Hides windowed/floating Commit TW when the commit started. Only for default non-modal commit mode + */ +@RequiresEdt +internal fun hideWindowedFloatingTwOnCommit(project: Project) { + val commitTw = getCommitToolWindow(project) ?: return + if (!commitTw.isActive || !commitTw.isVisible) return + + val commitTwType = commitTw.type + + if (commitTwType.isInWindow()) { + commitTw.hide() + } +} + +private fun ToolWindowType.isInWindow(): Boolean { + return this == ToolWindowType.WINDOWED || this == ToolWindowType.FLOATING +} + +private fun getCommitToolWindow(project: Project): ToolWindow? { + return ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.COMMIT) +} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/NonModalCommitWorkflowHandler.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/NonModalCommitWorkflowHandler.kt index 55af77a3910d..fd09a73df163 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/NonModalCommitWorkflowHandler.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/NonModalCommitWorkflowHandler.kt @@ -33,6 +33,7 @@ import com.intellij.openapi.vcs.changes.CommitExecutor import com.intellij.openapi.vcs.changes.actions.DefaultCommitExecutorAction import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.LOCAL_CHANGES +import com.intellij.openapi.vcs.changes.ui.hideWindowedFloatingTwOnCommit import com.intellij.openapi.vcs.checkin.* import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager @@ -300,6 +301,7 @@ abstract class NonModalCommitWorkflowHandler