vcs: Auto-include changes (resolved from current context) on invoking non-modal commit (IDEA-212233)

GitOrigin-RevId: ffdda3c25e33ce4dac8a0946bb7649d4f4661f0f
This commit is contained in:
Konstantin Kolosovsky
2019-05-26 15:05:06 +03:00
committed by intellij-monorepo-bot
parent a35a9c1e32
commit 56a0d5804d
6 changed files with 35 additions and 7 deletions
@@ -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<FilePath>) {
LOG.debug("invoking commit dialog after update")
val selectedChanges = context.selectedChanges
val selectedUnversioned = context.selectedUnversionedFiles
val initialChangeList = getInitiallySelectedChangeList(context, project)
val changesToCommit: Collection<Change>
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
@@ -65,4 +65,6 @@ open class CommonCheckinFilesAction : AbstractCommonCheckinAction() {
status != FileStatus.UNKNOWN && status != FileStatus.IGNORED
override fun getRoots(dataContext: VcsContext): Array<FilePath> = dataContext.selectedFilePaths
override fun isForceUpdateNotEmptyCommitState(): Boolean = true
}
@@ -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();
@@ -184,6 +184,8 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView) : BorderL
override fun getIncludedUnversionedFiles(): List<VirtualFile> =
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) =
@@ -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) =
@@ -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)
}