Browse Source

ADD: Differ - show warning when the text is identical, but has different line endings or encoding (fixes #146)
ADD: Differ - show warning when the text is identical, but the ignore options are used

Alexander Koblov 4 years ago
parent
commit
43f65f2813
2 changed files with 56 additions and 1 deletions
  1. 52 1
      src/fdiffer.pas
  2. 4 0
      src/ulng.pas

+ 52 - 1
src/fdiffer.pas

@@ -230,6 +230,7 @@ type
 private
 private
     procedure ShowDialog;
     procedure ShowDialog;
     procedure ShowIdentical;
     procedure ShowIdentical;
+    procedure ShowTextIdentical;
     procedure ShowProgressDialog;
     procedure ShowProgressDialog;
     procedure CloseProgressDialog;
     procedure CloseProgressDialog;
     procedure Clear(bLeft, bRight: Boolean);
     procedure Clear(bLeft, bRight: Boolean);
@@ -409,6 +410,14 @@ begin
             Application.QueueAsyncCall(@ShowFirstDifference, 0);
             Application.QueueAsyncCall(@ShowFirstDifference, 0);
             ShowDialog;
             ShowDialog;
           end;
           end;
+        end
+        else if (modifies = 0) and (adds = 0) and (deletes = 0) then
+        begin
+          if (SynDiffEditLeft.Encoding <> SynDiffEditRight.Encoding) or
+             (SynDiffEditLeft.Lines.TextLineBreakStyle <> SynDiffEditRight.Lines.TextLineBreakStyle) then
+          begin
+            ShowTextIdentical;
+          end;
         end;
         end;
       end;
       end;
     finally
     finally
@@ -844,10 +853,40 @@ end;
 procedure TfrmDiffer.ShowIdentical;
 procedure TfrmDiffer.ShowIdentical;
 var
 var
   Message: String;
   Message: String;
+  Encoding, LineBreak: Boolean;
+  DlgType: TMsgDlgType = mtInformation;
 begin
 begin
   Message:= rsDiffFilesIdentical + LineEnding + LineEnding;
   Message:= rsDiffFilesIdentical + LineEnding + LineEnding;
   Message+= edtFileNameLeft.Text + LineEnding + edtFileNameRight.Text;
   Message+= edtFileNameLeft.Text + LineEnding + edtFileNameRight.Text;
-  if MessageDlg(rsToolDiffer, Message, mtWarning, [mbIgnore, mbCancel], 0, mbIgnore) = mrCancel then
+  if not actBinaryCompare.Checked then
+  begin
+    Encoding:= (SynDiffEditLeft.Encoding <> SynDiffEditRight.Encoding);
+    LineBreak:= (SynDiffEditLeft.Lines.TextLineBreakStyle <> SynDiffEditRight.Lines.TextLineBreakStyle);
+    if Encoding or LineBreak then
+    begin
+      DlgType:= mtWarning;
+      Message:= rsDiffTextIdenticalNotMatch;
+      if Encoding then begin
+        Message+= LineEnding + rsDiffTextDifferenceEncoding +
+                  Format(' (%s, %s)', [SynDiffEditLeft.Encoding, SynDiffEditRight.Encoding]);
+      end;
+      if LineBreak then begin
+        Message+= LineEnding + rsDiffTextDifferenceLineEnding;
+      end;
+    end
+    else if actIgnoreCase.Checked or actIgnoreWhiteSpace.Checked then
+    begin
+      DlgType:= mtWarning;
+      Message:= rsDiffTextIdentical;
+      if actIgnoreCase.Checked then begin
+        Message+= LineEnding + actIgnoreCase.Caption;
+      end;
+      if actIgnoreWhiteSpace.Checked then begin
+        Message+= LineEnding + actIgnoreWhiteSpace.Caption;
+      end;
+    end;
+  end;
+  if MessageDlg(rsToolDiffer, Message, DlgType, [mbIgnore, mbCancel], 0, mbIgnore) = mrCancel then
     Close
     Close
   else begin
   else begin
     FShowIdentical:= False;
     FShowIdentical:= False;
@@ -855,6 +894,18 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TfrmDiffer.ShowTextIdentical;
+var
+  Message: String;
+begin
+  Message:= rsDiffTextIdenticalNotMatch;
+  if (SynDiffEditLeft.Encoding <> SynDiffEditRight.Encoding) then
+    Message+= LineEnding + rsDiffTextDifferenceEncoding;
+  if (SynDiffEditLeft.Lines.TextLineBreakStyle <> SynDiffEditRight.Lines.TextLineBreakStyle) then
+    Message+= LineEnding + rsDiffTextDifferenceLineEnding;
+  MessageDlg(rsToolDiffer, Message, mtWarning, [mbOK], 0, mbOK);
+end;
+
 procedure TfrmDiffer.ShowProgressDialog;
 procedure TfrmDiffer.ShowProgressDialog;
 var
 var
   lblPrompt : TLabel;
   lblPrompt : TLabel;

+ 4 - 0
src/ulng.pas

@@ -575,6 +575,10 @@ resourcestring
   rsDiffDeletes = ' Deletes: ';
   rsDiffDeletes = ' Deletes: ';
   rsDiffComparing = 'Comparing...';
   rsDiffComparing = 'Comparing...';
   rsDiffFilesIdentical = 'The two files are identical!';
   rsDiffFilesIdentical = 'The two files are identical!';
+  rsDiffTextIdentical = 'The text is identical, but the following options are used:';
+  rsDiffTextIdenticalNotMatch =  'The text is identical, but the files do not match!'+#$0A+'The following differences were found:';
+  rsDiffTextDifferenceEncoding = 'Encoding';
+  rsDiffTextDifferenceLineEnding = 'Line-endings';
   // Find files dialog
   // Find files dialog
   rsFindSearchFiles = 'Find files';
   rsFindSearchFiles = 'Find files';
   rsFindDefineTemplate = 'Define template';
   rsFindDefineTemplate = 'Define template';