mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 20:38:16 +02:00
IDE, FindInFiles: Refactored, moved away from SourceNotebook
git-svn-id: trunk@24089 -
This commit is contained in:
parent
2307785cf3
commit
2b5156b908
@ -25,7 +25,8 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, LCLIntf, Controls, StdCtrls, Forms, Buttons,
|
||||
ExtCtrls, FileUtil, LazarusIDEStrConsts, Dialogs, SynEditTypes,
|
||||
IDEDialogs, IDEWindowIntf, InputHistory, IDEContextHelpEdit, ButtonPanel;
|
||||
IDEDialogs, IDEWindowIntf, InputHistory, IDEContextHelpEdit, ButtonPanel,
|
||||
SrcEditorIntf, EditorOptions, SearchFrm, Project, SynEdit, SearchResultView;
|
||||
|
||||
type
|
||||
{ TLazFindInFilesDialog }
|
||||
@ -70,14 +71,28 @@ type
|
||||
property ReplaceText: string read GetReplaceText write SetReplaceText;
|
||||
property SynSearchOptions: TSynSearchOptions read GetSynOptions
|
||||
write SetSynOptions;
|
||||
procedure LoadHistory;
|
||||
procedure SaveHistory;
|
||||
procedure FindInFilesPerDialog(AProject: TProject);
|
||||
procedure InitFromLazSearch(Sender: TObject);
|
||||
procedure FindInFiles(AProject: TProject; const AFindText: string);
|
||||
end;
|
||||
|
||||
|
||||
var
|
||||
FindInFilesDialog: TLazFindInFilesDialog = nil;
|
||||
function FindInFilesDialog: TLazFindInFilesDialog;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
FindInFilesDialogSingleton: TLazFindInFilesDialog = nil;
|
||||
|
||||
function FindInFilesDialog: TLazFindInFilesDialog;
|
||||
begin
|
||||
Result := FindInFilesDialogSingleton;
|
||||
if FindInFilesDialogSingleton <> nil then exit;
|
||||
FindInFilesDialogSingleton := TLazFindInFilesDialog.Create(Application);
|
||||
Result := FindInFilesDialogSingleton;
|
||||
end;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TLazFindInFilesDialog }
|
||||
@ -249,5 +264,141 @@ begin
|
||||
ButtonPanel1.OKButton.Caption := lisBtnFind;
|
||||
end;
|
||||
|
||||
procedure TLazFindInFilesDialog.LoadHistory;
|
||||
|
||||
procedure AssignToComboBox(AComboBox: TComboBox; Strings: TStrings);
|
||||
begin
|
||||
AComboBox.Items.Assign(Strings);
|
||||
if AComboBox.Items.Count>0 then
|
||||
AComboBox.ItemIndex := 0;
|
||||
end;
|
||||
|
||||
procedure AddFileToComboBox(AComboBox: TComboBox; const Filename: string);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if Filename='' then exit;
|
||||
for i:=0 to AComboBox.Items.Count-1 do begin
|
||||
if CompareFilenames(Filename,AComboBox.Items[i])=0 then begin
|
||||
// move to front (but not top, top should be the last used directory)
|
||||
if i>2 then
|
||||
AComboBox.Items.Move(i,1);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
// insert in front (but not top, top should be the last used directory)
|
||||
if AComboBox.Items.Count>0 then
|
||||
i:=1
|
||||
else
|
||||
i:=0;
|
||||
AComboBox.Items.Insert(i,Filename);
|
||||
end;
|
||||
|
||||
var
|
||||
SrcEdit: TSourceEditorInterface;
|
||||
begin
|
||||
SrcEdit := SourceEditorManagerIntf.ActiveEditor;
|
||||
//DebugLn('TSourceNotebook.LoadFindInFilesHistory ',dbgsName(TextToFindComboBox),' ',dbgsName(FindHistory));
|
||||
TextToFindComboBox.Items.Assign(InputHistories.FindHistory);
|
||||
ReplaceTextComboBox.Items.Assign(InputHistories.ReplaceHistory);
|
||||
if not EditorOpts.FindTextAtCursor then begin
|
||||
if TextToFindComboBox.Items.Count>0 then begin
|
||||
//debugln('TSourceNotebook.LoadFindInFilesHistory A TextToFindComboBox.Text=',TextToFindComboBox.Text);
|
||||
TextToFindComboBox.ItemIndex:=0;
|
||||
TextToFindComboBox.SelectAll;
|
||||
//debugln('TSourceNotebook.LoadFindInFilesHistory B TextToFindComboBox.Text=',TextToFindComboBox.Text);
|
||||
end;
|
||||
end;
|
||||
// show last used directories and directory of current file
|
||||
AssignToComboBox(DirectoryComboBox, InputHistories.FindInFilesPathHistory);
|
||||
if (SrcEdit<>nil) and (FilenameIsAbsolute(SrcEdit.FileName)) then
|
||||
AddFileToComboBox(DirectoryComboBox, ExtractFilePath(SrcEdit.FileName));
|
||||
// show last used file masks
|
||||
AssignToComboBox(FileMaskComboBox, InputHistories.FindInFilesMaskHistory);
|
||||
Options := InputHistories.FindInFilesSearchOptions;
|
||||
end;
|
||||
|
||||
procedure TLazFindInFilesDialog.SaveHistory;
|
||||
begin
|
||||
InputHistories.AddToFindHistory(FindText);
|
||||
InputHistories.AddToFindInFilesPathHistory(DirectoryComboBox.Text);
|
||||
InputHistories.AddToFindInFilesMaskHistory(FileMaskComboBox.Text);
|
||||
InputHistories.FindInFilesSearchOptions:=Options;
|
||||
InputHistories.Save;
|
||||
end;
|
||||
|
||||
procedure TLazFindInFilesDialog.FindInFilesPerDialog(AProject: TProject);
|
||||
var
|
||||
TempEditor: TSourceEditorInterface;
|
||||
Begin
|
||||
FindText:='';
|
||||
TempEditor := SourceEditorManagerIntf.ActiveEditor;
|
||||
if TempEditor <> nil
|
||||
then //with TempEditor.EditorComponent do
|
||||
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);
|
||||
end else begin
|
||||
if InputHistories.FindHistory.Count>0 then
|
||||
FindText:=InputHistories.FindHistory[0];
|
||||
end;
|
||||
end;
|
||||
|
||||
FindInFiles(AProject, FindText);
|
||||
end;
|
||||
|
||||
procedure TLazFindInFilesDialog.InitFromLazSearch(Sender: TObject);
|
||||
begin
|
||||
DirectoryComboBox.Text:= TLazSearch(Sender).SearchDirectory;
|
||||
Options:= TLazSearch(Sender).SearchOptions;
|
||||
FileMaskComboBox.Text:= TLazSearch(Sender).SearchMask;
|
||||
end;
|
||||
|
||||
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject;
|
||||
const AFindText: string);
|
||||
var
|
||||
SearchForm: TSearchForm;
|
||||
begin
|
||||
LoadHistory;
|
||||
|
||||
// if there is no FindText, use the most recently used FindText
|
||||
FindText:= AFindText;
|
||||
if (FindText = '') and (InputHistories.FindHistory.Count > 0) then
|
||||
FindText := InputHistories.FindHistory[0];
|
||||
|
||||
// disable replace. Find in files is often called,
|
||||
// but almost never to replace with the same parameters
|
||||
Options := Options-[fifReplace,fifReplaceAll];
|
||||
if ShowModal=mrOk then
|
||||
begin
|
||||
SaveHistory;
|
||||
|
||||
SearchForm:= TSearchForm.Create(SearchResultsView);
|
||||
with SearchForm do begin
|
||||
SearchOptions := self.Options;
|
||||
SearchText := self.FindText;
|
||||
ReplaceText := self.ReplaceText;
|
||||
SearchMask := self.FileMaskComboBox.Text;
|
||||
SearchDirectory := self.DirectoryComboBox.Text;
|
||||
end;
|
||||
|
||||
try
|
||||
if FindText <> '' then
|
||||
begin
|
||||
case WhereRadioGroup.ItemIndex of
|
||||
0: SearchForm.DoSearchProject(AProject);
|
||||
1: SearchForm.DoSearchOpenFiles;
|
||||
2: SearchForm.DoSearchDir;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FreeAndNil(SearchForm);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
28
ide/main.pp
28
ide/main.pp
@ -412,7 +412,6 @@ type
|
||||
procedure OnSrcNotebookToggleFormUnit(Sender: TObject);
|
||||
procedure OnSrcNotebookToggleObjectInsp(Sender: TObject);
|
||||
procedure OnSrcNotebookViewJumpHistory(Sender: TObject);
|
||||
procedure OnSrcNotebookShowSearchResultsView(Sender: TObject);
|
||||
procedure OnSrcNoteBookPopupMenu(const AddMenuItemProc: TAddMenuItemProc);
|
||||
|
||||
// ObjectInspector + PropertyEditorHook events
|
||||
@ -729,7 +728,6 @@ type
|
||||
procedure StartIDE; override;
|
||||
destructor Destroy; override;
|
||||
procedure CreateOftenUsedForms; override;
|
||||
procedure CreateSearchResultWindow;
|
||||
procedure UpdateDefaultPascalFileExtensions;
|
||||
function DoResetToolStatus(AFlags: TResetToolFlags): boolean; override;
|
||||
|
||||
@ -1411,15 +1409,6 @@ begin
|
||||
LazFindReplaceDialog:=TLazFindReplaceDialog.Create(nil);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.CreateSearchResultWindow;
|
||||
begin
|
||||
if SearchResultsView<>nil then exit;
|
||||
Application.CreateForm(TSearchResultsView, SearchResultsView);
|
||||
with SearchResultsView do begin
|
||||
OnSelectionChanged:= @SearchResultsViewSelectionChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OIOnSelectPersistents(Sender: TObject);
|
||||
begin
|
||||
TheControlSelection.AssignSelection(ObjectInspector1.Selection);
|
||||
@ -1922,9 +1911,11 @@ begin
|
||||
SourceEditorManager.OnToggleFormUnitClicked := @OnSrcNotebookToggleFormUnit;
|
||||
SourceEditorManager.OnToggleObjectInspClicked:= @OnSrcNotebookToggleObjectInsp;
|
||||
SourceEditorManager.OnViewJumpHistory := @OnSrcNotebookViewJumpHistory;
|
||||
SourceEditorManager.OnShowSearchResultsView := @OnSrcNotebookShowSearchResultsView;
|
||||
SourceEditorManager.OnPopupMenu := @OnSrcNoteBookPopupMenu;
|
||||
DebugBoss.ConnectSourceNotebookEvents;
|
||||
DebugBoss.ConnectSourceNotebookEvents;
|
||||
|
||||
OnSearchResultsViewSelectionChanged := @SearchResultsViewSelectionChanged;
|
||||
OnSearchAgainClicked := @FindInFilesDialog.InitFromLazSearch;
|
||||
|
||||
// connect search menu to sourcenotebook
|
||||
MainIDEBar.itmSearchFind.OnClick := @SourceNotebook.FindClicked;
|
||||
@ -3508,7 +3499,6 @@ end;
|
||||
|
||||
Procedure TMainIDE.mnuViewSearchResultsClick(Sender: TObject);
|
||||
Begin
|
||||
CreateSearchResultWindow;
|
||||
SearchResultsView.ShowOnTop;
|
||||
End;
|
||||
|
||||
@ -12156,7 +12146,6 @@ var
|
||||
SrcEdit: TSourceEditor;
|
||||
begin
|
||||
Result:=false;
|
||||
CreateSearchResultWindow;
|
||||
if pos('(',SearchResultsView.GetSelectedText) > 0 then
|
||||
begin
|
||||
AFileName:= SearchResultsView.GetSourceFileName;
|
||||
@ -12243,7 +12232,6 @@ var
|
||||
WasVisible: boolean;
|
||||
ALayout: TIDEWindowLayout;
|
||||
begin
|
||||
CreateSearchResultWindow;
|
||||
WasVisible := SearchResultsView.Visible;
|
||||
SearchResultsView.Visible:=true;
|
||||
ALayout:=EnvironmentOptions.IDEWindowLayoutList.
|
||||
@ -13819,7 +13807,6 @@ begin
|
||||
|
||||
// show result
|
||||
if (not Options.Rename) or (not Rename) then begin
|
||||
CreateSearchResultWindow;
|
||||
Result:=ShowIdentifierReferences(DeclarationUnitInfo.Source,
|
||||
DeclarationCaretXY,PascalReferences);
|
||||
if Result<>mrOk then exit;
|
||||
@ -14217,7 +14204,7 @@ function TMainIDE.DoFindInFiles: TModalResult;
|
||||
begin
|
||||
Result:=mrOk;
|
||||
DoArrangeSourceEditorAndMessageView(true);
|
||||
SourceNotebook.FindInFilesPerDialog(Project1);
|
||||
FindInFilesDialog.FindInFilesPerDialog(Project1);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.DoCompleteCodeAtCursor;
|
||||
@ -15019,11 +15006,6 @@ begin
|
||||
JumpHistoryViewWin.ShowOnTop;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OnSrcNotebookShowSearchResultsView(Sender: TObject);
|
||||
begin
|
||||
CreateSearchResultWindow;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OnSrcNoteBookPopupMenu(
|
||||
const AddMenuItemProc: TAddMenuItemProc);
|
||||
begin
|
||||
|
@ -68,7 +68,7 @@ uses
|
||||
TransferMacros, ObjectInspector, PropEdits, IDEDefs, MsgView,
|
||||
EnvironmentOpts, EditorOptions, CompilerOptions, KeyMapping, IDEProcs,
|
||||
Debugger, IDEOptionDefs, CodeToolsDefines, Splash, Designer,
|
||||
SourceEditor, BuildManager,
|
||||
SourceEditor, BuildManager, FindInFilesDlg,
|
||||
MainBar, MainIntf;
|
||||
|
||||
type
|
||||
@ -1150,12 +1150,12 @@ end;
|
||||
|
||||
procedure TMainIDEBase.FindInFilesPerDialog(AProject: TProject);
|
||||
begin
|
||||
SourceNotebook.FindInFilesPerDialog(AProject);
|
||||
FindInFilesDialog.FindInFilesPerDialog(AProject);
|
||||
end;
|
||||
|
||||
procedure TMainIDEBase.FindInFiles(AProject: TProject; const FindText: string);
|
||||
begin
|
||||
SourceNotebook.FindInFiles(AProject, FindText);
|
||||
FindInFilesDialog.FindInFiles(AProject, FindText);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -37,9 +37,9 @@ uses
|
||||
// synedit, codetools
|
||||
SynEditSearch, SynRegExpr, SourceLog, KeywordFuncLists, BasicCodeTools,
|
||||
// IDEIntf
|
||||
LazIDEIntf, SrcEditorIntf,
|
||||
LazIDEIntf, SrcEditorIntf, MainIntf,
|
||||
// ide
|
||||
LazarusIDEStrConsts, InputHistory, FindInFilesDlg, SearchResultView;
|
||||
LazarusIDEStrConsts, InputHistory, SearchResultView, Project;
|
||||
|
||||
type
|
||||
|
||||
@ -89,6 +89,11 @@ type
|
||||
function GetOptions: TLazFindInFileSearchOptions;
|
||||
procedure SearchFile(const aFilename: string);
|
||||
procedure SetFlag(Flag: TSrcEditSearchOption; AValue: boolean);
|
||||
procedure DoSearchAndAddToSearchResults;
|
||||
public
|
||||
procedure DoSearchOpenFiles;
|
||||
procedure DoSearchDir;
|
||||
procedure DoSearchProject(AProject: TProject);
|
||||
public
|
||||
procedure DoSearch;
|
||||
property SearchDirectory: string read fTheDirectory write fTheDirectory;
|
||||
@ -878,6 +883,89 @@ begin
|
||||
Exclude(fFlags,Flag);
|
||||
end;
|
||||
|
||||
procedure TSearchForm.DoSearchAndAddToSearchResults;
|
||||
var
|
||||
ListIndex: integer;
|
||||
begin
|
||||
ListIndex:=SearchResultsView.AddSearch(SearchText,
|
||||
SearchText,
|
||||
ReplaceText,
|
||||
SearchDirectory,
|
||||
SearchMask,
|
||||
SearchOptions);
|
||||
|
||||
try
|
||||
SearchResultsView.BeginUpdate(ListIndex);
|
||||
ResultsList := SearchResultsView.Items[ListIndex];
|
||||
SearchResultsView.Items[ListIndex].Clear;
|
||||
ResultsWindow:= ListIndex;
|
||||
try
|
||||
Show;
|
||||
// update Window Menu, the OnIdle event does not occur while searching
|
||||
MainIDEInterface.UpdateWindowMenu;
|
||||
DoSearch;
|
||||
except
|
||||
on E: ERegExpr do
|
||||
MessageDlg(lisUEErrorInRegularExpression, E.Message,mtError,
|
||||
[mbCancel],0);
|
||||
end;
|
||||
finally
|
||||
SearchResultsView.EndUpdate(ListIndex);
|
||||
SearchResultsView.ShowOnTop;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSearchForm.DoSearchOpenFiles;
|
||||
var
|
||||
i: integer;
|
||||
TheFileList: TStringList;
|
||||
begin
|
||||
try
|
||||
TheFileList:= TStringList.Create;
|
||||
for i:= 0 to SourceEditorManagerIntf.SourceEditorCount -1 do
|
||||
begin
|
||||
//only if file exists on disk
|
||||
if FilenameIsAbsolute(SourceEditorManagerIntf.SourceEditors[i].FileName) and
|
||||
FileExistsUTF8(SourceEditorManagerIntf.SourceEditors[i].FileName) then
|
||||
begin
|
||||
TheFileList.Add(SourceEditorManagerIntf.SourceEditors[i].FileName);
|
||||
end;
|
||||
end;
|
||||
SearchFileList:= TheFileList;
|
||||
DoSearchAndAddToSearchResults;
|
||||
finally
|
||||
FreeAndNil(TheFileList);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSearchForm.DoSearchDir;
|
||||
begin
|
||||
SearchFileList:= Nil;
|
||||
DoSearchAndAddToSearchResults;
|
||||
end;
|
||||
|
||||
procedure TSearchForm.DoSearchProject(AProject: TProject);
|
||||
var
|
||||
AnUnitInfo: TUnitInfo;
|
||||
TheFileList: TStringList;
|
||||
begin
|
||||
try
|
||||
TheFileList:= TStringList.Create;
|
||||
AnUnitInfo:=AProject.FirstPartOfProject;
|
||||
while AnUnitInfo<>nil do begin
|
||||
//Only if file exists on disk.
|
||||
if FilenameIsAbsolute(AnUnitInfo.FileName)
|
||||
and FileExistsUTF8(AnUnitInfo.FileName) then
|
||||
TheFileList.Add(AnUnitInfo.FileName);
|
||||
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
|
||||
end;
|
||||
SearchFileList:= TheFileList;
|
||||
DoSearchAndAddToSearchResults;
|
||||
finally
|
||||
FreeAndNil(TheFileList);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSearchForm.PadAndShorten(FileName: string): string;
|
||||
var
|
||||
FoundAt: integer;
|
||||
|
@ -39,8 +39,8 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs,
|
||||
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus,
|
||||
IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, EditorOptions, InputHistory,
|
||||
IDEProcs, FindInFilesDlg, Project, MainIntf, Clipbrd;
|
||||
IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, InputHistory,
|
||||
IDEProcs, Project, MainIntf, Clipbrd;
|
||||
|
||||
type
|
||||
{ TLazSearchMatchPos }
|
||||
@ -206,8 +206,11 @@ type
|
||||
property MaxItems: integer read FMaxItems write SetMaxItems;
|
||||
end;
|
||||
|
||||
function SearchResultsView: TSearchResultsView;
|
||||
|
||||
var
|
||||
SearchResultsView: TSearchResultsView;
|
||||
OnSearchResultsViewSelectionChanged: TNotifyEvent = nil;
|
||||
OnSearchAgainClicked: TNotifyEvent = nil;
|
||||
|
||||
implementation
|
||||
|
||||
@ -217,7 +220,9 @@ implementation
|
||||
|
||||
const
|
||||
MaxTextLen = 80;
|
||||
|
||||
var
|
||||
SearchResultsViewSingleton: TSearchResultsView = nil;
|
||||
|
||||
function CopySearchMatchPos(var Src, Dest: TLazSearchMatchPos): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
@ -248,6 +253,15 @@ begin
|
||||
sl.Free;
|
||||
end;
|
||||
|
||||
function SearchResultsView: TSearchResultsView;
|
||||
begin
|
||||
Result := SearchResultsViewSingleton;
|
||||
if SearchResultsViewSingleton <> nil then exit;
|
||||
Application.CreateForm(TSearchResultsView, SearchResultsViewSingleton);
|
||||
SearchResultsViewSingleton.OnSelectionChanged := OnSearchResultsViewSelectionChanged;
|
||||
Result := SearchResultsViewSingleton;
|
||||
end;
|
||||
|
||||
procedure TSearchResultsView.Form1Create(Sender: TObject);
|
||||
var
|
||||
ALayout: TIDEWindowLayout;
|
||||
@ -727,16 +741,8 @@ begin
|
||||
end
|
||||
else begin
|
||||
SearchObj:= CurrentTV.SearchObject;
|
||||
if Assigned(FindInFilesDialog) then
|
||||
begin
|
||||
with FindInFilesDialog do
|
||||
begin
|
||||
DirectoryComboBox.Text:= SearchObj.SearchDirectory;
|
||||
Options:= SearchObj.SearchOptions;
|
||||
FileMaskComboBox.Text:= SearchObj.SearchMask;
|
||||
end;//with
|
||||
MainIDEInterface.FindInFiles(Project1, SearchObj.SearchString);
|
||||
end;//if
|
||||
OnSearchAgainClicked(SearchObj);
|
||||
MainIDEInterface.FindInFiles(Project1, SearchObj.SearchString);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -41,25 +41,22 @@ uses
|
||||
MemCheck,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, LCLIntf,
|
||||
FileUtil, Forms, Buttons, ComCtrls, Dialogs, StdCtrls, GraphType, Graphics,
|
||||
Translations, ClipBrd, TypInfo, types, Extctrls, Menus, HelpIntfs,
|
||||
LazHelpIntf, LConvEncoding, LDockCtrl,
|
||||
FileUtil, Forms, ComCtrls, Dialogs, StdCtrls, Graphics,
|
||||
Translations, ClipBrd, types, Extctrls, Menus, HelpIntfs, LConvEncoding, LDockCtrl,
|
||||
// codetools
|
||||
BasicCodeTools, CodeBeautifier, CodeToolManager, CodeCache, SourceLog,
|
||||
// synedit
|
||||
SynEditLines, SynEditStrConst, SynEditTypes, SynEdit, SynRegExpr,
|
||||
SynEditHighlighter, SynEditAutoComplete, SynEditKeyCmds, SynCompletion,
|
||||
SynEditMiscClasses, SynEditMarkupHighAll, SynGutterLineNumber, SynEditMarks,
|
||||
SynEditMiscClasses, SynEditMarkupHighAll, SynEditMarks,
|
||||
SynBeautifier, SynEditTextBase, SynPluginTemplateEdit, SynPluginSyncroEdit,
|
||||
SynPluginSyncronizedEditBase,
|
||||
// IDE interface
|
||||
MacroIntf, ProjectIntf, SrcEditorIntf, MenuIntf, LazIDEIntf, PackageIntf,
|
||||
IDEDialogs, IDEHelpIntf, IDEWindowIntf, IDEImagesIntf,
|
||||
SynPluginSyncronizedEditBase, ProjectIntf, SrcEditorIntf, MenuIntf, LazIDEIntf, PackageIntf,
|
||||
IDEDialogs, IDEHelpIntf, IDEImagesIntf,
|
||||
// IDE units
|
||||
LazarusIDEStrConsts, LazConf, IDECommands, EditorOptions, KeyMapping, Project,
|
||||
WordCompletion, FindReplaceDialog, FindInFilesDlg, IDEProcs, IDEOptionDefs,
|
||||
LazarusIDEStrConsts, IDECommands, EditorOptions, Project,
|
||||
WordCompletion, FindReplaceDialog, IDEProcs, IDEOptionDefs,
|
||||
MacroPromptDlg, TransferMacros, CodeContextForm, SrcEditHintFrm,
|
||||
EnvironmentOpts, MsgView, SearchResultView, InputHistory, CodeMacroPrompt,
|
||||
EnvironmentOpts, MsgView, InputHistory, CodeMacroPrompt,
|
||||
CodeTemplatesDlg, TodoDlg, TodoList, CodeToolsOptions,
|
||||
SortSelectionDlg, EncloseSelectionDlg, DiffDialog, ConDef, InvertAssignTool,
|
||||
SourceEditProcs, SourceMarks, CharacterMapDlg, SearchFrm,
|
||||
@ -753,20 +750,6 @@ type
|
||||
property IncrementalSearchStr: string
|
||||
read FIncrementalSearchStr write SetIncrementalSearchStr;
|
||||
|
||||
// FindInFiles
|
||||
procedure FindInFilesPerDialog(AProject: TProject);
|
||||
procedure FindInFiles(AProject: TProject; const FindText: string);
|
||||
procedure ShowSearchResultsView;
|
||||
function CreateFindInFilesDialog: TLazFindInFilesDialog;
|
||||
procedure LoadFindInFilesHistory(ADialog: TLazFindInFilesDialog);
|
||||
procedure SaveFindInFilesHistory(ADialog: TLazFindInFilesDialog);
|
||||
procedure FIFSearchProject(AProject: TProject;
|
||||
ADialog: TLazFindInFilesDialog);
|
||||
procedure FIFSearchOpenFiles(ADialog: TLazFindInFilesDialog);
|
||||
procedure FIFSearchDir(ADialog: TLazFindInFilesDialog);
|
||||
function FIFCreateSearchForm(ADialog:TLazFindInFilesDialog): TSearchForm;
|
||||
procedure DoFindInFiles(ASearchForm: TSearchForm);
|
||||
|
||||
// goto line number
|
||||
procedure GotoLineClicked(Sender: TObject);
|
||||
|
||||
@ -919,7 +902,6 @@ type
|
||||
fOnReadOnlyChanged: TNotifyEvent;
|
||||
FOnShowCodeContext: TOnShowCodeContext;
|
||||
FOnShowHintForSource: TOnShowHintForSource;
|
||||
FOnShowSearchResultsView: TNotifyEvent;
|
||||
FOnShowUnitInfo: TNotifyEvent;
|
||||
FOnToggleFormUnitClicked: TNotifyEvent;
|
||||
FOnToggleObjectInspClicked: TNotifyEvent;
|
||||
@ -975,8 +957,6 @@ type
|
||||
read FOnToggleObjectInspClicked write FOnToggleObjectInspClicked;
|
||||
property OnViewJumpHistory: TNotifyEvent
|
||||
read FOnViewJumpHistory write FOnViewJumpHistory;
|
||||
property OnShowSearchResultsView: TNotifyEvent
|
||||
read FOnShowSearchResultsView write FOnShowSearchResultsView;
|
||||
property OnPopupMenu: TSrcEditPopupMenuEvent read FOnPopupMenu write FOnPopupMenu;
|
||||
end;
|
||||
|
||||
@ -5804,262 +5784,6 @@ Begin
|
||||
if TempEditor <> nil then TempEditor.FindPrevious;
|
||||
End;
|
||||
|
||||
function TSourceNotebook.CreateFindInFilesDialog: TLazFindInFilesDialog;
|
||||
begin
|
||||
Result := TLazFindInFilesDialog.Create(Application);
|
||||
LoadFindInFilesHistory(Result);
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.LoadFindInFilesHistory(ADialog: TLazFindInFilesDialog);
|
||||
|
||||
procedure AssignToComboBox(AComboBox: TComboBox; Strings: TStrings);
|
||||
begin
|
||||
AComboBox.Items.Assign(Strings);
|
||||
if AComboBox.Items.Count>0 then
|
||||
AComboBox.ItemIndex := 0;
|
||||
end;
|
||||
|
||||
procedure AddFileToComboBox(AComboBox: TComboBox; const Filename: string);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if Filename='' then exit;
|
||||
for i:=0 to AComboBox.Items.Count-1 do begin
|
||||
if CompareFilenames(Filename,AComboBox.Items[i])=0 then begin
|
||||
// move to front (but not top, top should be the last used directory)
|
||||
if i>2 then
|
||||
AComboBox.Items.Move(i,1);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
// insert in front (but not top, top should be the last used directory)
|
||||
if AComboBox.Items.Count>0 then
|
||||
i:=1
|
||||
else
|
||||
i:=0;
|
||||
AComboBox.Items.Insert(i,Filename);
|
||||
end;
|
||||
|
||||
var
|
||||
SrcEdit: TSourceEditor;
|
||||
begin
|
||||
if not Assigned(ADialog) then exit;
|
||||
SrcEdit:=GetActiveSE;
|
||||
with ADialog, InputHistories do
|
||||
begin
|
||||
//DebugLn('TSourceNotebook.LoadFindInFilesHistory ',dbgsName(TextToFindComboBox),' ',dbgsName(FindHistory));
|
||||
TextToFindComboBox.Items.Assign(FindHistory);
|
||||
ReplaceTextComboBox.Items.Assign(ReplaceHistory);
|
||||
if not EditorOpts.FindTextAtCursor then begin
|
||||
if TextToFindComboBox.Items.Count>0 then begin
|
||||
//debugln('TSourceNotebook.LoadFindInFilesHistory A TextToFindComboBox.Text=',TextToFindComboBox.Text);
|
||||
TextToFindComboBox.ItemIndex:=0;
|
||||
TextToFindComboBox.SelectAll;
|
||||
//debugln('TSourceNotebook.LoadFindInFilesHistory B TextToFindComboBox.Text=',TextToFindComboBox.Text);
|
||||
end;
|
||||
end;
|
||||
// show last used directories and directory of current file
|
||||
AssignToComboBox(DirectoryComboBox, FindInFilesPathHistory);
|
||||
if (SrcEdit<>nil) and (FilenameIsAbsolute(SrcEdit.FileName)) then
|
||||
AddFileToComboBox(DirectoryComboBox, ExtractFilePath(SrcEdit.FileName));
|
||||
// show last used file masks
|
||||
AssignToComboBox(FileMaskComboBox, FindInFilesMaskHistory);
|
||||
Options:=FindInFilesSearchOptions;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.SaveFindInFilesHistory(ADialog: TLazFindInFilesDialog);
|
||||
begin
|
||||
if Assigned(ADialog) then
|
||||
begin
|
||||
with ADialog do
|
||||
begin
|
||||
InputHistories.AddToFindHistory(FindText);
|
||||
InputHistories.AddToFindInFilesPathHistory(DirectoryComboBox.Text);
|
||||
InputHistories.AddToFindInFilesMaskHistory(FileMaskComboBox.Text);
|
||||
InputHistories.FindInFilesSearchOptions:=Options;
|
||||
end;
|
||||
InputHistories.Save;
|
||||
end;
|
||||
end;
|
||||
|
||||
{Search All the files in a project and add the results to the SearchResultsView
|
||||
Dialog}
|
||||
procedure TSourceNotebook.FIFSearchProject(AProject: TProject;
|
||||
ADialog: TLazFindInFilesDialog);
|
||||
var
|
||||
AnUnitInfo: TUnitInfo;
|
||||
TheFileList: TStringList;
|
||||
SearchForm: TSearchForm;
|
||||
begin
|
||||
try
|
||||
TheFileList:= TStringList.Create;
|
||||
AnUnitInfo:=AProject.FirstPartOfProject;
|
||||
while AnUnitInfo<>nil do begin
|
||||
//Only if file exists on disk.
|
||||
if FilenameIsAbsolute(AnUnitInfo.FileName)
|
||||
and FileExistsUTF8(AnUnitInfo.FileName) then
|
||||
TheFileList.Add(AnUnitInfo.FileName);
|
||||
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
|
||||
end;
|
||||
SearchForm:= FIFCreateSearchForm(ADialog);
|
||||
SearchForm.SearchFileList:= TheFileList;
|
||||
DoFindInFiles(SearchForm);
|
||||
finally
|
||||
FreeAndNil(TheFileList);
|
||||
FreeAndNil(SearchForm);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.FIFSearchDir(ADialog: TLazFindInFilesDialog);
|
||||
var
|
||||
SearchForm: TSearchForm;
|
||||
begin
|
||||
try
|
||||
SearchForm:= FIFCreateSearchForm(ADialog);
|
||||
SearchForm.SearchFileList:= Nil;
|
||||
DoFindInFiles(SearchForm);
|
||||
finally
|
||||
FreeAndNil(SearchForm);
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.DoFindInFiles(ASearchForm: TSearchForm);
|
||||
var
|
||||
ListIndex: integer;
|
||||
begin
|
||||
ShowSearchResultsView;
|
||||
ListIndex:=SearchResultsView.AddSearch(ASearchForm.SearchText,
|
||||
ASearchForm.SearchText,
|
||||
ASearchForm.ReplaceText,
|
||||
ASearchForm.SearchDirectory,
|
||||
ASearchForm.SearchMask,
|
||||
ASearchForm.SearchOptions);
|
||||
|
||||
try
|
||||
SearchResultsView.BeginUpdate(ListIndex);
|
||||
ASearchForm.ResultsList:= SearchResultsView.Items[ListIndex];
|
||||
SearchResultsView.Items[ListIndex].Clear;
|
||||
ASearchForm.ResultsWindow:= ListIndex;
|
||||
try
|
||||
ASearchForm.Show;
|
||||
// update Window Menu, the OnIdle event does not occur while searching
|
||||
MainIDEInterface.UpdateWindowMenu;
|
||||
ASearchForm.DoSearch;
|
||||
except
|
||||
on E: ERegExpr do
|
||||
MessageDlg(lisUEErrorInRegularExpression, E.Message,mtError,
|
||||
[mbCancel],0);
|
||||
end;
|
||||
finally
|
||||
SearchResultsView.EndUpdate(ListIndex);
|
||||
SearchResultsView.ShowOnTop;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.FIFSearchOpenFiles(ADialog: TLazFindInFilesDialog);
|
||||
var
|
||||
i: integer;
|
||||
TheFileList: TStringList;
|
||||
SearchForm: TSearchForm;
|
||||
begin
|
||||
try
|
||||
TheFileList:= TStringList.Create;
|
||||
for i:= 0 to EditorCount -1 do
|
||||
begin
|
||||
//only if file exists on disk
|
||||
if FilenameIsAbsolute(Editors[i].FileName) and
|
||||
FileExistsUTF8(Editors[i].FileName) then
|
||||
begin
|
||||
TheFileList.Add(Editors[i].FileName);
|
||||
end;//if
|
||||
end;//for
|
||||
SearchForm:= FIFCreateSearchForm(ADialog);
|
||||
SearchForm.SearchFileList:= TheFileList;
|
||||
DoFindInFiles(SearchForm);
|
||||
finally
|
||||
FreeAndNil(TheFileList);
|
||||
FreeAndNil(SearchForm);
|
||||
end;//finally
|
||||
end;//FIFSearchOpenFiles
|
||||
|
||||
{Creates the search form and loads the options selected in the
|
||||
findinfilesdialog}
|
||||
function TSourceNotebook.FIFCreateSearchForm
|
||||
(ADialog: TLazFindInFilesDialog): TSearchForm;
|
||||
begin
|
||||
result:= TSearchForm.Create(SearchResultsView);
|
||||
with result do
|
||||
begin
|
||||
SearchOptions:= ADialog.Options;
|
||||
SearchText:= ADialog.FindText;
|
||||
ReplaceText:= ADialog.ReplaceText;
|
||||
SearchMask:= ADialog.FileMaskComboBox.Text;
|
||||
SearchDirectory:= ADialog.DirectoryComboBox.Text;
|
||||
end;//with
|
||||
end;//FIFCreateSearchForm
|
||||
|
||||
Procedure TSourceNotebook.FindInFilesPerDialog(AProject: TProject);
|
||||
var
|
||||
TempEditor: TSourceEditor;
|
||||
FindText: string;
|
||||
Begin
|
||||
FindText:='';
|
||||
TempEditor := GetActiveSE;
|
||||
if TempEditor <> nil
|
||||
then with TempEditor, EditorComponent do
|
||||
begin
|
||||
if EditorOpts.FindTextAtCursor
|
||||
then begin
|
||||
if SelAvail and (BlockBegin.Y = BlockEnd.Y)
|
||||
then FindText := SelText
|
||||
else FindText := GetWordAtRowCol(LogicalCaretXY);
|
||||
end else begin
|
||||
if InputHistories.FindHistory.Count>0 then
|
||||
FindText:=InputHistories.FindHistory[0];
|
||||
end;
|
||||
end;
|
||||
|
||||
FindInFiles(AProject, FindText);
|
||||
End;
|
||||
|
||||
procedure TSourceNotebook.FindInFiles(AProject: TProject;
|
||||
const FindText: string);
|
||||
begin
|
||||
if FindInFilesDialog = nil then
|
||||
FindInFilesDialog := CreateFindInFilesDialog
|
||||
else
|
||||
LoadFindInFilesHistory(FindInFilesDialog);
|
||||
|
||||
// if there is no FindText, use the most recently used FindText
|
||||
FindInFilesDialog.FindText:= FindText;
|
||||
if (FindInFilesDialog.FindText='') and (InputHistories.FindHistory.Count > 0) then
|
||||
FindInFilesDialog.FindText:=InputHistories.FindHistory[0];
|
||||
|
||||
// disable replace. Find in files is often called,
|
||||
// but almost never to replace with the same parameters
|
||||
FindInFilesDialog.Options:=
|
||||
FindInFilesDialog.Options-[fifReplace,fifReplaceAll];
|
||||
if FindInFilesDialog.ShowModal=mrOk then
|
||||
begin
|
||||
SaveFindInFilesHistory(FindInFilesDialog);
|
||||
|
||||
if FindInFilesDialog.FindText <>'' then
|
||||
begin
|
||||
case FindInFilesDialog.WhereRadioGroup.ItemIndex of
|
||||
0: FIFSearchProject(AProject, FindInFilesDialog);
|
||||
1: FIFSearchOpenFiles(FindInFilesDialog);
|
||||
2: FIFSearchDir(FindInFilesDialog);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.ShowSearchResultsView;
|
||||
begin
|
||||
if Assigned(Manager.OnShowSearchResultsView) then Manager.OnShowSearchResultsView(Self);
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.GotoLineClicked(Sender: TObject);
|
||||
var
|
||||
SrcEdit: TSourceEditor;
|
||||
|
Loading…
Reference in New Issue
Block a user