diff: "Jump to Source" - do not open temporary binary files
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 24 Oct 2016 15:16:56 +0000 (18:16 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 24 Oct 2016 15:50:38 +0000 (18:50 +0300)
platform/diff-impl/src/com/intellij/diff/DiffContentFactoryImpl.java
platform/diff-impl/src/com/intellij/diff/contents/FileContentImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java

index 4cfd88f3035fe28a24974b7bd3a54722700cac9f..582a151af741ce14eccb0de4bc71af914fb772ec 100644 (file)
@@ -251,7 +251,7 @@ public class DiffContentFactoryImpl extends DiffContentFactoryEx {
                                      @NotNull byte[] content,
                                      @NotNull FilePath filePath) throws IOException {
     if (filePath.getFileType().isBinary()) {
-      return createBinary(project, content, filePath.getFileType(), filePath.getName());
+      return createBinaryImpl(project, content, filePath.getFileType(), filePath.getName(), filePath.getVirtualFile());
     }
 
     return createDocumentFromBytes(project, content, filePath);
@@ -264,7 +264,7 @@ public class DiffContentFactoryImpl extends DiffContentFactoryEx {
                                      @NotNull VirtualFile highlightFile) throws IOException {
     // TODO: check if FileType.UNKNOWN is actually a text ?
     if (highlightFile.getFileType().isBinary()) {
-      return createBinary(project, content, highlightFile.getFileType(), highlightFile.getName());
+      return createBinaryImpl(project, content, highlightFile.getFileType(), highlightFile.getName(), highlightFile);
     }
 
     return createDocumentFromBytes(project, content, highlightFile);
@@ -290,6 +290,15 @@ public class DiffContentFactoryImpl extends DiffContentFactoryEx {
                                   @NotNull byte[] content,
                                   @NotNull FileType type,
                                   @NotNull String fileName) throws IOException {
+    return createBinaryImpl(project, content, type, fileName, null);
+  }
+
+  @NotNull
+  private DiffContent createBinaryImpl(@Nullable Project project,
+                                       @NotNull byte[] content,
+                                       @NotNull FileType type,
+                                       @NotNull String fileName,
+                                       @Nullable VirtualFile highlightFile) throws IOException {
     // workaround - our JarFileSystem and decompilers can't process non-local files
     boolean useTemporalFile = type instanceof ArchiveFileType || BinaryFileTypeDecompilers.INSTANCE.forFileType(type) != null;
 
@@ -302,7 +311,7 @@ public class DiffContentFactoryImpl extends DiffContentFactoryEx {
       file.setWritable(false);
     }
 
-    return create(project, file);
+    return new FileContentImpl(project, file, highlightFile);
   }
 
   @NotNull
index e64bff17a29707cbfbd226b816dcedbe37e45979..26a6095871a406500ec0e91be597df6ae692576b 100644 (file)
@@ -32,19 +32,34 @@ public class FileContentImpl extends DiffContentBase implements FileContent {
   @NotNull private final VirtualFile myFile;
   @Nullable private final Project myProject;
   @NotNull private final FileType myType;
+  @Nullable private final VirtualFile myHighlightFile;
 
   public FileContentImpl(@Nullable Project project, @NotNull VirtualFile file) {
+    this(project, file, getHighlightFile(file));
+  }
+
+  public FileContentImpl(@Nullable Project project,
+                         @NotNull VirtualFile file,
+                         @Nullable VirtualFile highlightFile) {
     assert file.isValid() && !file.isDirectory();
-    myProject = project;
     myFile = file;
+    myProject = project;
     myType = file.getFileType();
+    myHighlightFile = highlightFile;
   }
 
   @Nullable
   @Override
   public Navigatable getNavigatable() {
-    if (myProject == null || myProject.isDefault() || !myFile.isValid()) return null;
-    return new OpenFileDescriptor(myProject, myFile);
+    if (myProject == null || myProject.isDefault()) return null;
+    if (myHighlightFile == null || !myHighlightFile.isValid()) return null;
+    return new OpenFileDescriptor(myProject, myHighlightFile);
+  }
+
+  @Nullable
+  private static VirtualFile getHighlightFile(@NotNull VirtualFile file) {
+    if (file.isInLocalFileSystem()) return file;
+    return null;
   }
 
   @NotNull
index d4fe1491df809e01baf9f550a83fc29152580248..74ff182f3e9214768e8c0e5d6ab7f74df2c960ee 100644 (file)
@@ -226,9 +226,9 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
 
   @NotNull
   private DiffRequest createRequest(@Nullable Project project,
-                                           @NotNull Change change,
-                                           @NotNull UserDataHolder context,
-                                           @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
+                                    @NotNull Change change,
+                                    @NotNull UserDataHolder context,
+                                    @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
     if (ChangesUtil.isTextConflictingChange(change)) { // three side diff
       // FIXME: This part is ugly as a VCS merge subsystem itself.
 
@@ -388,7 +388,7 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
         if (content == null) {
           throw new DiffRequestProducerException("Can't get binary revision content");
         }
-        return contentFactory.createBinary(project, content, filePath.getFileType(), filePath.getName());
+        return contentFactory.createFromBytes(project, content, filePath);
       }
 
       if (revision instanceof ByteBackedContentRevision) {