diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index 67c67b3a1802..28ded913bf57 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -222,9 +222,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec listsToBeDeleted.clear(); } - ChangeListRemoveConfirmation.deleteLists(myProject, false, listsToBeDeletedSilently, toAsk -> true); + ChangeListRemoveConfirmation.deleteEmptyInactiveLists(myProject, listsToBeDeletedSilently, toAsk -> true); - ChangeListRemoveConfirmation.deleteLists(myProject, false, listsToBeDeleted, toAsk -> { + ChangeListRemoveConfirmation.deleteEmptyInactiveLists(myProject, listsToBeDeleted, toAsk -> { return myConfig.REMOVE_EMPTY_INACTIVE_CHANGELISTS == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY || showRemoveEmptyChangeListsProposal(myProject, myConfig, toAsk); }); 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 b571a897a011..222e173b9243 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 @@ -53,15 +53,14 @@ object ChangeListRemoveConfirmation { } @JvmStatic - fun deleteLists(project: Project, explicitly: Boolean, lists: Collection, - askIfShouldRemoveChangeLists: (toAsk: List) -> Boolean) { + fun deleteLists(project: Project, lists: Collection) { val manager = ChangeListManager.getInstance(project) val toRemove = mutableListOf() val toAsk = mutableListOf() for (list in lists.mapNotNull { manager.getChangeList(it.id) }) { - when (checkCanDeleteChangelist(project, list, explicitly)) { + when (checkCanDeleteChangelist(project, list, explicitly = true)) { ThreeState.UNSURE -> toAsk.add(list) ThreeState.YES -> toRemove.add(list) ThreeState.NO -> { @@ -69,7 +68,7 @@ object ChangeListRemoveConfirmation { } } - if (toAsk.isNotEmpty() && askIfShouldRemoveChangeLists(toAsk)) { + if (toAsk.isNotEmpty() && RemoveChangeListAction.askIfShouldRemoveChangeLists(project, toAsk)) { toRemove.addAll(toAsk) } @@ -83,4 +82,32 @@ object ChangeListRemoveConfirmation { manager.removeChangeList(defaultList.name) } } + + @JvmStatic + fun deleteEmptyInactiveLists(project: Project, lists: Collection, + confirm: (toAsk: List) -> Boolean) { + val manager = ChangeListManager.getInstance(project) + + val toRemove = mutableListOf() + val toAsk = mutableListOf() + + for (list in lists.mapNotNull { manager.getChangeList(it.id) }) { + if (list.isDefault) continue + + when (checkCanDeleteChangelist(project, list, explicitly = false)) { + ThreeState.UNSURE -> toAsk.add(list) + ThreeState.YES -> toRemove.add(list) + ThreeState.NO -> { + } + } + } + + if (toAsk.isNotEmpty() && confirm(toAsk)) { + toRemove.addAll(toAsk) + } + + toRemove.forEach { + manager.removeChangeList(it.name) + } + } } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RemoveChangeListAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RemoveChangeListAction.java index 3ab19bb4cdbd..7aee8361e4fb 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RemoveChangeListAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RemoveChangeListAction.java @@ -67,12 +67,10 @@ public class RemoveChangeListAction extends AnAction implements DumbAware { final ChangeList[] selectedLists = e.getRequiredData(VcsDataKeys.CHANGE_LISTS); //noinspection unchecked - ChangeListRemoveConfirmation.deleteLists(project, true, (Collection)Arrays.asList(selectedLists), toAsk -> { - return askIfShouldRemoveChangeLists(project, toAsk); - }); + ChangeListRemoveConfirmation.deleteLists(project, (Collection)Arrays.asList(selectedLists)); } - private static boolean askIfShouldRemoveChangeLists(@NotNull Project project, @NotNull List lists) { + public static boolean askIfShouldRemoveChangeLists(@NotNull Project project, @NotNull List lists) { boolean activeChangelistSelected = lists.stream().anyMatch(LocalChangeList::isDefault); if (activeChangelistSelected) { return confirmActiveChangeListRemoval(project, lists);