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

This commit is contained in:
Alexander Koblov 2022-04-16 11:18:00 +03:00
commit ecba46346d
4 changed files with 195 additions and 20 deletions

View file

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

View file

@ -48,8 +48,20 @@
{"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":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.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.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.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..."},

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
Internal diff and merge tool
Copyright (C) 2010-2021 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2010-2022 Alexander Koblov (alexx2000@mail.ru)
This program is free software; you can redistribute it and/or
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,
ActnList, ExtCtrls, EditBtn, Buttons, SynEdit, uSynDiffControls,
uPariterControls, uDiffOND, uFormCommands, uHotkeyManager, uOSForms,
uBinaryDiffViewer, uShowForm, KASStatusBar, Graphics, StdCtrls;
uBinaryDiffViewer, uShowForm, KASStatusBar, Graphics, StdCtrls, fEditSearch;
type
@ -49,6 +49,11 @@ type
actEditDelete: TAction;
actEditUndo: TAction;
actEditRedo: TAction;
actFind: TAction;
actFindNext: TAction;
actFindPrev: TAction;
actFindReplace: TAction;
actGotoLine: TAction;
actEditSelectAll: TAction;
actEditPaste: TAction;
actAbout: TAction;
@ -79,6 +84,7 @@ type
MainMenu: TMainMenu;
miAutoCompare: TMenuItem;
miDivider10: TMenuItem;
miDivider11: TMenuItem;
miLineDifferences: TMenuItem;
miEncodingRight: TMenuItem;
miEncodingLeft: TMenuItem;
@ -89,8 +95,12 @@ type
miCopyContext: TMenuItem;
miCutContext: TMenuItem;
miDeleteContext: TMenuItem;
miFind: TMenuItem;
miFindNext: TMenuItem;
miFindPrevious: TMenuItem;
miFindReplace: TMenuItem;
miGotoLine: TMenuItem;
miEditSelectAll: TMenuItem;
miDivider9: TMenuItem;
miEditDelete: TMenuItem;
miEditPaste: TMenuItem;
miEditCopy: TMenuItem;
@ -227,6 +237,7 @@ type
FWaitData: TWaitData;
FElevate: TDuplicates;
FCommands: TFormCommands;
FSearchOptions: TEditSearchOptions;
private
procedure ShowDialog;
procedure ShowIdentical;
@ -236,6 +247,7 @@ private
procedure Clear(bLeft, bRight: Boolean);
procedure BuildHashList(bLeft, bRight: Boolean);
procedure ChooseEncoding(SynDiffEdit: TSynDiffEdit);
function GetDisplayNumber(LineNumber: Integer): Integer;
procedure SetColors(cAdded, cDeleted, cModified: TColor);
procedure ChooseEncoding(MenuItem: TMenuItem; Encoding: String);
procedure FillEncodingMenu(TheOwner: TMenuItem; MenuHandler: TNotifyEvent; GroupIndex: LongInt);
@ -258,6 +270,11 @@ private
published
procedure cm_CopyLeftToRight(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_FirstDifference(const Params: array of string);
procedure cm_LastDifference(const Params: array of string);
@ -539,6 +556,11 @@ begin
actCopyRightToLeft.Enabled:= not actBinaryCompare.Checked;
actEditUndo.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;
actSaveAs.Enabled:= not actBinaryCompare.Checked;
actSaveLeft.Enabled:= not actBinaryCompare.Checked;
@ -1108,6 +1130,77 @@ begin
SynDiffEditRight.Renumber;
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);
begin
Close;
@ -1367,6 +1460,21 @@ begin
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);
var
I: Integer;

View file

@ -172,7 +172,7 @@ type
const
{ 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".
// 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".
@ -1232,6 +1232,11 @@ begin
with HMForm.Hotkeys do
begin
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+Up'],[],'cm_PrevDifference');
AddIfNotExists(['Alt+Home'],[],'cm_FirstDifference');