vcs: allow to modify local content in diff for "Patch applied with conflicts" case
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 20 Aug 2015 13:00:59 +0000 (16:00 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 20 Aug 2015 13:27:01 +0000 (16:27 +0300)
* local content is editable for "Patch applied" case.

platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchDiffRequestFactory.java

index 08c553cf8669a49b122b090a32fc36979f548c06..b73411c517893116c90c2e2b10e0a61a14fc5667 100644 (file)
@@ -47,7 +47,6 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileTypes.StdFileTypes;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.WindowWrapper;
 import com.intellij.openapi.util.BooleanGetter;
 import com.intellij.openapi.util.Computable;
@@ -306,7 +305,8 @@ public class ApplyPatchAction extends DumbAwareAction {
   }
 
   @NotNull
-  public static DiffRequest createBadDiffRequest(@NotNull final VirtualFile file,
+  public static DiffRequest createBadDiffRequest(@Nullable Project project,
+                                                 @NotNull final VirtualFile file,
                                                  @NotNull final ApplyPatchForBaseRevisionTexts texts) throws DiffRequestProducerException {
     if (texts.getLocal() == null) {
       throw new DiffRequestProducerException("Can't show diff for '" + file.getPresentableUrl() + "'");
@@ -317,10 +317,11 @@ public class ApplyPatchAction extends DumbAwareAction {
     final List<String> titles = ContainerUtil.list(VcsBundle.message("diff.title.local"), "Patched (with problems)");
 
     final DiffContentFactory contentFactory = DiffContentFactory.getInstance();
-    final DocumentContent originalContent = contentFactory.create(texts.getLocal().toString(), file.getFileType());
+    DocumentContent localContent = contentFactory.createDocument(project, file);
+    if (localContent == null) localContent = contentFactory.create(texts.getLocal().toString(), file.getFileType());
     final DiffContent mergedContent = contentFactory.create(texts.getPatched(), file.getFileType());
 
-    final List<DiffContent> contents = ContainerUtil.list(originalContent, mergedContent);
+    final List<DiffContent> contents = ContainerUtil.list(localContent, mergedContent);
 
     final DiffRequest request = new SimpleDiffRequest(windowTitle, contents, titles);
     DiffUtil.addNotification(new DiffIsApproximateNotification(), request);
index 4eb32f5a2146e2e8825bc7ae5fc3377cb56ecd18..485bbfd7513a3b3d3f94946bad1831c666633deb 100644 (file)
@@ -20,10 +20,8 @@ import com.intellij.diff.chains.DiffRequestProducerException;
 import com.intellij.diff.contents.DocumentContent;
 import com.intellij.diff.requests.DiffRequest;
 import com.intellij.diff.requests.SimpleDiffRequest;
-import com.intellij.diff.requests.UnknownFileTypeDiffRequest;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.fileTypes.FileType;
-import com.intellij.openapi.fileTypes.UnknownFileType;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Getter;
@@ -71,16 +69,17 @@ public class PatchDiffRequestFactory {
     ApplyPatchForBaseRevisionTexts texts = textsRef.get();
 
     if (texts.getBase() == null) {
-      return ApplyPatchAction.createBadDiffRequest(file, texts);
+      return ApplyPatchAction.createBadDiffRequest(project, file, texts);
     }
     else {
-      DiffContentFactory contentFactory = DiffContentFactory.getInstance();
       String path = FileUtil.toSystemDependentName(file.getPresentableUrl());
       FileType type = file.getFileType();
 
       String windowTitle = VcsBundle.message("patch.apply.conflict.title", path);
 
-      DocumentContent localContent = contentFactory.create(texts.getLocal().toString(), type);
+      DiffContentFactory contentFactory = DiffContentFactory.getInstance();
+      DocumentContent localContent = contentFactory.createDocument(project, file);
+      if (localContent == null) localContent = contentFactory.create(texts.getLocal().toString(), type);
       DocumentContent baseContent = contentFactory.create(texts.getBase().toString(), type);
       DocumentContent patchedContent = contentFactory.create(texts.getPatched(), type);