diff: use new API in FileHistoryDialog
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 2 Jul 2015 15:36:03 +0000 (18:36 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Tue, 4 Aug 2015 13:40:57 +0000 (16:40 +0300)
platform/lvcs-impl/src/com/intellij/history/integration/ui/models/EntireFileDifferenceModel.java
platform/lvcs-impl/src/com/intellij/history/integration/ui/models/FileDifferenceModel.java
platform/lvcs-impl/src/com/intellij/history/integration/ui/models/SelectionDifferenceModel.java
platform/lvcs-impl/src/com/intellij/history/integration/ui/views/FileHistoryDialog.java
platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java
platform/platform-tests/testSrc/com/intellij/history/integration/ui/FileHistoryDialogTest.java
platform/platform-tests/testSrc/com/intellij/history/integration/ui/LocalHistoryUITestCase.java
platform/platform-tests/testSrc/com/intellij/history/integration/ui/SelectionHistoryDialogTest.java

index b0e065af90f9281c19b2c0d9f5c3e7656a407777..dc2e6fce1db2a4dc92f16a15dc2e477d58e77e6e 100644 (file)
 
 package com.intellij.history.integration.ui.models;
 
+import com.intellij.diff.DiffContentFactory;
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.contents.DocumentContent;
 import com.intellij.history.core.tree.Entry;
 import com.intellij.history.integration.IdeaGateway;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.DocumentContent;
-import com.intellij.openapi.diff.SimpleContent;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.project.Project;
 
@@ -67,10 +67,10 @@ public class EntireFileDifferenceModel extends FileDifferenceModel {
   @Override
   protected DiffContent getEditableRightDiffContent(RevisionProcessingProgress p) {
     Document d = getDocument();
-    return DocumentContent.fromDocument(myProject, d);
+    return DiffContentFactory.getInstance().create(myProject, d);
   }
 
-  private SimpleContent getDiffContent(Entry e) {
+  private DocumentContent getDiffContent(Entry e) {
     return createSimpleDiffContent(getContentOf(e), e);
   }
 
index 9b8404b42e2ab988add607aeefed19a1f10d0d88..6879913f63100596da2f34219611fd61b06ab9ff 100644 (file)
 
 package com.intellij.history.integration.ui.models;
 
+import com.intellij.diff.DiffContentFactory;
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.contents.DocumentContent;
 import com.intellij.history.core.tree.Entry;
 import com.intellij.history.integration.IdeaGateway;
 import com.intellij.history.integration.LocalHistoryBundle;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.SimpleContent;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.io.FileUtil;
@@ -70,26 +71,18 @@ public abstract class FileDifferenceModel {
   protected abstract Entry getRightEntry();
 
   public DiffContent getLeftDiffContent(RevisionProcessingProgress p) {
-    if (!canShowLeftEntry(p)) return new SimpleContent("");
+    if (!hasLeftEntry()) return DiffContentFactory.getInstance().create("");
+    if (!isLeftContentAvailable(p)) return DiffContentFactory.getInstance().create("Content not available");
     return doGetLeftDiffContent(p);
   }
 
-  protected abstract DiffContent doGetLeftDiffContent(RevisionProcessingProgress p);
-
   public DiffContent getRightDiffContent(RevisionProcessingProgress p) {
-    if (!canShowRightEntry(p)) return new SimpleContent("");
+    if (!hasRightEntry()) return DiffContentFactory.getInstance().create("");
+    if (!isRightContentAvailable(p)) return DiffContentFactory.getInstance().create("Content not available");
     if (isRightContentCurrent) return getEditableRightDiffContent(p);
     return getReadOnlyRightDiffContent(p);
   }
 
-  private boolean canShowLeftEntry(RevisionProcessingProgress p) {
-    return hasLeftEntry() && isLeftContentAvailable(p);
-  }
-
-  private boolean canShowRightEntry(RevisionProcessingProgress p) {
-    return hasRightEntry() && isRightContentAvailable(p);
-  }
-
   private boolean hasLeftEntry() {
     return getLeftEntry() != null;
   }
@@ -102,12 +95,14 @@ public abstract class FileDifferenceModel {
 
   protected abstract boolean isRightContentAvailable(RevisionProcessingProgress p);
 
+  protected abstract DiffContent doGetLeftDiffContent(RevisionProcessingProgress p);
+
   protected abstract DiffContent getReadOnlyRightDiffContent(RevisionProcessingProgress p);
 
   protected abstract DiffContent getEditableRightDiffContent(RevisionProcessingProgress p);
 
-  protected SimpleContent createSimpleDiffContent(String content, Entry e) {
-    return new SimpleContent(content, myGateway.getFileType(e.getName()));
+  protected DocumentContent createSimpleDiffContent(String content, Entry e) {
+    return DiffContentFactory.getInstance().create(content, myGateway.getFileType(e.getName()));
   }
 
   protected Document getDocument() {
index 608807a8c7be13f32e20c558000cc69a5ede2e94..a98f2dd271680f5b16408b90beb65f922f5f9332 100644 (file)
 
 package com.intellij.history.integration.ui.models;
 
+import com.intellij.diff.DiffContentFactory;
+import com.intellij.diff.actions.DocumentFragmentContent;
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.contents.DocumentContent;
 import com.intellij.history.core.revisions.Revision;
 import com.intellij.history.core.tree.Entry;
 import com.intellij.history.integration.IdeaGateway;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.FragmentContent;
-import com.intellij.openapi.diff.SimpleContent;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.TextRange;
 import com.intellij.util.diff.FilesTooBigForDiffException;
 
 public class SelectionDifferenceModel extends FileDifferenceModel {
@@ -96,10 +98,11 @@ public class SelectionDifferenceModel extends FileDifferenceModel {
     int fromOffset = d.getLineStartOffset(myFrom);
     int toOffset = d.getLineEndOffset(myTo);
 
-    return FragmentContent.fromRangeMarker(d.createRangeMarker(fromOffset, toOffset), myProject);
+    DocumentContent documentContent = DiffContentFactory.getInstance().create(myProject, d);
+    return new DocumentFragmentContent(myProject, documentContent, new TextRange(fromOffset, toOffset));
   }
 
-  private SimpleContent getDiffContent(Revision r, RevisionProcessingProgress p) {
+  private DocumentContent getDiffContent(Revision r, RevisionProcessingProgress p) {
     return createSimpleDiffContent(getContentOf(r, p), r.findEntry());
   }
 
index 82067f8f32d9110d97e429c796fce3da83db2c05..54630e9d43a63f8e7bff1b61fb288fb8700dc924 100644 (file)
 
 package com.intellij.history.integration.ui.views;
 
+import com.intellij.diff.DiffManager;
+import com.intellij.diff.DiffRequestPanel;
 import com.intellij.history.core.LocalHistoryFacade;
 import com.intellij.history.integration.IdeaGateway;
 import com.intellij.history.integration.ui.models.EntireFileHistoryDialogModel;
 import com.intellij.history.integration.ui.models.FileDifferenceModel;
 import com.intellij.history.integration.ui.models.FileHistoryDialogModel;
-import com.intellij.openapi.diff.DiffManager;
-import com.intellij.openapi.diff.DiffPanel;
-import com.intellij.openapi.diff.ex.DiffPanelEx;
-import com.intellij.openapi.diff.ex.DiffPanelOptions;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.Pair;
@@ -37,7 +35,7 @@ import javax.swing.border.Border;
 import java.awt.*;
 
 public class FileHistoryDialog extends HistoryDialog<FileHistoryDialogModel> {
-  private DiffPanel myDiffPanel;
+  private DiffRequestPanel myDiffPanel;
 
   public FileHistoryDialog(@NotNull Project p, IdeaGateway gw, VirtualFile f) {
     this(p, gw, f, true);
@@ -54,9 +52,7 @@ public class FileHistoryDialog extends HistoryDialog<FileHistoryDialogModel> {
 
   @Override
   protected Pair<JComponent, Dimension> createDiffPanel(JPanel root, ExcludingTraversalPolicy traversalPolicy) {
-    myDiffPanel = DiffManager.getInstance().createDiffPanel(getFrame(), myProject, this, null);
-    DiffPanelOptions o = ((DiffPanelEx)myDiffPanel).getOptions();
-    o.setRequestFocusOnNewContent(false);
+    myDiffPanel = DiffManager.getInstance().createRequestPanel(myProject, this, getFrame());
     return Pair.create((JComponent)myDiffPanel.getComponent(), null);
   }
 
@@ -77,7 +73,7 @@ public class FileHistoryDialog extends HistoryDialog<FileHistoryDialogModel> {
     final FileDifferenceModel diffModel = model.getDifferenceModel();
     return new Runnable() {
       public void run() {
-        myDiffPanel.setDiffRequest(createDifference(diffModel));
+        myDiffPanel.setRequest(createDifference(diffModel));
       }
     };
   }
index 4c909aeeb01bdc1bdb98af7260f3a7cf5c8193a5..5d7ae75afd202ec348c3eea96fecab9ff77ffe39 100644 (file)
@@ -17,6 +17,9 @@
 package com.intellij.history.integration.ui.views;
 
 import com.intellij.CommonBundle;
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.requests.ContentDiffRequest;
+import com.intellij.diff.requests.SimpleDiffRequest;
 import com.intellij.history.core.LocalHistoryFacade;
 import com.intellij.history.integration.IdeaGateway;
 import com.intellij.history.integration.LocalHistoryBundle;
@@ -33,8 +36,6 @@ import com.intellij.ide.ui.SplitterProportionsDataImpl;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.SimpleDiffRequest;
 import com.intellij.openapi.help.HelpManager;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.Task;
@@ -42,10 +43,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.*;
 import com.intellij.openapi.ui.popup.Balloon;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.Couple;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.*;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.patch.CreatePatchConfigurationPanel;
@@ -337,8 +335,8 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
 
   protected abstract Runnable doUpdateDiffs(T model);
 
-  protected SimpleDiffRequest createDifference(final FileDifferenceModel m) {
-    final SimpleDiffRequest r = new SimpleDiffRequest(myProject, m.getTitle());
+  protected ContentDiffRequest createDifference(final FileDifferenceModel m) {
+    final Ref<ContentDiffRequest> requestRef = new Ref<ContentDiffRequest>();
 
     new Task.Modal(myProject, message("message.processing.revisions"), false) {
       public void run(@NotNull final ProgressIndicator i) {
@@ -352,14 +350,13 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
             p.processingRightRevision();
             DiffContent right = m.getRightDiffContent(p);
 
-            r.setContents(left, right);
-            r.setContentTitles(m.getLeftTitle(p), m.getRightTitle(p));
+            requestRef.set(new SimpleDiffRequest(m.getTitle(), left, right, m.getLeftTitle(p), m.getRightTitle(p)));
           }
         });
       }
     }.queue();
 
-    return r;
+    return requestRef.get();
   }
 
   private void saveSplitterProportion() {
index c97e204176553d4fa50c3faaff7967272336d7a8..8a138b96187758cfe02beabde767ed635b613359 100644 (file)
 
 package com.intellij.history.integration.ui;
 
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.contents.DocumentContent;
 import com.intellij.history.integration.ui.models.EntireFileHistoryDialogModel;
 import com.intellij.history.integration.ui.models.FileHistoryDialogModel;
 import com.intellij.history.integration.ui.models.NullRevisionsProgress;
 import com.intellij.history.integration.ui.models.RevisionProcessingProgress;
 import com.intellij.history.integration.ui.views.FileHistoryDialog;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.DocumentContent;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -89,7 +89,7 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase {
     FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 0);
 
     assertDiffContents("old", "current", m);
-    assertEquals(DocumentContent.class, getRightDiffContent(m).getClass());
+    assertTrue(getRightDiffContent(m) instanceof DocumentContent);
   }
 
   public void testRevertion() throws Exception {
@@ -110,8 +110,8 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase {
     DiffContent left = getLeftDiffContent(m);
     DiffContent right = getRightDiffContent(m);
 
-    assertEquals(leftContent, new String(left.getBytes()));
-    assertEquals(rightContent, new String(right.getBytes()));
+    assertEquals(leftContent, left);
+    assertEquals(rightContent, right);
   }
 
   private DiffContent getLeftDiffContent(FileHistoryDialogModel m) {
index 421046f8d01cc06fb0a366692500a44658ff1611..36dcb951c1b0baa426460e2e8c5932f2b795da82 100644 (file)
 
 package com.intellij.history.integration.ui;
 
+import com.intellij.diff.contents.DiffContent;
+import com.intellij.diff.contents.DocumentContent;
 import com.intellij.history.integration.IntegrationTestCase;
 import com.intellij.testFramework.SkipInHeadlessEnvironment;
 
 @SkipInHeadlessEnvironment
 public abstract class LocalHistoryUITestCase extends IntegrationTestCase {
+  protected void assertEquals(String expected, DiffContent actual) {
+    actual.onAssigned(true);
+    try {
+      assertEquals(expected, ((DocumentContent)actual).getDocument().getText());
+    } finally {
+      actual.onAssigned(false);
+    }
+  }
 }
index a0ef16e072b90ae490c30e8dbcecc4c1ab718ca3..008a9bb166a98ffaf141831a2fe68200df26525a 100644 (file)
 
 package com.intellij.history.integration.ui;
 
+import com.intellij.diff.actions.DocumentFragmentContent;
+import com.intellij.diff.contents.DiffContent;
 import com.intellij.history.integration.revertion.Reverter;
 import com.intellij.history.integration.ui.models.FileDifferenceModel;
 import com.intellij.history.integration.ui.models.NullRevisionsProgress;
 import com.intellij.history.integration.ui.models.RevisionProcessingProgress;
 import com.intellij.history.integration.ui.views.SelectionHistoryDialog;
 import com.intellij.history.integration.ui.views.SelectionHistoryDialogModel;
-import com.intellij.openapi.diff.DiffContent;
-import com.intellij.openapi.diff.FragmentContent;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -90,8 +90,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
     DiffContent left = dm.getLeftDiffContent(new NullRevisionsProgress());
     DiffContent right = dm.getRightDiffContent(new NullRevisionsProgress());
 
-    assertEquals("b", new String(left.getBytes()));
-    assertEquals("bc", new String(right.getBytes()));
+    assertEquals("b", left);
+    assertEquals("bc", right);
   }
 
   public void testDiffContentsAndTitleForCurrentRevision() throws IOException {
@@ -101,8 +101,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
 
     DiffContent right = dm.getRightDiffContent(new NullRevisionsProgress());
 
-    assertEquals("bcd", new String(right.getBytes()));
-    assertTrue(right instanceof FragmentContent);
+    assertEquals("bcd", right);
+    assertTrue(right instanceof DocumentFragmentContent);
   }
 
   public void testDiffForDeletedAndRecreatedFile() throws Exception {
@@ -114,8 +114,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
 
     initModelOnSecondLineAndSelectRevisions(3, 3);
 
-    assertEquals("b", new String(dm.getLeftDiffContent(new NullRevisionsProgress()).getBytes()));
-    assertEquals("bcd", new String(dm.getRightDiffContent(new NullRevisionsProgress()).getBytes()));
+    assertEquals("b", dm.getLeftDiffContent(new NullRevisionsProgress()));
+    assertEquals("bcd", dm.getRightDiffContent(new NullRevisionsProgress()));
   }
 
   public void testRevert() throws IOException {