vcs: simplify - extract method for inactive changelist deletion

We should not silently remove default changelist, so there is no need to ask.
This commit is contained in:
Aleksey Pivovarov
2018-09-26 15:10:43 +03:00
parent 64265f807e
commit f5f0cd4a46
3 changed files with 35 additions and 10 deletions
@@ -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);
});
@@ -53,15 +53,14 @@ object ChangeListRemoveConfirmation {
}
@JvmStatic
fun deleteLists(project: Project, explicitly: Boolean, lists: Collection<LocalChangeList>,
askIfShouldRemoveChangeLists: (toAsk: List<LocalChangeList>) -> Boolean) {
fun deleteLists(project: Project, lists: Collection<LocalChangeList>) {
val manager = ChangeListManager.getInstance(project)
val toRemove = mutableListOf<LocalChangeList>()
val toAsk = mutableListOf<LocalChangeList>()
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<LocalChangeList>,
confirm: (toAsk: List<LocalChangeList>) -> Boolean) {
val manager = ChangeListManager.getInstance(project)
val toRemove = mutableListOf<LocalChangeList>()
val toAsk = mutableListOf<LocalChangeList>()
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)
}
}
}
@@ -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<? extends LocalChangeList> lists) {
public static boolean askIfShouldRemoveChangeLists(@NotNull Project project, @NotNull List<? extends LocalChangeList> lists) {
boolean activeChangelistSelected = lists.stream().anyMatch(LocalChangeList::isDefault);
if (activeChangelistSelected) {
return confirmActiveChangeListRemoval(project, lists);