VCS: apply patch, correctly select item in show diff according to grouping by folders...
authorirengrig <Irina.Chernushina@jetbrains.com>
Mon, 15 Mar 2010 10:56:58 +0000 (13:56 +0300)
committerirengrig <Irina.Chernushina@jetbrains.com>
Mon, 15 Mar 2010 10:56:58 +0000 (13:56 +0300)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java

index 9b68b9efec02298cecb82e8517f1dd9a7db9ed0c..1a840a924823a9fe5acd19217d77e72d39c568d0 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.openapi.vcs.changes.patch;
 
+import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.diff.impl.patch.FilePatch;
 import com.intellij.openapi.diff.impl.patch.PatchReader;
@@ -817,8 +818,10 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
   }
 
   private class MyShowDiff extends AnAction {
+    private final MyChangeComparator myMyChangeComparator;
     private MyShowDiff() {
       super("Show Diff", "Show Diff", IconLoader.getIcon("/actions/diff.png"));
+      myMyChangeComparator = new MyChangeComparator();
     }
 
     public void update(AnActionEvent e) {
@@ -828,7 +831,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
     public void actionPerformed(AnActionEvent e) {
       if (myPatches.isEmpty() || (! myContainBasedChanges)) return;
       final List<FilePatchInProgress.PatchChange> changes = getAllChanges();
-      Collections.sort(changes, MyChangeComparator.getInstance());
+      Collections.sort(changes, myMyChangeComparator);
       final List<FilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges();
 
       int selectedIdx = 0;
@@ -852,14 +855,11 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
     }
   }
 
-  private static class MyChangeComparator implements Comparator<FilePatchInProgress.PatchChange> {
-    private static final MyChangeComparator ourInstance = new MyChangeComparator();
-
-    public static MyChangeComparator getInstance() {
-      return ourInstance;
-    }
-
+  private class MyChangeComparator implements Comparator<FilePatchInProgress.PatchChange> {
     public int compare(FilePatchInProgress.PatchChange o1, FilePatchInProgress.PatchChange o2) {
+      if (PropertiesComponent.getInstance(myProject).isTrueValue("ChangesBrowser.SHOW_FLATTEN")) {
+        return o1.getPatchInProgress().getIoCurrentBase().getName().compareTo(o2.getPatchInProgress().getIoCurrentBase().getName());
+      }
       return o1.getPatchInProgress().getIoCurrentBase().compareTo(o2.getPatchInProgress().getIoCurrentBase());
     }
   }