Merge branch 'nz/shared_shelf'
[idea/community.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / shelf / ShelveChangesManager.java
index 9a4f0bdf767f7948a3b73b5d19bcdb3490ca099f..da65f1d9741b0e5c7e9f0e71ad8dfced5795ae5a 100644 (file)
@@ -24,6 +24,8 @@ package com.intellij.openapi.vcs.changes.shelf;
 
 import com.intellij.lifecycle.PeriodicalTasksCloser;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.application.impl.LaterInvocator;
 import com.intellij.openapi.components.AbstractProjectComponent;
 import com.intellij.openapi.components.PathMacroManager;
@@ -56,7 +58,6 @@ import com.intellij.util.Consumer;
 import com.intellij.util.PathUtil;
 import com.intellij.util.SmartList;
 import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.continuation.*;
 import com.intellij.util.messages.MessageBus;
 import com.intellij.util.messages.Topic;
 import com.intellij.util.text.CharArrayCharSequence;
@@ -64,6 +65,7 @@ import com.intellij.util.text.UniqueNameGenerator;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.vcsUtil.FilesProgress;
 import org.jdom.Element;
+import org.jetbrains.annotations.CalledInAny;
 import org.jdom.Parent;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -461,65 +463,55 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD
     return defaultPath;
   }
 
-  public void unshelveChangeList(@NotNull final ShelvedChangeList changeList, @Nullable final List<ShelvedChange> changes,
-                                 @Nullable final List<ShelvedBinaryFile> binaryFiles, final LocalChangeList targetChangeList) {
-    unshelveChangeList(changeList, changes, binaryFiles, targetChangeList, true);
-  }
-
-  @AsynchronousExecution
-  private void unshelveChangeList(@NotNull final ShelvedChangeList changeList,
-                                  @Nullable final List<ShelvedChange> changes,
-                                  @Nullable final List<ShelvedBinaryFile> binaryFiles,
-                                  @Nullable final LocalChangeList targetChangeList,
-                                  boolean showSuccessNotification) {
-    final Continuation continuation = Continuation.createForCurrentProgress(myProject, true, "Unshelve changes");
-    final GatheringContinuationContext initContext = new GatheringContinuationContext();
-    scheduleUnshelveChangeList(changeList, changes, binaryFiles, targetChangeList, showSuccessNotification, initContext, false,
-                               false, null, null);
-    continuation.run(initContext.getList());
-  }
-
-  @AsynchronousExecution
-  public void scheduleUnshelveChangeList(@NotNull final ShelvedChangeList changeList,
-                                         @Nullable final List<ShelvedChange> changes,
-                                         @Nullable final List<ShelvedBinaryFile> binaryFiles,
-                                         @Nullable final LocalChangeList targetChangeList,
-                                         final boolean showSuccessNotification,
-                                         final ContinuationContext context,
-                                         final boolean systemOperation,
-                                         final boolean reverse,
-                                         final String leftConflictTitle,
-                                         final String rightConflictTitle) {
-    context.next(new TaskDescriptor("", Where.AWT) {
-      @Override
-      public void run(ContinuationContext contextInner) {
-        final List<FilePatch> remainingPatches = new ArrayList<FilePatch>();
-
-        final CommitContext commitContext = new CommitContext();
-        final List<TextFilePatch> textFilePatches;
-        try {
-          textFilePatches = loadTextPatches(myProject, changeList, changes, remainingPatches, commitContext);
-        }
-        catch (IOException e) {
-          LOG.info(e);
-          PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
-          return;
-        }
-        catch (PatchSyntaxException e) {
-          PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
-          LOG.info(e);
-          return;
-        }
+  @CalledInAny
+  public void unshelveChangeList(final ShelvedChangeList changeList,
+                                 @Nullable final List<ShelvedChange> changes,
+                                 @Nullable final List<ShelvedBinaryFile> binaryFiles,
+                                 @Nullable final LocalChangeList targetChangeList,
+                                 boolean showSuccessNotification) {
+    unshelveChangeList(changeList, changes, binaryFiles, targetChangeList, showSuccessNotification, false, false, null, null);
+  }
+
+  @CalledInAny
+  public void unshelveChangeList(final ShelvedChangeList changeList,
+                                 @Nullable final List<ShelvedChange> changes,
+                                 @Nullable final List<ShelvedBinaryFile> binaryFiles,
+                                 @Nullable final LocalChangeList targetChangeList,
+                                 final boolean showSuccessNotification,
+                                 final boolean systemOperation,
+                                 final boolean reverse,
+                                 final String leftConflictTitle,
+                                 final String rightConflictTitle) {
+    final List<FilePatch> remainingPatches = new ArrayList<FilePatch>();
+
+    final CommitContext commitContext = new CommitContext();
+    final List<TextFilePatch> textFilePatches;
+    try {
+      textFilePatches = loadTextPatches(myProject, changeList, changes, remainingPatches, commitContext);
+    }
+    catch (IOException e) {
+      LOG.info(e);
+      PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
+      return;
+    }
+    catch (PatchSyntaxException e) {
+      PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
+      LOG.info(e);
+      return;
+    }
 
-        final List<FilePatch> patches = new ArrayList<FilePatch>(textFilePatches);
+    final List<FilePatch> patches = new ArrayList<FilePatch>(textFilePatches);
 
-        final List<ShelvedBinaryFile> remainingBinaries = new ArrayList<ShelvedBinaryFile>();
-        final List<ShelvedBinaryFile> binaryFilesToUnshelve = getBinaryFilesToUnshelve(changeList, binaryFiles, remainingBinaries);
+    final List<ShelvedBinaryFile> remainingBinaries = new ArrayList<ShelvedBinaryFile>();
+    final List<ShelvedBinaryFile> binaryFilesToUnshelve = getBinaryFilesToUnshelve(changeList, binaryFiles, remainingBinaries);
 
-        for (final ShelvedBinaryFile shelvedBinaryFile : binaryFilesToUnshelve) {
-          patches.add(new ShelvedBinaryFilePatch(shelvedBinaryFile));
-        }
+    for (final ShelvedBinaryFile shelvedBinaryFile : binaryFilesToUnshelve) {
+      patches.add(new ShelvedBinaryFilePatch(shelvedBinaryFile));
+    }
 
+    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+      @Override
+      public void run() {
         final BinaryPatchApplier binaryPatchApplier = new BinaryPatchApplier();
         final PatchApplier<ShelvedBinaryFilePatch> patchApplier =
           new PatchApplier<ShelvedBinaryFilePatch>(myProject, myProject.getBaseDir(),
@@ -527,24 +519,18 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD
                                                    rightConflictTitle);
         patchApplier.setIsSystemOperation(systemOperation);
 
-        // after patch applier part
-        contextInner.next(new TaskDescriptor("", Where.AWT) {
-          @Override
-          public void run(ContinuationContext context) {
-            remainingPatches.addAll(patchApplier.getRemainingPatches());
-
-            if (remainingPatches.isEmpty() && remainingBinaries.isEmpty()) {
-              recycleChangeList(changeList);
-            }
-            else {
-              saveRemainingPatches(changeList, remainingPatches, remainingBinaries, commitContext);
-            }
-          }
-        });
+        remainingPatches.addAll(patchApplier.getRemainingPatches());
+
+        if (remainingPatches.isEmpty() && remainingBinaries.isEmpty()) {
+          recycleChangeList(changeList);
+        }
+        else {
+          saveRemainingPatches(changeList, remainingPatches, remainingBinaries, commitContext);
+        }
 
-        patchApplier.scheduleSelf(showSuccessNotification, contextInner, systemOperation);
+        patchApplier.execute(showSuccessNotification, systemOperation);
       }
-    });
+    }, ModalityState.defaultModalityState());
   }
 
   private static List<TextFilePatch> loadTextPatches(final Project project,