From b28447ec3be0f0d71e2ae2638605f328d8760a73 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 4 Feb 2016 16:02:55 +0300 Subject: [PATCH] IDEA-22363 IDEA-144276 diff: do not show "no differences" in status if all differences ignored --- .../tools/fragmented/UnifiedDiffViewer.java | 30 +++++++++++++----- .../diff/tools/simple/SimpleDiffViewer.java | 31 +++++++++++++------ .../intellij/diff/tools/util/StatusPanel.java | 9 +----- .../src/messages/DiffBundle.properties | 4 ++- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffViewer.java index d037240fd698..0b63705835aa 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffViewer.java @@ -36,6 +36,7 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.undo.UndoManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.diff.LineTokenizer; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actionSystem.EditorActionManager; @@ -297,12 +298,12 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { LineNumberConvertor convertor = builder.getConvertor(); List changedLines = builder.getChangedLines(); - boolean isEqual = builder.isEqual(); + boolean isContentsEqual = builder.isEqual(); CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor.createConvertor1(), convertor.createConvertor2()); - return apply(editorData, builder.getBlocks(), convertor, changedLines, isEqual); + return apply(editorData, builder.getBlocks(), convertor, changedLines, isContentsEqual); } catch (DiffTooBigException e) { return new Runnable() { @@ -377,14 +378,14 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { @NotNull final List blocks, @NotNull final LineNumberConvertor convertor, @NotNull final List changedLines, - final boolean isEqual) { + final boolean isContentsEqual) { return new Runnable() { @Override public void run() { myFoldingModel.updateContext(myRequest, getFoldingModelSettings()); clearDiffPresentation(); - if (isEqual) myPanel.addNotification(DiffNotifications.createEqualContents()); + if (isContentsEqual) myPanel.addNotification(DiffNotifications.createEqualContents()); TIntFunction separatorLines = myFoldingModel.getLineNumberConvertor(); myEditor.getGutterComponentEx().setLineNumberConvertor(mergeConverters(data.getLineConvertor1(), separatorLines), @@ -426,7 +427,7 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { guarderRangeBlocks.add(createGuardedBlock(textLength, textLength)); } - myChangedBlockData = new ChangedBlockData(diffChanges, guarderRangeBlocks, convertor); + myChangedBlockData = new ChangedBlockData(diffChanges, guarderRangeBlocks, convertor, isContentsEqual); myFoldingModel.install(changedLines, myRequest, getFoldingModelSettings()); @@ -1198,9 +1199,15 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { } private class MyStatusPanel extends StatusPanel { + @Nullable @Override - protected int getChangesCount() { - return myChangedBlockData == null ? 0 : myChangedBlockData.getDiffChanges().size(); + protected String getMessage() { + if (myChangedBlockData == null) return null; + int changesCount = myChangedBlockData.getDiffChanges().size(); + if (changesCount == 0 && !myChangedBlockData.isContentsEqual()) { + return DiffBundle.message("diff.all.differences.ignored.text"); + } + return DiffBundle.message("diff.count.differences.status.text", changesCount); } } @@ -1237,13 +1244,16 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { @NotNull private final List myDiffChanges; @NotNull private final List myGuardedRangeBlocks; @NotNull private final LineNumberConvertor myLineNumberConvertor; + private final boolean myIsContentsEqual; public ChangedBlockData(@NotNull List diffChanges, @NotNull List guarderRangeBlocks, - @NotNull LineNumberConvertor lineNumberConvertor) { + @NotNull LineNumberConvertor lineNumberConvertor, + boolean isContentsEqual) { myDiffChanges = diffChanges; myGuardedRangeBlocks = guarderRangeBlocks; myLineNumberConvertor = lineNumberConvertor; + myIsContentsEqual = isContentsEqual; } @NotNull @@ -1260,6 +1270,10 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase { public LineNumberConvertor getLineNumberConvertor() { return myLineNumberConvertor; } + + public boolean isContentsEqual() { + return myIsContentsEqual; + } } private static class CombinedEditorData { diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java index 994603468f57..5c866d44c81e 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java @@ -32,6 +32,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.diff.DiffNavigationContext; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; @@ -66,6 +67,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @NotNull private final List myDiffChanges = new ArrayList(); @NotNull private final List myInvalidDiffChanges = new ArrayList(); + private boolean myIsContentsEqual; @NotNull private final MyFoldingModel myFoldingModel; @NotNull private final MyInitialScrollHelper myInitialScrollHelper = new MyInitialScrollHelper(); @@ -207,10 +209,10 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { lineFragments = DiffUtil.compare(myRequest, texts[0], texts[1], getDiffConfig(), indicator); } - boolean isEqualContents = (lineFragments == null || lineFragments.isEmpty()) && + boolean isContentsEqual = (lineFragments == null || lineFragments.isEmpty()) && StringUtil.equals(texts[0], texts[1]); - return apply(new CompareData(lineFragments, isEqualContents)); + return apply(new CompareData(lineFragments, isContentsEqual)); } catch (DiffTooBigException e) { return applyNotification(DiffNotifications.createDiffTooBig()); @@ -232,7 +234,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { myFoldingModel.updateContext(myRequest, getFoldingModelSettings()); clearDiffPresentation(); - if (data.isEqualContent()) myPanel.addNotification(DiffNotifications.createEqualContents()); + myIsContentsEqual = data.isContentsEqual(); + if (data.isContentsEqual()) myPanel.addNotification(DiffNotifications.createEqualContents()); if (data.getFragments() != null) { for (LineFragment fragment : data.getFragments()) { @@ -282,6 +285,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { // private void destroyChangedBlocks() { + myIsContentsEqual = false; + for (SimpleDiffChange change : myDiffChanges) { change.destroyHighlighter(); } @@ -862,19 +867,25 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { } private class MyStatusPanel extends StatusPanel { + @Nullable @Override - protected int getChangesCount() { - return myDiffChanges.size() + myInvalidDiffChanges.size(); + protected String getMessage() { + if (getHighlightPolicy() == HighlightPolicy.DO_NOT_HIGHLIGHT) return DiffBundle.message("diff.highlighting.disabled.text"); + int changesCount = myDiffChanges.size() + myInvalidDiffChanges.size(); + if (changesCount == 0 && !myIsContentsEqual) { + return DiffBundle.message("diff.all.differences.ignored.text"); + } + return DiffBundle.message("diff.count.differences.status.text", changesCount); } } private static class CompareData { @Nullable private final List myFragments; - private final boolean myEqualContent; + private final boolean myIsContentsEqual; - public CompareData(@Nullable List fragments, boolean equalContent) { + public CompareData(@Nullable List fragments, boolean isContentsEqual) { myFragments = fragments; - myEqualContent = equalContent; + myIsContentsEqual = isContentsEqual; } @Nullable @@ -882,8 +893,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { return myFragments; } - public boolean isEqualContent() { - return myEqualContent; + public boolean isContentsEqual() { + return myIsContentsEqual; } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/StatusPanel.java b/platform/diff-impl/src/com/intellij/diff/tools/util/StatusPanel.java index 786072ba3807..38633c6ac20b 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/StatusPanel.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/StatusPanel.java @@ -15,7 +15,6 @@ */ package com.intellij.diff.tools.util; -import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.AnimatedIcon; import com.intellij.util.ui.AsyncProcessIcon; @@ -62,12 +61,6 @@ public class StatusPanel extends JPanel { @Nullable protected String getMessage() { - int count = getChangesCount(); - if (count == -1) return null; - return DiffBundle.message("diff.count.differences.status.text", count); - } - - protected int getChangesCount() { - return -1; + return null; } } diff --git a/platform/platform-resources-en/src/messages/DiffBundle.properties b/platform/platform-resources-en/src/messages/DiffBundle.properties index d22880cc6dda..ac08cc3ddaff 100644 --- a/platform/platform-resources-en/src/messages/DiffBundle.properties +++ b/platform/platform-resources-en/src/messages/DiffBundle.properties @@ -41,7 +41,9 @@ merge.dialog.cannot.load.file.error.message=Cannot load file: {0} merge.editor.replace.operation.name=Replace merge.editor.insert.operation.name=Insert merge.editor.remove.operation.name=Remove -diff.count.differences.status.text={0, choice, 0#no differences|1#1 difference|2#{0, number} differences} +diff.count.differences.status.text={0, choice, 0#No differences|1#1 difference|2#{0, number} differences} +diff.all.differences.ignored.text=Differences ignored +diff.highlighting.disabled.text=Differences highlighting is off cant.launch.diff.tool.error.message=Can't Launch Diff Tool binary.files.are.identical.message=Binary files are identical files.are.identical.dialog.title=Files Are Identical