diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index 77700c972fb6..118687be6d2b 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -527,7 +527,7 @@ cannot.apply.file.already.exists=Cannot apply patch to file {0}: it already exis change.lists.manager.add.unversioned=Add unversioned files change.lists.manager.move.changes.to.list=Move Changes to List vcs.shelf.action.restore.text=Restore -vcs.shelf.action.restore.description=Makes selected already unshelved changelist(s) available for unshelve again +vcs.shelf.action.restore.description=Restore recently deleted {0} vcs.shelf.move.text=Move shelves to the new location vcs.shelf.store.base.content=Shelve base revisions of files under distributed version control systems delete.all.already.unshelved=Delete All Already Unshelved diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/RestoreShelvedChange.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/RestoreShelvedChange.java index 1a8d5374f3a0..aa1a8c698fe5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/RestoreShelvedChange.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/RestoreShelvedChange.java @@ -3,13 +3,19 @@ package com.intellij.openapi.vcs.changes.shelf; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Date; +import java.util.List; + +import static com.intellij.util.containers.ContainerUtil.isEmpty; +import static com.intellij.util.containers.ContainerUtil.notNullize; public class RestoreShelvedChange extends DumbAwareAction { public RestoreShelvedChange() { @@ -19,19 +25,24 @@ public class RestoreShelvedChange extends DumbAwareAction { @Override public void update(@NotNull final AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); - final Collection recycledChanges = e.getData(ShelvedChangesViewManager.SHELVED_RECYCLED_CHANGELIST_KEY); - e.getPresentation().setText(VcsBundle.message("vcs.shelf.action.restore.text")); - e.getPresentation().setDescription(VcsBundle.message("vcs.shelf.action.restore.description")); - e.getPresentation().setEnabled(project != null && recycledChanges != null); + Presentation presentation = e.getPresentation(); + if (project == null || project.isDisposed()) { + presentation.setEnabledAndVisible(false); + return; + } + Collection deletedLists = notNullize(e.getData(ShelvedChangesViewManager.SHELVED_DELETED_CHANGELIST_KEY)); + presentation.setText(VcsBundle.message("vcs.shelf.action.restore.text")); + presentation + .setDescription(VcsBundle.message("vcs.shelf.action.restore.description", StringUtil.pluralize("changelist", deletedLists.size()))); + presentation.setEnabled(!isEmpty(deletedLists)); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); - final Collection recycledChanges = e.getData(ShelvedChangesViewManager.SHELVED_RECYCLED_CHANGELIST_KEY); - if (recycledChanges != null && recycledChanges.size() == 1) { - //noinspection ConstantConditions - ShelveChangesManager.getInstance(project).restoreList(ContainerUtil.getFirstItem(recycledChanges)); - } + ShelveChangesManager shelveChangesManager = ShelveChangesManager.getInstance(project); + List lists = e.getRequiredData(ShelvedChangesViewManager.SHELVED_DELETED_CHANGELIST_KEY); + Date currentDate = new Date(System.currentTimeMillis()); + lists.forEach(l -> shelveChangesManager.restoreList(l, currentDate)); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java index 49b4daf74ecb..bfc3322ad07d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java @@ -951,12 +951,9 @@ public class ShelveChangesManager implements JDOMExternalizable, ProjectComponen return listCopy; } - public void restoreList(@NotNull final ShelvedChangeList changeList) { - ShelvedChangeList list = mySchemeManager.findSchemeByName(changeList.getName()); - if (list != null) { - list.setRecycled(false); - list.updateDate(); - } + public void restoreList(@NotNull final ShelvedChangeList shelvedChangeList, @NotNull Date restoreDate) { + shelvedChangeList.setDeleted(false); + shelvedChangeList.DATE = restoreDate; notifyStateChanged(); }