shelf: show only latest notification for undo shelf deletion

* do not keep all "undo delete" notification valid cause it can produce useless data storing; it's enough to show only latest one;
* check that we can restore deleted lists when undo or warn;
* add util method to show only one notification of type;
This commit is contained in:
Nadya Zabrodina
2018-11-06 20:24:37 +03:00
parent 2251e3aaee
commit 5b5f51dfcf
4 changed files with 35 additions and 7 deletions
@@ -361,6 +361,7 @@ patch.apply.partially.applied=Some of the changes in the specified patch were sk
patch.apply.success.applied.text=Patch successfully applied
patch.apply.command=apply patch
shelve.changes.delete.notification={0}{1}{2} deleted successfully
shelve.changes.restore.error=Can''t fully restore {0} shelved {1} as some files were deleted permanently
create.patch.success.confirmation=Successfully created patch {0}
patch.apply.error=Failed to apply patch for file {0}: {1}
patch.load.base.revision.error=Failed to load patch base revision for file {0}: {1}
@@ -183,4 +183,12 @@ public class VcsNotifier {
public Notification logInfo(@NotNull String title, @NotNull String message) {
return notify(SILENT_NOTIFICATION, title, message, NotificationType.INFORMATION);
}
public void showNotificationAndHideExisting(@NotNull Notification notificationToShow, @NotNull Class<? extends Notification> klass) {
NotificationsManager notificationsManager = NotificationsManager.getNotificationsManager();
for (Notification notification : notificationsManager.getNotificationsOfType(klass, myProject)) {
notification.expire();
}
notificationToShow.notify(myProject);
}
}
@@ -0,0 +1,16 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.changes.shelf
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.vcs.VcsNotifier
import com.intellij.xml.util.XmlStringUtil
open class ShelfNotification(groupDisplayId: String,
title: String,
content: String,
type: NotificationType) : Notification(groupDisplayId, title, content, type)
class ShelfDeleteNotification(content: String) : ShelfNotification(VcsNotifier.STANDARD_NOTIFICATION.displayId, "Shelf Deletion",
XmlStringUtil.wrapInHtml(content),
NotificationType.INFORMATION)
@@ -61,7 +61,6 @@ import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import com.intellij.vcsUtil.VcsImplUtil;
import com.intellij.vcsUtil.VcsUtil;
import com.intellij.xml.util.XmlStringUtil;
import one.util.streamex.StreamEx;
import org.jetbrains.annotations.CalledInAwt;
import org.jetbrains.annotations.NonNls;
@@ -651,12 +650,11 @@ public class ShelvedChangesViewManager implements Disposable {
StringUtil.capitalize(VcsBundle.message("shelve.changes.delete.notification", constructDeleteFilesInfoMessage(fileListSize),
changeListSize != 0 && fileListSize != 0 ? " and " : "",
constructShelvedListInfoMessage(changeListSize, getFirstItem(shelvedListsToDelete))));
AnAction showRecentlyDeleted = ActionManager.getInstance().getAction("ShelvedChanges.ShowRecentlyDeleted");
VcsNotifier.getInstance(myProject)
.notifyMinorInfo("Shelf Deletion", XmlStringUtil.wrapInHtml(message),
new UndoShelfDeletionAction(createdDeletedListsWithOriginalDate), NotificationAction
.create(showRecentlyDeleted.getTemplatePresentation().getText(),
(e, n) -> showRecentlyDeleted.actionPerformed(e)));
Notification shelfDeletionNotification = new ShelfDeleteNotification(message);
shelfDeletionNotification.addAction(new UndoShelfDeletionAction(createdDeletedListsWithOriginalDate));
shelfDeletionNotification.addAction(ActionManager.getInstance().getAction("ShelvedChanges.ShowRecentlyDeleted"));
VcsNotifier.getInstance(myProject).showNotificationAndHideExisting(shelfDeletionNotification, ShelfDeleteNotification.class);
}
private class UndoShelfDeletionAction extends NotificationAction {
@@ -670,8 +668,13 @@ public class ShelvedChangesViewManager implements Disposable {
@Override
public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
ShelveChangesManager manager = ShelveChangesManager.getInstance(myProject);
List cantRestoreList = findAll(myListDateMap.keySet(), l -> !myShelveChangesManager.getDeletedLists().contains(l));
myListDateMap.forEach((l, d) -> manager.restoreList(l, d));
notification.expire();
if (!cantRestoreList.isEmpty()) {
VcsNotifier.getInstance(myProject).notifyMinorWarning("Undo Shelf Deletion", VcsBundle
.message("shelve.changes.restore.error", cantRestoreList.size(), StringUtil.pluralize("changelist", cantRestoreList.size())));
}
}
}