From 73604de7bddcc41d283b15fe39314309e4ad2b0a Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 20 Oct 2020 03:40:39 +0300 Subject: [PATCH] [cherry-pick] show staging area with preset message for commit when changelists are disabled GitOrigin-RevId: 67d437970773c35a2048af7599ebd4e53ed0ec8a --- .../src/git4idea/GitApplyChangesProcess.kt | 9 +++++++- .../git4idea/index/GitStageContentProvider.kt | 21 +++++++++++++++++++ .../src/git4idea/index/ui/GitStagePanel.kt | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/GitApplyChangesProcess.kt b/plugins/git4idea/src/git4idea/GitApplyChangesProcess.kt index 6c50e2690b0c..dbcd2a65a37c 100644 --- a/plugins/git4idea/src/git4idea/GitApplyChangesProcess.kt +++ b/plugins/git4idea/src/git4idea/GitApplyChangesProcess.kt @@ -7,6 +7,7 @@ import com.intellij.notification.Notification import com.intellij.notification.NotificationListener import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.application.runInEdt import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsSafe @@ -32,6 +33,7 @@ import git4idea.commands.GitSimpleEventDetector.Event.CHERRY_PICK_CONFLICT import git4idea.commands.GitSimpleEventDetector.Event.LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK import git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector import git4idea.i18n.GitBundle +import git4idea.index.showStagingArea import git4idea.merge.GitConflictResolver import git4idea.merge.GitDefaultMergeDialogCustomizer import git4idea.repo.GitRepository @@ -180,7 +182,12 @@ class GitApplyChangesProcess(private val project: Project, changeList: LocalChangeList, successfulCommits: MutableList, alreadyPicked: MutableList): Boolean { - if (!changeListManager.areChangeListsEnabled()) return false + if (!changeListManager.areChangeListsEnabled()) { + runInEdt { + showStagingArea(project, commitMessage) + } + return false + } val actualList = changeListManager.getChangeList(changeList.id) if (actualList == null) { diff --git a/plugins/git4idea/src/git4idea/index/GitStageContentProvider.kt b/plugins/git4idea/src/git4idea/index/GitStageContentProvider.kt index abc8a541b95a..15d4b1eefdc9 100644 --- a/plugins/git4idea/src/git4idea/index/GitStageContentProvider.kt +++ b/plugins/git4idea/src/git4idea/index/GitStageContentProvider.kt @@ -11,8 +11,11 @@ import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManagerListener import com.intellij.openapi.vcs.changes.ui.ChangesViewContentProvider import com.intellij.ui.content.Content import com.intellij.util.NotNullFunction +import com.intellij.util.concurrency.annotations.RequiresEdt +import com.intellij.util.ui.UIUtil import com.intellij.vcs.commit.CommitTabTitleUpdater import com.intellij.vcsUtil.VcsUtil +import git4idea.index.GitStageContentProvider.Companion.STAGING_AREA_TAB_NAME import git4idea.index.ui.GitStagePanel import org.jetbrains.annotations.Nls import org.jetbrains.annotations.NonNls @@ -71,4 +74,22 @@ class GitStageContentVisibilityPredicate : NotNullFunction { class GitStageDisplayNameSupplier : Supplier { override fun get(): @Nls String = VcsBundle.message("tab.title.commit") +} + +@RequiresEdt +fun showStagingArea(project: Project, commitMessage: String) { + showStagingArea(project) { + it.setCommitMessage(commitMessage) + } +} + +private fun showStagingArea(project: Project, consumer: (GitStagePanel) -> Unit) { + val toolWindow = ChangesViewContentManager.getToolWindowFor(project, STAGING_AREA_TAB_NAME) ?: return + toolWindow.activate({ + val contentManager = ChangesViewContentManager.getInstance(project) as ChangesViewContentManager + val content = contentManager.findContents { it.tabName == STAGING_AREA_TAB_NAME }.singleOrNull() ?: return@activate + + contentManager.setSelectedContent(content, true) + (content.component as? GitStagePanel)?.let(consumer) + }, true) } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/index/ui/GitStagePanel.kt b/plugins/git4idea/src/git4idea/index/ui/GitStagePanel.kt index de75c9a98381..25f67c70936d 100644 --- a/plugins/git4idea/src/git4idea/index/ui/GitStagePanel.kt +++ b/plugins/git4idea/src/git4idea/index/ui/GitStagePanel.kt @@ -155,6 +155,10 @@ internal class GitStagePanel(private val tracker: GitStageTracker, isEditorDiffP } } + internal fun setCommitMessage(commitMessage: String) { + commitPanel.commitMessage.setCommitMessage(commitMessage) + } + override fun dispose() { }