[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;
This commit is contained in:
Dmitry Cherniachenko
2017-06-08 15:56:39 +03:00
committed by Nadya Zabrodina
parent 2c7a9616ac
commit 05d14efc37
2 changed files with 15 additions and 6 deletions
@@ -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
@@ -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<? extends LocalChangeList> 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<LocalChangeList> 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")