mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-11 13:28:04 +02:00
IDE, FindReplace: Refactored, moved away from SourceNotebook
git-svn-id: trunk@24090 -
This commit is contained in:
parent
2b5156b908
commit
b8f4eca4e8
@ -41,8 +41,8 @@ uses
|
||||
Classes, Math, SysUtils, LCLProc, LCLType, Controls, StdCtrls, Forms, Buttons,
|
||||
ExtCtrls, Dialogs, Graphics,
|
||||
SynEditTypes, SynRegExpr, SynEdit,
|
||||
IDEImagesIntf, IDEWindowIntf,
|
||||
LazarusIdeStrConsts, IDEContextHelpEdit;
|
||||
IDEImagesIntf, IDEWindowIntf, LazarusIdeStrConsts, IDEContextHelpEdit,
|
||||
InputHistory;
|
||||
|
||||
type
|
||||
TFindDlgComponent = (fdcText, fdcReplace);
|
||||
@ -92,6 +92,8 @@ type
|
||||
FOnKey: TOnFindDlgKey;
|
||||
fReplaceAllClickedLast: boolean;
|
||||
RegExpr: TRegExpr;
|
||||
DlgHistoryIndex: array[TFindDlgComponent] of integer;
|
||||
DlgUserText: array[TFindDlgComponent] of string;
|
||||
function CheckInput: boolean;
|
||||
function GetComponentText(c: TFindDlgComponent): string;
|
||||
function GetEnableAutoComplete: boolean;
|
||||
@ -109,6 +111,7 @@ type
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure UpdateHints;
|
||||
procedure ResetUserHistory;
|
||||
public
|
||||
property Options: TSynSearchOptions read GetOptions write SetOptions;
|
||||
property EnableAutoComplete: boolean read GetEnableAutoComplete
|
||||
@ -209,17 +212,81 @@ begin
|
||||
EnableAutoCompleteSpeedButton.Hint:=lisAutoCompletionOff;
|
||||
end;
|
||||
|
||||
procedure TLazFindReplaceDialog.ResetUserHistory;
|
||||
var
|
||||
c: TFindDlgComponent;
|
||||
begin
|
||||
for c := Low(TFindDlgComponent) to High(TFindDlgComponent) do
|
||||
DlgHistoryIndex[c] := -1;
|
||||
end;
|
||||
|
||||
procedure TLazFindReplaceDialog.TextToFindComboBoxKeyDown(
|
||||
Sender: TObject; var Key:Word; Shift:TShiftState);
|
||||
var Component: TFindDlgComponent;
|
||||
var
|
||||
Component: TFindDlgComponent;
|
||||
HistoryList: TStringList;
|
||||
CurText: string;
|
||||
CurIndex: integer;
|
||||
|
||||
procedure SetHistoryText;
|
||||
var s: string;
|
||||
begin
|
||||
if DlgHistoryIndex[Component]>=0 then
|
||||
s := HistoryList[DlgHistoryIndex[Component]]
|
||||
else
|
||||
s := DlgUserText[Component];
|
||||
//writeln(' SetHistoryText "',s,'"');
|
||||
ComponentText[Component]:=s
|
||||
end;
|
||||
|
||||
procedure FetchFocus;
|
||||
begin
|
||||
if Sender is TWinControl then
|
||||
TWinControl(Sender).SetFocus;
|
||||
end;
|
||||
|
||||
begin
|
||||
//debugln('TLazFindReplaceDialog.TextToFindComboBoxKeyDown Key=',Key,' RETURN=',VK_RETURN,' TAB=',VK_TAB,' DOWN=',VK_DOWN,' UP=',VK_UP);
|
||||
if Sender=TextToFindComboBox then
|
||||
Component:=fdcText
|
||||
else
|
||||
Component:=fdcReplace;
|
||||
|
||||
if Assigned(OnKey) then begin
|
||||
if Sender=TextToFindComboBox then
|
||||
Component:=fdcText
|
||||
else
|
||||
Component:=fdcReplace;
|
||||
OnKey(Sender, Key, Shift, Component);
|
||||
end
|
||||
else
|
||||
begin
|
||||
if Component=fdcText then
|
||||
HistoryList:= InputHistories.FindHistory
|
||||
else
|
||||
HistoryList:= InputHistories.ReplaceHistory;
|
||||
CurIndex := DlgHistoryIndex[Component];
|
||||
CurText := ComponentText[Component];
|
||||
if Key=VK_UP then begin
|
||||
// go forward in history
|
||||
if CurIndex >= 0 then begin
|
||||
if (HistoryList[CurIndex] <> CurText) then
|
||||
DlgUserText[Component] := CurText; // save user text
|
||||
dec(DlgHistoryIndex[Component]);
|
||||
SetHistoryText;
|
||||
end;
|
||||
FetchFocus;
|
||||
Key:=VK_UNKNOWN;
|
||||
end
|
||||
else if Key=VK_DOWN then begin
|
||||
// go back in history
|
||||
if (CurIndex<0)
|
||||
or (HistoryList[CurIndex] <> CurText) then
|
||||
DlgUserText[Component] := CurText; // save user text
|
||||
if CurIndex < HistoryList.Count-1 then
|
||||
begin
|
||||
inc(DlgHistoryIndex[Component]);
|
||||
SetHistoryText;
|
||||
end;
|
||||
FetchFocus;
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -689,8 +689,6 @@ type
|
||||
procedure BeginAutoFocusLock;
|
||||
procedure EndAutoFocusLock;
|
||||
public
|
||||
FindReplaceDlgHistoryIndex: array[TFindDlgComponent] of integer;
|
||||
FindReplaceDlgUserText: array[TFindDlgComponent] of string;
|
||||
ControlDocker: TLazControlDocker;
|
||||
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
@ -737,7 +735,6 @@ type
|
||||
procedure ToggleObjectInspClicked(Sender: TObject);
|
||||
|
||||
// find / replace text
|
||||
procedure InitFindDialog;
|
||||
procedure FindClicked(Sender: TObject);
|
||||
procedure FindNextClicked(Sender: TObject);
|
||||
procedure FindPreviousClicked(Sender: TObject);
|
||||
@ -807,8 +804,6 @@ type
|
||||
procedure RegisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated;
|
||||
procedure UnregisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated;
|
||||
|
||||
procedure FindReplaceDlgKey(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState; FindDlgComponent: TFindDlgComponent);
|
||||
procedure SetupShortCuts;
|
||||
|
||||
function GetCapabilities: TNoteBookCapabilities;
|
||||
@ -1362,8 +1357,7 @@ var
|
||||
bSelectedTextOption: Boolean;
|
||||
DlgResult: TModalResult;
|
||||
begin
|
||||
if SourceNotebook<>nil then
|
||||
SourceNotebook.InitFindDialog;
|
||||
LazFindReplaceDialog.ResetUserHistory;
|
||||
//debugln('TSourceEditor.StartFindAndReplace A LazFindReplaceDialog.FindText="',dbgstr(LazFindReplaceDialog.FindText),'"');
|
||||
if ReadOnly then Replace := False;
|
||||
NewOptions:=LazFindReplaceDialog.Options;
|
||||
@ -5493,68 +5487,6 @@ Begin
|
||||
Result := (not assigned(Notebook)) or (PageCount = 0);
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.FindReplaceDlgKey(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState; FindDlgComponent: TFindDlgComponent);
|
||||
var
|
||||
HistoryList: TStringList;
|
||||
CurText: string;
|
||||
CurIndex: integer;
|
||||
|
||||
procedure SetHistoryText;
|
||||
var s: string;
|
||||
begin
|
||||
if FindReplaceDlgHistoryIndex[FindDlgComponent]>=0 then
|
||||
s:=HistoryList[FindReplaceDlgHistoryIndex[FindDlgComponent]]
|
||||
else
|
||||
s:=FindReplaceDlgUserText[FindDlgComponent];
|
||||
//writeln(' SetHistoryText "',s,'"');
|
||||
LazFindReplaceDialog.ComponentText[FindDlgComponent]:=s
|
||||
end;
|
||||
|
||||
procedure FetchFocus;
|
||||
begin
|
||||
if Sender is TWinControl then
|
||||
TWinControl(Sender).SetFocus;
|
||||
end;
|
||||
|
||||
begin
|
||||
if FindDlgComponent=fdcText then
|
||||
HistoryList:=InputHistories.FindHistory
|
||||
else
|
||||
HistoryList:=InputHistories.ReplaceHistory;
|
||||
CurIndex:=FindReplaceDlgHistoryIndex[FindDlgComponent];
|
||||
CurText:=LazFindReplaceDialog.ComponentText[FindDlgComponent];
|
||||
//writeln('TSourceNotebook.FindReplaceDlgKey CurIndex=',CurIndex,' CurText="',CurText,'"');
|
||||
if Key=VK_UP then begin
|
||||
// go forward in history
|
||||
if CurIndex>=0 then begin
|
||||
if (HistoryList[CurIndex]<>CurText) then begin
|
||||
// save user text
|
||||
FindReplaceDlgUserText[FindDlgComponent]:=CurText;
|
||||
end;
|
||||
dec(FindReplaceDlgHistoryIndex[FindDlgComponent]);
|
||||
SetHistoryText;
|
||||
end;
|
||||
FetchFocus;
|
||||
Key:=VK_UNKNOWN;
|
||||
end else if Key=VK_DOWN then begin
|
||||
if (CurIndex<0)
|
||||
or (HistoryList[CurIndex]<>CurText) then
|
||||
begin
|
||||
// save user text
|
||||
FindReplaceDlgUserText[FindDlgComponent]:=CurText;
|
||||
end;
|
||||
// go back in history
|
||||
if CurIndex<HistoryList.Count-1 then
|
||||
begin
|
||||
inc(FindReplaceDlgHistoryIndex[FindDlgComponent]);
|
||||
SetHistoryText;
|
||||
end;
|
||||
FetchFocus;
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.SetupShortCuts;
|
||||
|
||||
function GetCommand(ACommand: Word): TIDECommand; inline;
|
||||
@ -6687,14 +6619,6 @@ begin
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TSourceNotebook.InitFindDialog;
|
||||
var c: TFindDlgComponent;
|
||||
begin
|
||||
LazFindReplaceDialog.OnKey:=@FindReplaceDlgKey;
|
||||
for c:=Low(TFindDlgComponent) to High(TFindDlgComponent) do
|
||||
FindReplaceDlgHistoryIndex[c]:=-1;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.UpdateStatusBar;
|
||||
var
|
||||
tempEditor: TSourceEditor;
|
||||
|
Loading…
Reference in New Issue
Block a user