diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index fbf2be20db82..7fbb16d28b83 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -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} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java index fff15be6046f..ee8cb77124f6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java @@ -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 klass) { + NotificationsManager notificationsManager = NotificationsManager.getNotificationsManager(); + for (Notification notification : notificationsManager.getNotificationsOfType(klass, myProject)) { + notification.expire(); + } + notificationToShow.notify(myProject); + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfNotification.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfNotification.kt new file mode 100644 index 000000000000..79dc971eeac7 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfNotification.kt @@ -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) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java index d74791102375..2127025a04ab 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java @@ -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()))); + } } }