Jelajahi Sumber

ADD: Feature [0002367] Add Find, Replace and Goto line commands to Compare files

Alexander Koblov 3 tahun lalu
induk
melakukan
ecba46346d
4 mengubah file dengan 195 tambahan dan 20 penghapusan
  1. 66 16
      src/fdiffer.lfm
  2. 12 0
      src/fdiffer.lrj
  3. 111 3
      src/fdiffer.pas
  4. 6 1
      src/uglobs.pas

+ 66 - 16
src/fdiffer.lfm

@@ -16,7 +16,7 @@ object frmDiffer: TfrmDiffer
   SessionProperties = 'actAutoCompare.Checked;Height;Left;Top;Width;WindowState'
   SessionProperties = 'actAutoCompare.Checked;Height;Left;Top;Width;WindowState'
   ShowHint = True
   ShowHint = True
   ShowInTaskBar = stAlways
   ShowInTaskBar = stAlways
-  LCLVersion = '2.0.7.0'
+  LCLVersion = '2.2.0.4'
   object ToolBar: TToolBar
   object ToolBar: TToolBar
     Left = 0
     Left = 0
     Height = 22
     Height = 22
@@ -115,12 +115,12 @@ object frmDiffer: TfrmDiffer
       Style = tbsSeparator
       Style = tbsSeparator
     end
     end
     object btnEditUndo: TToolButton
     object btnEditUndo: TToolButton
-      Left = 310
+      Left = 249
       Top = 2
       Top = 2
       Action = actEditUndo
       Action = actEditUndo
     end
     end
     object btnEditRedo: TToolButton
     object btnEditRedo: TToolButton
-      Left = 335
+      Left = 269
       Top = 2
       Top = 2
       Action = actEditRedo
       Action = actEditRedo
     end
     end
@@ -333,8 +333,8 @@ object frmDiffer: TfrmDiffer
   end
   end
   object MainMenu: TMainMenu
   object MainMenu: TMainMenu
     Images = dmComData.ilEditorImages
     Images = dmComData.ilEditorImages
-    left = 88
-    top = 136
+    Left = 88
+    Top = 136
     object mnuFile: TMenuItem
     object mnuFile: TMenuItem
       Caption = '&File'
       Caption = '&File'
       object miOpenLeft: TMenuItem
       object miOpenLeft: TMenuItem
@@ -401,13 +401,28 @@ object frmDiffer: TfrmDiffer
         Action = actEditDelete
         Action = actEditDelete
         OnClick = actEditDeleteExecute
         OnClick = actEditDeleteExecute
       end
       end
-      object miDivider9: TMenuItem
-        Caption = '-'
-      end
       object miEditSelectAll: TMenuItem
       object miEditSelectAll: TMenuItem
         Action = actEditSelectAll
         Action = actEditSelectAll
         OnClick = actEditSelectAllExecute
         OnClick = actEditSelectAllExecute
       end
       end
+      object miDivider11: TMenuItem
+        Caption = '-'
+      end
+      object miFind: TMenuItem
+        Action = actFind
+      end
+      object miFindNext: TMenuItem
+        Action = actFindNext
+      end
+      object miFindPrev: TMenuItem
+        Action = actFindPrev
+      end
+      object miFindReplace: TMenuItem
+        Action = actFindReplace
+      end
+      object miGotoLine: TMenuItem
+        Action = actGotoLine
+      end
     end
     end
     object mnuOptions: TMenuItem
     object mnuOptions: TMenuItem
       Caption = '&Options'
       Caption = '&Options'
@@ -503,8 +518,8 @@ object frmDiffer: TfrmDiffer
   end
   end
   object ActionList: TActionList
   object ActionList: TActionList
     Images = dmComData.ilEditorImages
     Images = dmComData.ilEditorImages
-    left = 24
-    top = 136
+    Left = 24
+    Top = 136
     object actSave: TAction
     object actSave: TAction
       Caption = 'Save'
       Caption = 'Save'
       Hint = 'Save'
       Hint = 'Save'
@@ -662,6 +677,41 @@ object frmDiffer: TfrmDiffer
       ImageIndex = 15
       ImageIndex = 15
       OnExecute = actEditSelectAllExecute
       OnExecute = actEditSelectAllExecute
     end
     end
+    object actFind: TAction
+      Category = 'Edit'
+      Caption = '&Find'
+      HelpType = htKeyword
+      Hint = 'Find'
+      ImageIndex = 10
+      OnExecute = actExecute
+    end
+    object actFindNext: TAction
+      Category = 'Edit'
+      Caption = 'Find next'
+      Hint = 'Find next'
+      OnExecute = actExecute
+    end
+    object actFindPrev: TAction
+      Category = 'Edit'
+      Caption = 'Find previous'
+      Hint = 'Find previous'
+      OnExecute = actExecute
+    end
+    object actFindReplace: TAction
+      Category = 'Edit'
+      Caption = '&Replace'
+      HelpType = htKeyword
+      Hint = 'Replace'
+      ImageIndex = 11
+      OnExecute = actExecute
+    end
+    object actGotoLine: TAction
+      Category = 'Edit'
+      Caption = 'Goto Line...'
+      Hint = 'Goto Line'
+      ImageIndex = 16
+      OnExecute = actExecute
+    end
     object actEditRedo: TAction
     object actEditRedo: TAction
       Category = 'Edit'
       Category = 'Edit'
       Caption = 'Redo'
       Caption = 'Redo'
@@ -707,8 +757,8 @@ object frmDiffer: TfrmDiffer
   end
   end
   object ContextMenu: TPopupMenu
   object ContextMenu: TPopupMenu
     Images = dmComData.ilEditorImages
     Images = dmComData.ilEditorImages
-    left = 160
-    top = 136
+    Left = 160
+    Top = 136
     object miUndoContext: TMenuItem
     object miUndoContext: TMenuItem
       Action = actEditUndo
       Action = actEditUndo
       OnClick = actEditUndoExecute
       OnClick = actEditUndoExecute
@@ -741,12 +791,12 @@ object frmDiffer: TfrmDiffer
     end
     end
   end
   end
   object pmEncodingLeft: TPopupMenu
   object pmEncodingLeft: TPopupMenu
-    left = 248
-    top = 136
+    Left = 248
+    Top = 136
   end
   end
   object pmEncodingRight: TPopupMenu
   object pmEncodingRight: TPopupMenu
-    left = 352
-    top = 136
+    Left = 352
+    Top = 136
   end
   end
   object tmProgress: TTimer
   object tmProgress: TTimer
     OnTimer = tmProgressTimer
     OnTimer = tmProgressTimer

+ 12 - 0
src/fdiffer.lrj

@@ -48,8 +48,20 @@
 {"hash":5671589,"name":"tfrmdiffer.acteditpaste.caption","sourcebytes":[80,97,115,116,101],"value":"Paste"},
 {"hash":5671589,"name":"tfrmdiffer.acteditpaste.caption","sourcebytes":[80,97,115,116,101],"value":"Paste"},
 {"hash":78392485,"name":"tfrmdiffer.acteditdelete.caption","sourcebytes":[68,101,108,101,116,101],"value":"Delete"},
 {"hash":78392485,"name":"tfrmdiffer.acteditdelete.caption","sourcebytes":[68,101,108,101,116,101],"value":"Delete"},
 {"hash":171665052,"name":"tfrmdiffer.acteditselectall.caption","sourcebytes":[83,101,108,101,99,116,32,38,65,108,108],"value":"Select &All"},
 {"hash":171665052,"name":"tfrmdiffer.acteditselectall.caption","sourcebytes":[83,101,108,101,99,116,32,38,65,108,108],"value":"Select &All"},
+{"hash":2805828,"name":"tfrmdiffer.actfind.caption","sourcebytes":[38,70,105,110,100],"value":"&Find"},
+{"hash":315460,"name":"tfrmdiffer.actfind.hint","sourcebytes":[70,105,110,100],"value":"Find"},
+{"hash":73859572,"name":"tfrmdiffer.actfindnext.caption","sourcebytes":[70,105,110,100,32,110,101,120,116],"value":"Find next"},
+{"hash":73859572,"name":"tfrmdiffer.actfindnext.hint","sourcebytes":[70,105,110,100,32,110,101,120,116],"value":"Find next"},
+{"hash":97034739,"name":"tfrmdiffer.actfindprev.caption","sourcebytes":[70,105,110,100,32,112,114,101,118,105,111,117,115],"value":"Find previous"},
+{"hash":97034739,"name":"tfrmdiffer.actfindprev.hint","sourcebytes":[70,105,110,100,32,112,114,101,118,105,111,117,115],"value":"Find previous"},
+{"hash":147268901,"name":"tfrmdiffer.actfindreplace.caption","sourcebytes":[38,82,101,112,108,97,99,101],"value":"&Replace"},
+{"hash":147269573,"name":"tfrmdiffer.actfindreplace.hint","sourcebytes":[82,101,112,108,97,99,101],"value":"Replace"},
+{"hash":102945374,"name":"tfrmdiffer.actgotoline.caption","sourcebytes":[71,111,116,111,32,76,105,110,101,46,46,46],"value":"Goto Line..."},
+{"hash":185950757,"name":"tfrmdiffer.actgotoline.hint","sourcebytes":[71,111,116,111,32,76,105,110,101],"value":"Goto Line"},
 {"hash":363439,"name":"tfrmdiffer.acteditredo.caption","sourcebytes":[82,101,100,111],"value":"Redo"},
 {"hash":363439,"name":"tfrmdiffer.acteditredo.caption","sourcebytes":[82,101,100,111],"value":"Redo"},
+{"hash":363439,"name":"tfrmdiffer.acteditredo.hint","sourcebytes":[82,101,100,111],"value":"Redo"},
 {"hash":378031,"name":"tfrmdiffer.acteditundo.caption","sourcebytes":[85,110,100,111],"value":"Undo"},
 {"hash":378031,"name":"tfrmdiffer.acteditundo.caption","sourcebytes":[85,110,100,111],"value":"Undo"},
+{"hash":378031,"name":"tfrmdiffer.acteditundo.hint","sourcebytes":[85,110,100,111],"value":"Undo"},
 {"hash":171783006,"name":"tfrmdiffer.actsaveleftas.caption","sourcebytes":[83,97,118,101,32,76,101,102,116,32,65,115,46,46,46],"value":"Save Left As..."},
 {"hash":171783006,"name":"tfrmdiffer.actsaveleftas.caption","sourcebytes":[83,97,118,101,32,76,101,102,116,32,65,115,46,46,46],"value":"Save Left As..."},
 {"hash":171783006,"name":"tfrmdiffer.actsaveleftas.hint","sourcebytes":[83,97,118,101,32,76,101,102,116,32,65,115,46,46,46],"value":"Save Left As..."},
 {"hash":171783006,"name":"tfrmdiffer.actsaveleftas.hint","sourcebytes":[83,97,118,101,32,76,101,102,116,32,65,115,46,46,46],"value":"Save Left As..."},
 {"hash":18171454,"name":"tfrmdiffer.actsaverightas.caption","sourcebytes":[83,97,118,101,32,82,105,103,104,116,32,65,115,46,46,46],"value":"Save Right As..."},
 {"hash":18171454,"name":"tfrmdiffer.actsaverightas.caption","sourcebytes":[83,97,118,101,32,82,105,103,104,116,32,65,115,46,46,46],"value":"Save Right As..."},

+ 111 - 3
src/fdiffer.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    -------------------------------------------------------------------------
    Internal diff and merge tool
    Internal diff and merge tool
 
 
-   Copyright (C) 2010-2021 Alexander Koblov ([email protected])
+   Copyright (C) 2010-2022 Alexander Koblov ([email protected])
 
 
    This program is free software; you can redistribute it and/or
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    modify it under the terms of the GNU General Public License as
@@ -29,7 +29,7 @@ uses
   Classes, SysUtils, FileUtil, Forms, Controls, Dialogs, Menus, ComCtrls,
   Classes, SysUtils, FileUtil, Forms, Controls, Dialogs, Menus, ComCtrls,
   ActnList, ExtCtrls, EditBtn, Buttons, SynEdit, uSynDiffControls,
   ActnList, ExtCtrls, EditBtn, Buttons, SynEdit, uSynDiffControls,
   uPariterControls, uDiffOND, uFormCommands, uHotkeyManager, uOSForms,
   uPariterControls, uDiffOND, uFormCommands, uHotkeyManager, uOSForms,
-  uBinaryDiffViewer, uShowForm, KASStatusBar, Graphics, StdCtrls;
+  uBinaryDiffViewer, uShowForm, KASStatusBar, Graphics, StdCtrls, fEditSearch;
 
 
 type
 type
 
 
@@ -49,6 +49,11 @@ type
     actEditDelete: TAction;
     actEditDelete: TAction;
     actEditUndo: TAction;
     actEditUndo: TAction;
     actEditRedo: TAction;
     actEditRedo: TAction;
+    actFind: TAction;
+    actFindNext: TAction;
+    actFindPrev: TAction;
+    actFindReplace: TAction;
+    actGotoLine: TAction;
     actEditSelectAll: TAction;
     actEditSelectAll: TAction;
     actEditPaste: TAction;
     actEditPaste: TAction;
     actAbout: TAction;
     actAbout: TAction;
@@ -79,6 +84,7 @@ type
     MainMenu: TMainMenu;
     MainMenu: TMainMenu;
     miAutoCompare: TMenuItem;
     miAutoCompare: TMenuItem;
     miDivider10: TMenuItem;
     miDivider10: TMenuItem;
+    miDivider11: TMenuItem;
     miLineDifferences: TMenuItem;
     miLineDifferences: TMenuItem;
     miEncodingRight: TMenuItem;
     miEncodingRight: TMenuItem;
     miEncodingLeft: TMenuItem;
     miEncodingLeft: TMenuItem;
@@ -89,8 +95,12 @@ type
     miCopyContext: TMenuItem;
     miCopyContext: TMenuItem;
     miCutContext: TMenuItem;
     miCutContext: TMenuItem;
     miDeleteContext: TMenuItem;
     miDeleteContext: TMenuItem;
+    miFind: TMenuItem;
+    miFindNext: TMenuItem;
+    miFindPrevious: TMenuItem;
+    miFindReplace: TMenuItem;
+    miGotoLine: TMenuItem;
     miEditSelectAll: TMenuItem;
     miEditSelectAll: TMenuItem;
-    miDivider9: TMenuItem;
     miEditDelete: TMenuItem;
     miEditDelete: TMenuItem;
     miEditPaste: TMenuItem;
     miEditPaste: TMenuItem;
     miEditCopy: TMenuItem;
     miEditCopy: TMenuItem;
@@ -227,6 +237,7 @@ type
     FWaitData: TWaitData;
     FWaitData: TWaitData;
     FElevate: TDuplicates;
     FElevate: TDuplicates;
     FCommands: TFormCommands;
     FCommands: TFormCommands;
+    FSearchOptions: TEditSearchOptions;
 private
 private
     procedure ShowDialog;
     procedure ShowDialog;
     procedure ShowIdentical;
     procedure ShowIdentical;
@@ -236,6 +247,7 @@ private
     procedure Clear(bLeft, bRight: Boolean);
     procedure Clear(bLeft, bRight: Boolean);
     procedure BuildHashList(bLeft, bRight: Boolean);
     procedure BuildHashList(bLeft, bRight: Boolean);
     procedure ChooseEncoding(SynDiffEdit: TSynDiffEdit);
     procedure ChooseEncoding(SynDiffEdit: TSynDiffEdit);
+    function GetDisplayNumber(LineNumber: Integer): Integer;
     procedure SetColors(cAdded, cDeleted, cModified: TColor);
     procedure SetColors(cAdded, cDeleted, cModified: TColor);
     procedure ChooseEncoding(MenuItem: TMenuItem; Encoding: String);
     procedure ChooseEncoding(MenuItem: TMenuItem; Encoding: String);
     procedure FillEncodingMenu(TheOwner: TMenuItem; MenuHandler: TNotifyEvent; GroupIndex: LongInt);
     procedure FillEncodingMenu(TheOwner: TMenuItem; MenuHandler: TNotifyEvent; GroupIndex: LongInt);
@@ -258,6 +270,11 @@ private
   published
   published
     procedure cm_CopyLeftToRight(const Params: array of string);
     procedure cm_CopyLeftToRight(const Params: array of string);
     procedure cm_CopyRightToLeft(const Params: array of string);
     procedure cm_CopyRightToLeft(const Params: array of string);
+    procedure cm_Find(const Params: array of string);
+    procedure cm_FindNext(const Params: array of string);
+    procedure cm_FindPrev(const Params: array of string);
+    procedure cm_FindReplace(const Params: array of string);
+    procedure cm_GotoLine(const Params: array of string);
     procedure cm_Exit(const Params: array of string);
     procedure cm_Exit(const Params: array of string);
     procedure cm_FirstDifference(const Params: array of string);
     procedure cm_FirstDifference(const Params: array of string);
     procedure cm_LastDifference(const Params: array of string);
     procedure cm_LastDifference(const Params: array of string);
@@ -539,6 +556,11 @@ begin
   actCopyRightToLeft.Enabled:= not actBinaryCompare.Checked;
   actCopyRightToLeft.Enabled:= not actBinaryCompare.Checked;
   actEditUndo.Enabled:= not actBinaryCompare.Checked;
   actEditUndo.Enabled:= not actBinaryCompare.Checked;
   actEditRedo.Enabled:= not actBinaryCompare.Checked;
   actEditRedo.Enabled:= not actBinaryCompare.Checked;
+  actFind.Enabled:= not actBinaryCompare.Checked;
+  actFindNext.Enabled:= not actBinaryCompare.Checked;
+  actFindPrev.Enabled:= not actBinaryCompare.Checked;
+  actFindReplace.Enabled:= not actBinaryCompare.Checked;
+  actGotoLine.Enabled:= not actBinaryCompare.Checked;
   actSave.Enabled:= not actBinaryCompare.Checked;
   actSave.Enabled:= not actBinaryCompare.Checked;
   actSaveAs.Enabled:= not actBinaryCompare.Checked;
   actSaveAs.Enabled:= not actBinaryCompare.Checked;
   actSaveLeft.Enabled:= not actBinaryCompare.Checked;
   actSaveLeft.Enabled:= not actBinaryCompare.Checked;
@@ -1108,6 +1130,77 @@ begin
   SynDiffEditRight.Renumber;
   SynDiffEditRight.Renumber;
 end;
 end;
 
 
+procedure TfrmDiffer.cm_Find(const Params: array of string);
+begin
+  if not actBinaryCompare.Checked then
+  begin
+    ShowSearchReplaceDialog(Self, SynDiffEditActive, cbUnchecked, FSearchOptions);
+  end;
+end;
+
+procedure TfrmDiffer.cm_FindNext(const Params: array of string);
+begin
+  if not actBinaryCompare.Checked then
+  begin
+    if gFirstTextSearch then
+      ShowSearchReplaceDialog(Self, SynDiffEditActive, cbUnchecked, FSearchOptions)
+    else if FSearchOptions.SearchText <> '' then
+    begin
+      DoSearchReplaceText(SynDiffEditActive, False, ssoBackwards in FSearchOptions.Flags, FSearchOptions);
+      FSearchOptions.Flags -= [ssoEntireScope];
+    end;
+  end;
+end;
+
+procedure TfrmDiffer.cm_FindPrev(const Params: array of string);
+begin
+  if not actBinaryCompare.Checked then
+  begin
+    if gFirstTextSearch then
+    begin
+      FSearchOptions.Flags += [ssoBackwards];
+      ShowSearchReplaceDialog(Self, SynDiffEditActive, cbUnchecked, FSearchOptions);
+    end
+    else if FSearchOptions.SearchText <> '' then
+    begin
+      SynDiffEditActive.SelEnd := SynDiffEditActive.SelStart;
+      DoSearchReplaceText(SynDiffEditActive, False, True, FSearchOptions);
+      FSearchOptions.Flags -= [ssoEntireScope];
+    end;
+  end;
+end;
+
+procedure TfrmDiffer.cm_FindReplace(const Params: array of string);
+begin
+  if not actBinaryCompare.Checked then
+  begin
+    ShowSearchReplaceDialog(Self, SynDiffEditActive, cbChecked, FSearchOptions);
+  end;
+end;
+
+procedure TfrmDiffer.cm_GotoLine(const Params: array of string);
+var
+  P: TPoint;
+  Value: String;
+  NewTopLine: Integer;
+begin
+  if not actBinaryCompare.Checked then
+  begin
+    if ShowInputQuery(rsEditGotoLineTitle, rsEditGotoLineQuery, Value) then
+    begin
+      P.X := 1;
+      P.Y := GetDisplayNumber(StrToIntDef(Value, 1));
+      NewTopLine := P.Y - (SynDiffEditActive.LinesInWindow div 2);
+      if NewTopLine < 1 then begin
+        NewTopLine := 1;
+      end;
+      SynDiffEditActive.CaretXY := P;
+      SynDiffEditActive.TopLine := NewTopLine;
+      SynDiffEditActive.SetFocus;
+    end;
+  end;
+end;
+
 procedure TfrmDiffer.cm_Exit(const Params: array of string);
 procedure TfrmDiffer.cm_Exit(const Params: array of string);
 begin
 begin
   Close;
   Close;
@@ -1367,6 +1460,21 @@ begin
     end;
     end;
 end;
 end;
 
 
+function TfrmDiffer.GetDisplayNumber(LineNumber: Integer): Integer;
+var
+  I: Integer;
+begin
+  Result := 1;
+  for I := 0 to SynDiffEditActive.Lines.Count - 1 do
+  begin
+    if SynDiffEditActive.Lines.Number[I] = LineNumber then
+    begin
+      Result := I + 1;
+      Break;
+    end;
+  end;
+end;
+
 procedure TfrmDiffer.ChooseEncoding(MenuItem: TMenuItem; Encoding: String);
 procedure TfrmDiffer.ChooseEncoding(MenuItem: TMenuItem; Encoding: String);
 var
 var
   I: Integer;
   I: Integer;

+ 6 - 1
src/uglobs.pas

@@ -172,7 +172,7 @@ type
 
 
 const
 const
   { Default hotkey list version number }
   { Default hotkey list version number }
-  hkVersion = 54;
+  hkVersion = 55;
   // 54 - In "Viewer" context, added the "W" for "cm_WrapText", "4" for "cm_ShowAsDec", "8" for "cm_ShowOffice".
   // 54 - In "Viewer" context, added the "W" for "cm_WrapText", "4" for "cm_ShowAsDec", "8" for "cm_ShowOffice".
   // 53 - In "Main" context, change shortcut "Alt+`" to "Alt+0" for the "cm_ActivateTabByIndex".
   // 53 - In "Main" context, change shortcut "Alt+`" to "Alt+0" for the "cm_ActivateTabByIndex".
   // 52 - In "Main" context, add shortcut "Ctrl+Shift+B" for "cm_FlatViewSel".
   // 52 - In "Main" context, add shortcut "Ctrl+Shift+B" for "cm_FlatViewSel".
@@ -1232,6 +1232,11 @@ begin
   with HMForm.Hotkeys do
   with HMForm.Hotkeys do
     begin
     begin
       AddIfNotExists(['Ctrl+R'],[],'cm_Reload');
       AddIfNotExists(['Ctrl+R'],[],'cm_Reload');
+      AddIfNotExists([SmkcSuper + 'F' ,'','',
+                      'F7'            ,'',''],'cm_Find');
+      AddIfNotExists(['F3'],[],'cm_FindNext');
+      AddIfNotExists(['Shift+F3'],[],'cm_FindPrev');
+      AddIfNotExists(VK_G, [ssModifier], 'cm_GotoLine');
       AddIfNotExists(['Alt+Down'],[],'cm_NextDifference');
       AddIfNotExists(['Alt+Down'],[],'cm_NextDifference');
       AddIfNotExists(['Alt+Up'],[],'cm_PrevDifference');
       AddIfNotExists(['Alt+Up'],[],'cm_PrevDifference');
       AddIfNotExists(['Alt+Home'],[],'cm_FirstDifference');
       AddIfNotExists(['Alt+Home'],[],'cm_FirstDifference');