IDE, FindReplace: Refactored, moved away from SourceNotebook

git-svn-id: trunk@24090 -
This commit is contained in:
martin 2010-03-18 21:25:19 +00:00
parent 2b5156b908
commit b8f4eca4e8
2 changed files with 75 additions and 84 deletions

View File

@ -41,8 +41,8 @@ uses
Classes, Math, SysUtils, LCLProc, LCLType, Controls, StdCtrls, Forms, Buttons, Classes, Math, SysUtils, LCLProc, LCLType, Controls, StdCtrls, Forms, Buttons,
ExtCtrls, Dialogs, Graphics, ExtCtrls, Dialogs, Graphics,
SynEditTypes, SynRegExpr, SynEdit, SynEditTypes, SynRegExpr, SynEdit,
IDEImagesIntf, IDEWindowIntf, IDEImagesIntf, IDEWindowIntf, LazarusIdeStrConsts, IDEContextHelpEdit,
LazarusIdeStrConsts, IDEContextHelpEdit; InputHistory;
type type
TFindDlgComponent = (fdcText, fdcReplace); TFindDlgComponent = (fdcText, fdcReplace);
@ -92,6 +92,8 @@ type
FOnKey: TOnFindDlgKey; FOnKey: TOnFindDlgKey;
fReplaceAllClickedLast: boolean; fReplaceAllClickedLast: boolean;
RegExpr: TRegExpr; RegExpr: TRegExpr;
DlgHistoryIndex: array[TFindDlgComponent] of integer;
DlgUserText: array[TFindDlgComponent] of string;
function CheckInput: boolean; function CheckInput: boolean;
function GetComponentText(c: TFindDlgComponent): string; function GetComponentText(c: TFindDlgComponent): string;
function GetEnableAutoComplete: boolean; function GetEnableAutoComplete: boolean;
@ -109,6 +111,7 @@ type
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure UpdateHints; procedure UpdateHints;
procedure ResetUserHistory;
public public
property Options: TSynSearchOptions read GetOptions write SetOptions; property Options: TSynSearchOptions read GetOptions write SetOptions;
property EnableAutoComplete: boolean read GetEnableAutoComplete property EnableAutoComplete: boolean read GetEnableAutoComplete
@ -209,17 +212,81 @@ begin
EnableAutoCompleteSpeedButton.Hint:=lisAutoCompletionOff; EnableAutoCompleteSpeedButton.Hint:=lisAutoCompletionOff;
end; end;
procedure TLazFindReplaceDialog.ResetUserHistory;
var
c: TFindDlgComponent;
begin
for c := Low(TFindDlgComponent) to High(TFindDlgComponent) do
DlgHistoryIndex[c] := -1;
end;
procedure TLazFindReplaceDialog.TextToFindComboBoxKeyDown( procedure TLazFindReplaceDialog.TextToFindComboBoxKeyDown(
Sender: TObject; var Key:Word; Shift:TShiftState); 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 begin
//debugln('TLazFindReplaceDialog.TextToFindComboBoxKeyDown Key=',Key,' RETURN=',VK_RETURN,' TAB=',VK_TAB,' DOWN=',VK_DOWN,' UP=',VK_UP); //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 Assigned(OnKey) then begin
if Sender=TextToFindComboBox then
Component:=fdcText
else
Component:=fdcReplace;
OnKey(Sender, Key, Shift, Component); 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;
end; end;

View File

@ -689,8 +689,6 @@ type
procedure BeginAutoFocusLock; procedure BeginAutoFocusLock;
procedure EndAutoFocusLock; procedure EndAutoFocusLock;
public public
FindReplaceDlgHistoryIndex: array[TFindDlgComponent] of integer;
FindReplaceDlgUserText: array[TFindDlgComponent] of string;
ControlDocker: TLazControlDocker; ControlDocker: TLazControlDocker;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -737,7 +735,6 @@ type
procedure ToggleObjectInspClicked(Sender: TObject); procedure ToggleObjectInspClicked(Sender: TObject);
// find / replace text // find / replace text
procedure InitFindDialog;
procedure FindClicked(Sender: TObject); procedure FindClicked(Sender: TObject);
procedure FindNextClicked(Sender: TObject); procedure FindNextClicked(Sender: TObject);
procedure FindPreviousClicked(Sender: TObject); procedure FindPreviousClicked(Sender: TObject);
@ -807,8 +804,6 @@ type
procedure RegisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated; procedure RegisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated;
procedure UnregisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated; procedure UnregisterCompletionPlugin(Plugin: TSourceEditorCompletionPlugin); override; deprecated;
procedure FindReplaceDlgKey(Sender: TObject; var Key: Word;
Shift: TShiftState; FindDlgComponent: TFindDlgComponent);
procedure SetupShortCuts; procedure SetupShortCuts;
function GetCapabilities: TNoteBookCapabilities; function GetCapabilities: TNoteBookCapabilities;
@ -1362,8 +1357,7 @@ var
bSelectedTextOption: Boolean; bSelectedTextOption: Boolean;
DlgResult: TModalResult; DlgResult: TModalResult;
begin begin
if SourceNotebook<>nil then LazFindReplaceDialog.ResetUserHistory;
SourceNotebook.InitFindDialog;
//debugln('TSourceEditor.StartFindAndReplace A LazFindReplaceDialog.FindText="',dbgstr(LazFindReplaceDialog.FindText),'"'); //debugln('TSourceEditor.StartFindAndReplace A LazFindReplaceDialog.FindText="',dbgstr(LazFindReplaceDialog.FindText),'"');
if ReadOnly then Replace := False; if ReadOnly then Replace := False;
NewOptions:=LazFindReplaceDialog.Options; NewOptions:=LazFindReplaceDialog.Options;
@ -5493,68 +5487,6 @@ Begin
Result := (not assigned(Notebook)) or (PageCount = 0); Result := (not assigned(Notebook)) or (PageCount = 0);
end; 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; procedure TSourceNotebook.SetupShortCuts;
function GetCommand(ACommand: Word): TIDECommand; inline; function GetCommand(ACommand: Word): TIDECommand; inline;
@ -6687,14 +6619,6 @@ begin
end; end;
{$ENDIF} {$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; Procedure TSourceNotebook.UpdateStatusBar;
var var
tempEditor: TSourceEditor; tempEditor: TSourceEditor;