diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeListRemoveConfirmation.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeListRemoveConfirmation.kt index a4c2d74b1a63..b571a897a011 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeListRemoveConfirmation.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeListRemoveConfirmation.kt @@ -22,35 +22,50 @@ import com.intellij.openapi.vcs.changes.LocalChangeList import com.intellij.util.ThreeState object ChangeListRemoveConfirmation { - @JvmStatic - fun deleteLists(project: Project, explicitly: Boolean, allLists: Collection, - askIfShouldRemoveChangeLists: (toAsk: List) -> Boolean) { - val manager = ChangeListManager.getInstance(project) + private fun checkCanDeleteChangelist(project: Project, + list: LocalChangeList, + explicitly: Boolean): ThreeState { val activeVcss = ProjectLevelVcsManager.getInstance(project).allActiveVcss - val toAsk = mutableListOf() + var confirmationAsked = false + var removeVetoed = false + + for (vcs in activeVcss) { + val permission = vcs.mayRemoveChangeList(list, explicitly) + if (permission != ThreeState.UNSURE) { + confirmationAsked = true + } + if (permission == ThreeState.NO) { + removeVetoed = true + break + } + } + + if (!confirmationAsked) { + return ThreeState.UNSURE + } + else if (removeVetoed) { + return ThreeState.NO + } + else { + return ThreeState.YES + } + } + + @JvmStatic + fun deleteLists(project: Project, explicitly: Boolean, lists: Collection, + askIfShouldRemoveChangeLists: (toAsk: List) -> Boolean) { + val manager = ChangeListManager.getInstance(project) + val toRemove = mutableListOf() + val toAsk = mutableListOf() - for (list in allLists.mapNotNull { manager.getChangeList(it.id) }) { - var confirmationAsked = false - var removeVetoed = false - - for (vcs in activeVcss) { - val permission = vcs.mayRemoveChangeList(list, explicitly) - if (permission != ThreeState.UNSURE) { - confirmationAsked = true + for (list in lists.mapNotNull { manager.getChangeList(it.id) }) { + when (checkCanDeleteChangelist(project, list, explicitly)) { + ThreeState.UNSURE -> toAsk.add(list) + ThreeState.YES -> toRemove.add(list) + ThreeState.NO -> { } - if (permission == ThreeState.NO) { - removeVetoed = true - break - } - } - - if (!confirmationAsked) { - toAsk.add(list) - } - else if (!removeVetoed) { - toRemove.add(list) } }