mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 12:30:36 +02:00
IDE: package editor: implemented find in files
git-svn-id: trunk@48239 -
This commit is contained in:
parent
2290274ae7
commit
cff68418fe
@ -115,7 +115,7 @@ type
|
|||||||
procedure ReplaceText(const StartPos, EndPos: TPoint; const NewText: string);
|
procedure ReplaceText(const StartPos, EndPos: TPoint; const NewText: string);
|
||||||
procedure AskReplace(Sender: TObject; const ASearch, AReplace: string;
|
procedure AskReplace(Sender: TObject; const ASearch, AReplace: string;
|
||||||
Line, Column: integer;
|
Line, Column: integer;
|
||||||
var Action: TSrcEditReplaceAction); virtual; abstract;
|
out Action: TSrcEditReplaceAction); virtual; abstract;
|
||||||
procedure CopyToClipboard; virtual; abstract;
|
procedure CopyToClipboard; virtual; abstract;
|
||||||
procedure CutToClipboard; virtual; abstract;
|
procedure CutToClipboard; virtual; abstract;
|
||||||
|
|
||||||
|
@ -57,13 +57,13 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ShowCodeMacroSelectDialog(var Parameter: string): TIDECodeMacro;
|
function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
function ShowCodeMacroSelectDialog(var Parameter: string): TIDECodeMacro;
|
function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
|
||||||
var
|
var
|
||||||
CodeMacroSelectDlg: TCodeMacroSelectDlg;
|
CodeMacroSelectDlg: TCodeMacroSelectDlg;
|
||||||
begin
|
begin
|
||||||
|
@ -53,6 +53,7 @@ type
|
|||||||
procedure ReplaceCheckBoxChange(Sender: TObject);
|
procedure ReplaceCheckBoxChange(Sender: TObject);
|
||||||
procedure WhereRadioGroupClick(Sender: TObject);
|
procedure WhereRadioGroupClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
|
FProject: TProject;
|
||||||
function GetFindText: string;
|
function GetFindText: string;
|
||||||
function GetOptions: TLazFindInFileSearchOptions;
|
function GetOptions: TLazFindInFileSearchOptions;
|
||||||
function GetReplaceText: string;
|
function GetReplaceText: string;
|
||||||
@ -72,10 +73,14 @@ type
|
|||||||
function GetBaseDirectory: string;
|
function GetBaseDirectory: string;
|
||||||
procedure LoadHistory;
|
procedure LoadHistory;
|
||||||
procedure SaveHistory;
|
procedure SaveHistory;
|
||||||
|
procedure FindInSearchPath(SearchPath: string);
|
||||||
procedure FindInFilesPerDialog(AProject: TProject);
|
procedure FindInFilesPerDialog(AProject: TProject);
|
||||||
|
procedure InitFindText;
|
||||||
procedure InitFromLazSearch(Sender: TObject);
|
procedure InitFromLazSearch(Sender: TObject);
|
||||||
procedure FindInFiles(AProject: TProject; const AFindText: string);
|
procedure FindInFiles(AProject: TProject; const AFindText: string);
|
||||||
function GetResolvedDirectories: string;
|
function GetResolvedDirectories: string;
|
||||||
|
function Execute: boolean;
|
||||||
|
property LazProject: TProject read FProject write FProject;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindInFilesDialog: TLazFindInFilesDialog;
|
function FindInFilesDialog: TLazFindInFilesDialog;
|
||||||
@ -373,11 +378,31 @@ begin
|
|||||||
InputHistories.Save;
|
InputHistories.Save;
|
||||||
end;
|
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);
|
procedure TLazFindInFilesDialog.FindInFilesPerDialog(AProject: TProject);
|
||||||
|
begin
|
||||||
|
InitFindText;
|
||||||
|
FindInFiles(AProject, FindText);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLazFindInFilesDialog.InitFindText;
|
||||||
var
|
var
|
||||||
TempEditor: TSourceEditorInterface;
|
TempEditor: TSourceEditorInterface;
|
||||||
Begin
|
NewFindText: String;
|
||||||
FindText:='';
|
begin
|
||||||
|
NewFindText:='';
|
||||||
TempEditor := SourceEditorManagerIntf.ActiveEditor;
|
TempEditor := SourceEditorManagerIntf.ActiveEditor;
|
||||||
if TempEditor <> nil
|
if TempEditor <> nil
|
||||||
then //with TempEditor.EditorComponent do
|
then //with TempEditor.EditorComponent do
|
||||||
@ -385,15 +410,14 @@ Begin
|
|||||||
if EditorOpts.FindTextAtCursor
|
if EditorOpts.FindTextAtCursor
|
||||||
then begin
|
then begin
|
||||||
if TempEditor.SelectionAvailable and (TempEditor.BlockBegin.Y = TempEditor.BlockEnd.Y)
|
if TempEditor.SelectionAvailable and (TempEditor.BlockBegin.Y = TempEditor.BlockEnd.Y)
|
||||||
then FindText := TempEditor.Selection
|
then NewFindText := TempEditor.Selection
|
||||||
else FindText := TSynEdit(TempEditor.EditorControl).GetWordAtRowCol(TempEditor.CursorTextXY);
|
else NewFindText := TSynEdit(TempEditor.EditorControl).GetWordAtRowCol(TempEditor.CursorTextXY);
|
||||||
end else begin
|
end else begin
|
||||||
if InputHistories.FindHistory.Count>0 then
|
if InputHistories.FindHistory.Count>0 then
|
||||||
FindText:=InputHistories.FindHistory[0];
|
NewFindText:=InputHistories.FindHistory[0];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
FindText:=NewFindText;
|
||||||
FindInFiles(AProject, FindText);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesDialog.InitFromLazSearch(Sender: TObject);
|
procedure TLazFindInFilesDialog.InitFromLazSearch(Sender: TObject);
|
||||||
@ -408,9 +432,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject; const AFindText: string);
|
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject; const AFindText: string);
|
||||||
var
|
|
||||||
SearchForm: TSearchProgressForm;
|
|
||||||
begin
|
begin
|
||||||
|
LazProject:=AProject;
|
||||||
LoadHistory;
|
LoadHistory;
|
||||||
|
|
||||||
// if there is no FindText, use the most recently used FindText
|
// if there is no FindText, use the most recently used FindText
|
||||||
@ -421,8 +444,23 @@ begin
|
|||||||
// disable replace. Find in files is often called,
|
// disable replace. Find in files is often called,
|
||||||
// but almost never to replace with the same parameters
|
// but almost never to replace with the same parameters
|
||||||
Options := Options-[fifReplace,fifReplaceAll];
|
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
|
if ShowModal=mrOk then
|
||||||
begin
|
begin
|
||||||
|
Result:=true;
|
||||||
SaveHistory;
|
SaveHistory;
|
||||||
|
|
||||||
SearchForm:= TSearchProgressForm.Create(SearchResultsView);
|
SearchForm:= TSearchProgressForm.Create(SearchResultsView);
|
||||||
@ -438,7 +476,11 @@ begin
|
|||||||
if FindText <> '' then
|
if FindText <> '' then
|
||||||
begin
|
begin
|
||||||
case WhereRadioGroup.ItemIndex of
|
case WhereRadioGroup.ItemIndex of
|
||||||
ItemIndProject : SearchForm.DoSearchProject(AProject);
|
ItemIndProject :
|
||||||
|
if LazProject=nil then
|
||||||
|
SearchForm.DoSearchProject(Project1)
|
||||||
|
else
|
||||||
|
SearchForm.DoSearchProject(LazProject);
|
||||||
ItemIndOpenFiles : SearchForm.DoSearchOpenFiles;
|
ItemIndOpenFiles : SearchForm.DoSearchOpenFiles;
|
||||||
ItemIndDirectories: SearchForm.DoSearchDir;
|
ItemIndDirectories: SearchForm.DoSearchDir;
|
||||||
ItemIndActiveFile : SearchForm.DoSearchActiveFile;
|
ItemIndActiveFile : SearchForm.DoSearchActiveFile;
|
||||||
@ -447,14 +489,10 @@ begin
|
|||||||
finally
|
finally
|
||||||
FreeAndNil(SearchForm);
|
FreeAndNil(SearchForm);
|
||||||
end;
|
end;
|
||||||
end;
|
end else
|
||||||
end;
|
Result:=false;
|
||||||
|
|
||||||
function TLazFindInFilesDialog.GetResolvedDirectories: string;
|
FProject:=nil;
|
||||||
begin
|
|
||||||
Result:=DirectoriesComboBox.Text;
|
|
||||||
IDEMacros.SubstituteMacros(Result);
|
|
||||||
Result:=TrimSearchPath(Result,GetBaseDirectory,true,true);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -355,7 +355,7 @@ type
|
|||||||
// find
|
// find
|
||||||
procedure StartFindAndReplace(Replace:boolean);
|
procedure StartFindAndReplace(Replace:boolean);
|
||||||
procedure AskReplace(Sender: TObject; const ASearch, AReplace:
|
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:
|
procedure OnReplace(Sender: TObject; const ASearch, AReplace:
|
||||||
string; {%H-}Line, {%H-}Column: integer; var Action: TSynReplaceAction);
|
string; {%H-}Line, {%H-}Column: integer; var Action: TSynReplaceAction);
|
||||||
function DoFindAndReplace(aFindText, aReplaceText: String; anOptions: TSynSearchOptions): Integer;
|
function DoFindAndReplace(aFindText, aReplaceText: String; anOptions: TSynSearchOptions): Integer;
|
||||||
@ -2963,7 +2963,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSourceEditor.AskReplace(Sender: TObject; const ASearch,
|
procedure TSourceEditor.AskReplace(Sender: TObject; const ASearch,
|
||||||
AReplace: string; Line, Column: integer; var Action: TSrcEditReplaceAction);
|
AReplace: string; Line, Column: integer; out Action: TSrcEditReplaceAction);
|
||||||
var
|
var
|
||||||
SynAction: TSynReplaceAction;
|
SynAction: TSynReplaceAction;
|
||||||
begin
|
begin
|
||||||
|
@ -4982,8 +4982,7 @@ var
|
|||||||
begin
|
begin
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
Dlg:=FindInFilesDialog;
|
Dlg:=FindInFilesDialog;
|
||||||
Dlg.DirectoriesComboBox.Text:='';
|
Dlg.FindInSearchPath(APackage.SourceDirectories.CreateSearchPathFromAllFiles);
|
||||||
Dlg.FindInFilesPerDialog(Project1);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPkgManager.AddDependencyToUnitOwners(const OwnedFilename,
|
function TPkgManager.AddDependencyToUnitOwners(const OwnedFilename,
|
||||||
|
Loading…
Reference in New Issue
Block a user