From 874afc0153038d4e30fa6cf9917f35e5521f76fc Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Fri, 4 May 2012 19:08:31 +0400 Subject: [PATCH] WI-10885 Recursive Compare: add action "Set overwrite older" --- .../intellij/ide/diff/DirDiffSettings.java | 6 ++++ .../openapi/diff/impl/dir/DirDiffElement.java | 36 ++++++++++++++----- .../diff/impl/dir/DirDiffTableModel.java | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java index 4876fd3c2aa2..034d30e7195d 100644 --- a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java +++ b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java @@ -41,6 +41,7 @@ public class DirDiffSettings { public boolean enableChoosers = true; public CompareMode compareMode = CompareMode.CONTENT; public double compareTimestampAccuracy = 0; + public CustomSourceChooser customSourceChooser; public boolean showInFrame = true; // in dialog otherwise @@ -103,4 +104,9 @@ public class DirDiffSettings { @Nullable String getName(CompareMode mode); } + + public interface CustomSourceChooser { + @Nullable + DiffElement chooseSource(@NotNull DiffElement first, @NotNull DiffElement second); + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java index 9f20c24c356a..16341103141a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java @@ -16,6 +16,7 @@ package com.intellij.openapi.diff.impl.dir; import com.intellij.ide.diff.DiffElement; +import com.intellij.ide.diff.DirDiffSettings; import com.intellij.util.text.DateFormatUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +40,8 @@ public class DirDiffElement { private DirDiffOperation myDefaultOperation; private DTree myNode; - private DirDiffElement(DTree parent, @Nullable DiffElement source, @Nullable DiffElement target, DType type, String name) { + private DirDiffElement(DTree parent, @Nullable DiffElement source, @Nullable DiffElement target, DType type, String name, + @Nullable DirDiffOperation defaultOperation) { myParent = parent.getParent(); myNode = parent; myType = type; @@ -48,7 +50,10 @@ public class DirDiffElement { myTarget = target; myTargetLength = target == null || target.isContainer() ? -1 : target.getSize(); myName = name; - if (type == DType.ERROR) { + if(defaultOperation != null){ + myDefaultOperation = defaultOperation; + } + else if (type == DType.ERROR) { myDefaultOperation = NONE; } else if (isSource()) { @@ -87,28 +92,41 @@ public class DirDiffElement { return timeStamp < 0 ? "" : DateFormatUtil.formatDateTime(timeStamp); } - public static DirDiffElement createChange(DTree parent, @NotNull DiffElement source, @NotNull DiffElement target) { - return new DirDiffElement(parent, source, target, DType.CHANGED, source.getName()); + public static DirDiffElement createChange(DTree parent, + @NotNull DiffElement source, + @NotNull DiffElement target, + @Nullable DirDiffSettings.CustomSourceChooser customSourceChooser) { + DirDiffOperation defaultOperation = null; + if (customSourceChooser != null) { + DiffElement chosenSource = customSourceChooser.chooseSource(source, target); + if (chosenSource == source) { // chosenSource might be null + defaultOperation = COPY_TO; + } + else if (chosenSource == target) { + defaultOperation = COPY_FROM; + } + } + return new DirDiffElement(parent, source, target, DType.CHANGED, source.getName(), defaultOperation); } public static DirDiffElement createError(DTree parent, @Nullable DiffElement source, @Nullable DiffElement target) { - return new DirDiffElement(parent, source, target, DType.ERROR, source == null ? target.getName() : source.getName()); + return new DirDiffElement(parent, source, target, DType.ERROR, source == null ? target.getName() : source.getName(), null); } public static DirDiffElement createSourceOnly(DTree parent, @NotNull DiffElement source) { - return new DirDiffElement(parent, source, null, DType.SOURCE, null); + return new DirDiffElement(parent, source, null, DType.SOURCE, null, null); } public static DirDiffElement createTargetOnly(DTree parent, @NotNull DiffElement target) { - return new DirDiffElement(parent, null, target, DType.TARGET, null); + return new DirDiffElement(parent, null, target, DType.TARGET, null, null); } public static DirDiffElement createDirElement(DTree parent, DiffElement src, DiffElement trg, String name) { - return new DirDiffElement(parent, src, trg, DType.SEPARATOR, name); + return new DirDiffElement(parent, src, trg, DType.SEPARATOR, name, null); } public static DirDiffElement createEqual(DTree parent, @NotNull DiffElement source, @NotNull DiffElement target) { - return new DirDiffElement(parent, source, target, DType.EQUAL, source.getName()); + return new DirDiffElement(parent, source, target, DType.EQUAL, source.getName(), null); } public DType getType() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index 1964b1c72218..47c36d1233ea 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -323,7 +323,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode elements.add(DirDiffElement.createTargetOnly(child, child.getTarget())); break; case CHANGED: - elements.add(DirDiffElement.createChange(child, child.getSource(), child.getTarget())); + elements.add(DirDiffElement.createChange(child, child.getSource(), child.getTarget(), mySettings.customSourceChooser)); break; case EQUAL: elements.add(DirDiffElement.createEqual(child, child.getSource(), child.getTarget()));