IDE: package editor: implemented find in files

git-svn-id: trunk@48239 -
This commit is contained in:
mattias 2015-03-10 16:27:19 +00:00
parent 2290274ae7
commit cff68418fe
5 changed files with 61 additions and 24 deletions

View File

@ -115,7 +115,7 @@ type
procedure ReplaceText(const StartPos, EndPos: TPoint; const NewText: string);
procedure AskReplace(Sender: TObject; const ASearch, AReplace: string;
Line, Column: integer;
var Action: TSrcEditReplaceAction); virtual; abstract;
out Action: TSrcEditReplaceAction); virtual; abstract;
procedure CopyToClipboard; virtual; abstract;
procedure CutToClipboard; virtual; abstract;

View File

@ -57,13 +57,13 @@ type
end;
function ShowCodeMacroSelectDialog(var Parameter: string): TIDECodeMacro;
function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
implementation
{$R *.lfm}
function ShowCodeMacroSelectDialog(var Parameter: string): TIDECodeMacro;
function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
var
CodeMacroSelectDlg: TCodeMacroSelectDlg;
begin

View File

@ -53,6 +53,7 @@ type
procedure ReplaceCheckBoxChange(Sender: TObject);
procedure WhereRadioGroupClick(Sender: TObject);
private
FProject: TProject;
function GetFindText: string;
function GetOptions: TLazFindInFileSearchOptions;
function GetReplaceText: string;
@ -72,10 +73,14 @@ type
function GetBaseDirectory: string;
procedure LoadHistory;
procedure SaveHistory;
procedure FindInSearchPath(SearchPath: string);
procedure FindInFilesPerDialog(AProject: TProject);
procedure InitFindText;
procedure InitFromLazSearch(Sender: TObject);
procedure FindInFiles(AProject: TProject; const AFindText: string);
function GetResolvedDirectories: string;
function Execute: boolean;
property LazProject: TProject read FProject write FProject;
end;
function FindInFilesDialog: TLazFindInFilesDialog;
@ -373,11 +378,31 @@ begin
InputHistories.Save;
end;
procedure TLazFindInFilesDialog.FindInSearchPath(SearchPath: string);
begin
debugln(['TLazFindInFilesDialog.FindInSearchPath ',SearchPath]);
InitFindText;
LoadHistory;
DirectoriesComboBox.Text:=SearchPath;
WhereRadioGroup.ItemIndex:=ItemIndDirectories;
// disable replace. Find in files is often called,
// but almost never to replace with the same parameters
Options := Options-[fifReplace,fifReplaceAll];
Execute;
end;
procedure TLazFindInFilesDialog.FindInFilesPerDialog(AProject: TProject);
begin
InitFindText;
FindInFiles(AProject, FindText);
end;
procedure TLazFindInFilesDialog.InitFindText;
var
TempEditor: TSourceEditorInterface;
Begin
FindText:='';
NewFindText: String;
begin
NewFindText:='';
TempEditor := SourceEditorManagerIntf.ActiveEditor;
if TempEditor <> nil
then //with TempEditor.EditorComponent do
@ -385,15 +410,14 @@ Begin
if EditorOpts.FindTextAtCursor
then begin
if TempEditor.SelectionAvailable and (TempEditor.BlockBegin.Y = TempEditor.BlockEnd.Y)
then FindText := TempEditor.Selection
else FindText := TSynEdit(TempEditor.EditorControl).GetWordAtRowCol(TempEditor.CursorTextXY);
then NewFindText := TempEditor.Selection
else NewFindText := TSynEdit(TempEditor.EditorControl).GetWordAtRowCol(TempEditor.CursorTextXY);
end else begin
if InputHistories.FindHistory.Count>0 then
FindText:=InputHistories.FindHistory[0];
NewFindText:=InputHistories.FindHistory[0];
end;
end;
FindInFiles(AProject, FindText);
FindText:=NewFindText;
end;
procedure TLazFindInFilesDialog.InitFromLazSearch(Sender: TObject);
@ -408,9 +432,8 @@ begin
end;
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject; const AFindText: string);
var
SearchForm: TSearchProgressForm;
begin
LazProject:=AProject;
LoadHistory;
// if there is no FindText, use the most recently used FindText
@ -421,8 +444,23 @@ begin
// disable replace. Find in files is often called,
// but almost never to replace with the same parameters
Options := Options-[fifReplace,fifReplaceAll];
Execute;
end;
function TLazFindInFilesDialog.GetResolvedDirectories: string;
begin
Result:=DirectoriesComboBox.Text;
IDEMacros.SubstituteMacros(Result);
Result:=TrimSearchPath(Result,GetBaseDirectory,true,true);
end;
function TLazFindInFilesDialog.Execute: boolean;
var
SearchForm: TSearchProgressForm;
begin
if ShowModal=mrOk then
begin
Result:=true;
SaveHistory;
SearchForm:= TSearchProgressForm.Create(SearchResultsView);
@ -438,7 +476,11 @@ begin
if FindText <> '' then
begin
case WhereRadioGroup.ItemIndex of
ItemIndProject : SearchForm.DoSearchProject(AProject);
ItemIndProject :
if LazProject=nil then
SearchForm.DoSearchProject(Project1)
else
SearchForm.DoSearchProject(LazProject);
ItemIndOpenFiles : SearchForm.DoSearchOpenFiles;
ItemIndDirectories: SearchForm.DoSearchDir;
ItemIndActiveFile : SearchForm.DoSearchActiveFile;
@ -447,14 +489,10 @@ begin
finally
FreeAndNil(SearchForm);
end;
end;
end;
end else
Result:=false;
function TLazFindInFilesDialog.GetResolvedDirectories: string;
begin
Result:=DirectoriesComboBox.Text;
IDEMacros.SubstituteMacros(Result);
Result:=TrimSearchPath(Result,GetBaseDirectory,true,true);
FProject:=nil;
end;
end.

View File

@ -355,7 +355,7 @@ type
// find
procedure StartFindAndReplace(Replace:boolean);
procedure AskReplace(Sender: TObject; const ASearch, AReplace:
string; Line, Column: integer; var Action: TSrcEditReplaceAction); override;
string; Line, Column: integer; out Action: TSrcEditReplaceAction); override;
procedure OnReplace(Sender: TObject; const ASearch, AReplace:
string; {%H-}Line, {%H-}Column: integer; var Action: TSynReplaceAction);
function DoFindAndReplace(aFindText, aReplaceText: String; anOptions: TSynSearchOptions): Integer;
@ -2963,7 +2963,7 @@ begin
end;
procedure TSourceEditor.AskReplace(Sender: TObject; const ASearch,
AReplace: string; Line, Column: integer; var Action: TSrcEditReplaceAction);
AReplace: string; Line, Column: integer; out Action: TSrcEditReplaceAction);
var
SynAction: TSynReplaceAction;
begin

View File

@ -4982,8 +4982,7 @@ var
begin
Result:=mrOk;
Dlg:=FindInFilesDialog;
Dlg.DirectoriesComboBox.Text:='';
Dlg.FindInFilesPerDialog(Project1);
Dlg.FindInSearchPath(APackage.SourceDirectories.CreateSearchPathFromAllFiles);
end;
function TPkgManager.AddDependencyToUnitOwners(const OwnedFilename,