From 05d14efc378f66e634eec54942d074effd6e6795 Mon Sep 17 00:00:00 2001 From: Dmitry Cherniachenko <2sabio@gmail.com> Date: Thu, 8 Jun 2017 15:46:56 +0300 Subject: [PATCH] [vcs]: Delete active changelist without confirmation in some cases * (IDEA-145520) if there are no changes to move and only 1 changelist left then it should be chosen by default as a new active; --- .../src/messages/ActionsBundle.properties | 2 +- .../actions/RemoveChangeListAction.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 44d8716632d0..23d16199528e 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -1248,7 +1248,7 @@ action.ChangesView.NewChangeList.text=New Changelist action.ChangesView.NewChangeList.description=Create new changelist action.ChangesView.Revert.text=_Revert action.ChangesView.Revert.description=Revert selected changes -action.ChangesView.RemoveChangeList.text=Delete Changelists +action.ChangesView.RemoveChangeList.text=Delete {0,choice,0#Changelist|1#Changelists} action.ChangesView.RemoveChangeList.description=Remove changelists and move all changes to {0} action.ChangesView.SetDefault.text=Set Active Changelist action.ChangesView.SetDefault.description=Set changelist to which new changes are placed by default 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 b8d538716fb1..0f1c7f37f3f5 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 @@ -42,6 +42,8 @@ public class RemoveChangeListAction extends AnAction implements DumbAware { Presentation presentation = e.getPresentation(); presentation.setEnabled(visible); + presentation + .setText(ActionsBundle.message("action.ChangesView.RemoveChangeList.text", changeLists != null && changeLists.length > 1 ? 1 : 0)); if (e.getPlace().equals(ActionPlaces.CHANGES_VIEW_POPUP)) { presentation.setVisible(visible); } @@ -86,13 +88,13 @@ public class RemoveChangeListAction extends AnAction implements DumbAware { } private static boolean askIfShouldRemoveChangeLists(@NotNull List lists, Project project) { - for (LocalChangeList list : lists) { - if (list.isDefault()) { - return confirmActiveChangeListRemoval(project, lists, list.getChanges().isEmpty()); - } + boolean activeChangelistSelected = lists.stream().anyMatch(LocalChangeList::isDefault); + boolean haveNoChanges = lists.stream().allMatch(l -> l.getChanges().isEmpty()); + + if (activeChangelistSelected) { + return confirmActiveChangeListRemoval(project, lists, haveNoChanges); } - boolean haveNoChanges = lists.stream().noneMatch(list -> !list.getChanges().isEmpty()); String message = lists.size() == 1 ? VcsBundle.message("changes.removechangelist.warning.text", lists.get(0).getName()) : VcsBundle.message("changes.removechangelist.multiple.warning.text", lists.size()); @@ -107,6 +109,13 @@ public class RemoveChangeListAction extends AnAction implements DumbAware { List remainingLists = ChangeListManager.getInstance(project).getChangeListsCopy(); remainingLists.removeAll(lists); + // don't ask "Which changelist to make active" if there is only one option anyway + // unless there are some changes to be moved - give user a chance to cancel deletion + if (remainingLists.size() == 1 && empty) { + ChangeListManager.getInstance(project).setDefaultChangeList(remainingLists.get(0)); + return true; + } + String[] remainingListsNames = remainingLists.stream().map(ChangeList::getName).toArray(String[]::new); int nameIndex = Messages.showChooseDialog(project, empty ? VcsBundle.message("changes.remove.active.empty.prompt")