From 56a0d5804d014ed82a173ef4e0f5f3e15e3915fd Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Sat, 25 May 2019 13:40:18 +0300 Subject: [PATCH] vcs: Auto-include changes (resolved from current context) on invoking non-modal commit (IDEA-212233) GitOrigin-RevId: ffdda3c25e33ce4dac8a0946bb7649d4f4661f0f --- .../actions/AbstractCommonCheckinAction.kt | 19 ++++++++++++------- .../vcs/actions/CommonCheckinFilesAction.kt | 2 ++ .../openapi/vcs/changes/ui/ChangesTree.java | 6 ++++++ .../vcs/commit/ChangesViewCommitPanel.kt | 2 ++ .../ChangesViewCommitWorkflowHandler.kt | 7 +++++++ .../vcs/commit/ChangesViewCommitWorkflowUi.kt | 6 ++++++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt index 18bf997cd91e..e67c4bee73c0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt @@ -76,17 +76,20 @@ abstract class AbstractCommonCheckinAction : AbstractVcsAction(), UpdateInBackgr return DescindingFilesFilter.filterDescindingFiles(roots, project) } + protected open fun isForceUpdateNotEmptyCommitState(): Boolean = false + protected open fun performCheckIn(context: VcsContext, project: Project, roots: Array) { LOG.debug("invoking commit dialog after update") val selectedChanges = context.selectedChanges val selectedUnversioned = context.selectedUnversionedFiles + val initialChangeList = getInitiallySelectedChangeList(context, project) val changesToCommit: Collection val included: Collection<*> if (selectedChanges.isNullOrEmpty() && selectedUnversioned.isEmpty()) { changesToCommit = getChangesIn(project, roots) - included = changesToCommit + included = initialChangeList.changes.intersect(changesToCommit) } else { changesToCommit = selectedChanges.orEmpty().toList() @@ -96,20 +99,22 @@ abstract class AbstractCommonCheckinAction : AbstractVcsAction(), UpdateInBackgr val executor = getExecutor(project) if (executor == null && isNonModalCommit()) { val workflowHandler = (ChangesViewManager.getInstance(project) as? ChangesViewManager)?.commitWorkflowHandler - workflowHandler?.activate() + workflowHandler?.run { + setCommitState(included, isForceUpdateNotEmptyCommitState()) + activate() + } } else { - val initialChangeList = getInitiallySelectedChangeList(context, project) CommitChangeListDialog.commitChanges(project, changesToCommit, included, initialChangeList, executor, null) } } - protected open fun getInitiallySelectedChangeList(context: VcsContext, project: Project): LocalChangeList? { + protected open fun getInitiallySelectedChangeList(context: VcsContext, project: Project): LocalChangeList { val manager = ChangeListManager.getInstance(project) - context.selectedChangeLists?.firstOrNull()?.let { return manager.findChangeList(it.name) } - context.selectedChanges?.firstOrNull()?.let { return manager.getChangeList(it) } - return manager.defaultChangeList + return context.selectedChangeLists?.firstOrNull()?.let { manager.findChangeList(it.name) } + ?: context.selectedChanges?.firstOrNull()?.let { manager.getChangeList(it) } + ?: manager.defaultChangeList } protected open fun getExecutor(project: Project): CommitExecutor? = null diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.kt index 81be03219429..df966cb04b34 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.kt @@ -65,4 +65,6 @@ open class CommonCheckinFilesAction : AbstractCommonCheckinAction() { status != FileStatus.UNKNOWN && status != FileStatus.IGNORED override fun getRoots(dataContext: VcsContext): Array = dataContext.selectedFilePaths + + override fun isForceUpdateNotEmptyCommitState(): Boolean = true } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java index bba2e7549351..ad1f449f220b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java @@ -485,6 +485,12 @@ public abstract class ChangesTree extends Tree implements DataProvider { repaint(); } + public void clearInclusion() { + myIncludedChanges.clear(); + notifyInclusionListener(); + repaint(); + } + public void retainInclusion(@NotNull Collection changes) { if (myIncludedChanges.retainAll(changes)) { notifyInclusionListener(); diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt index fc9155515bf1..3b13afc35ec8 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt @@ -184,6 +184,8 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView) : BorderL override fun getIncludedUnversionedFiles(): List = includedUnderTag(changesView, UNVERSIONED_FILES_TAG).userObjects(VirtualFile::class.java) + override fun isInclusionEmpty(): Boolean = changesView.isInclusionEmpty + override fun clearInclusion() = changesView.clearInclusion() override fun includeIntoCommit(items: Collection<*>) = changesView.includeChanges(items) override fun addInclusionListener(listener: InclusionListener, parent: Disposable) = diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt index 823ae5053c34..43545f86b894 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt @@ -57,6 +57,13 @@ class ChangesViewCommitWorkflowHandler( ui.isDefaultCommitActionEnabled = isDefaultCommitEnabled() } + fun setCommitState(items: Collection<*>, forceIfNotEmpty: Boolean) { + if (forceIfNotEmpty || ui.isInclusionEmpty()) { + ui.clearInclusion() + ui.includeIntoCommit(items) + } + } + fun activate(): Boolean = ui.activate() fun showCommitOptions(isFromToolbar: Boolean, dataContext: DataContext) = diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt index 0fece0aa274b..272ed336fb27 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt @@ -6,5 +6,11 @@ import com.intellij.openapi.actionSystem.DataContext interface ChangesViewCommitWorkflowUi : CommitWorkflowUi { var isDefaultCommitActionEnabled: Boolean + // TODO Looks better to create "interface ItemInclusionModel" to which ChangesTree will delegate + // And just pass such model to CommitWorkflowUi instead of adding include-related methods to CommitWorkflowUi directly + fun isInclusionEmpty(): Boolean + + fun clearInclusion() + fun showCommitOptions(options: CommitOptions, isFromToolbar: Boolean, dataContext: DataContext) } \ No newline at end of file