mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 17:59:16 +02:00
ide: find in files wnd: path editor
This commit is contained in:
parent
dc9124cb4e
commit
4db15c7bce
@ -699,7 +699,6 @@ object LazFindInFilesWindow: TLazFindInFilesWindow
|
|||||||
AnchorSideLeft.Control = WherePanel
|
AnchorSideLeft.Control = WherePanel
|
||||||
AnchorSideTop.Control = FileMaskComboBox
|
AnchorSideTop.Control = FileMaskComboBox
|
||||||
AnchorSideTop.Side = asrBottom
|
AnchorSideTop.Side = asrBottom
|
||||||
AnchorSideRight.Control = DirsEditSpeedButton
|
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 30
|
Height = 30
|
||||||
Top = 32
|
Top = 32
|
||||||
@ -707,6 +706,8 @@ object LazFindInFilesWindow: TLazFindInFilesWindow
|
|||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
BorderSpacing.Top = 2
|
BorderSpacing.Top = 2
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
|
ParentShowHint = False
|
||||||
|
ShowHint = True
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Text = 'Directories'
|
Text = 'Directories'
|
||||||
end
|
end
|
||||||
@ -769,6 +770,8 @@ object LazFindInFilesWindow: TLazFindInFilesWindow
|
|||||||
Width = 463
|
Width = 463
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
|
ParentShowHint = False
|
||||||
|
ShowHint = True
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
Text = 'Packages'
|
Text = 'Packages'
|
||||||
end
|
end
|
||||||
@ -785,19 +788,6 @@ object LazFindInFilesWindow: TLazFindInFilesWindow
|
|||||||
Anchors = [akTop, akRight, akBottom]
|
Anchors = [akTop, akRight, akBottom]
|
||||||
Caption = '...'
|
Caption = '...'
|
||||||
end
|
end
|
||||||
object DirsEditSpeedButton: TSpeedButton
|
|
||||||
AnchorSideTop.Control = DirectoriesComboBox
|
|
||||||
AnchorSideRight.Control = WherePanel
|
|
||||||
AnchorSideRight.Side = asrBottom
|
|
||||||
AnchorSideBottom.Control = DirectoriesComboBox
|
|
||||||
AnchorSideBottom.Side = asrBottom
|
|
||||||
Left = 778
|
|
||||||
Height = 30
|
|
||||||
Top = 32
|
|
||||||
Width = 23
|
|
||||||
Anchors = [akTop, akRight, akBottom]
|
|
||||||
Caption = '...'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
object ReplaceButton: TButton
|
object ReplaceButton: TButton
|
||||||
AnchorSideTop.Control = ReplaceTextComboBox
|
AnchorSideTop.Control = ReplaceTextComboBox
|
||||||
|
@ -20,9 +20,11 @@ unit FindInFilesWnd;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, StdCtrls, Buttons, ComCtrls, ExtCtrls, DividerBevel,
|
Classes, SysUtils, System.UITypes, Forms, StdCtrls, Buttons, ComCtrls,
|
||||||
SynEdit, EnvironmentOpts, MenuIntf, IDEWindowIntf, LazIDEIntf, SrcEditorIntf,
|
ExtCtrls, Controls, DividerBevel, SynEdit, EnvironmentOpts, SearchPathProcs,
|
||||||
LazFileUtils, InputHistory, EditorOptions;
|
MenuIntf, IDEWindowIntf, LazIDEIntf, SrcEditorIntf, IDEDialogs, LazFileUtils,
|
||||||
|
LazLoggerBase, ProjectIntf, MacroIntf, InputHistory, EditorOptions,
|
||||||
|
PathEditorDlg;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -32,7 +34,6 @@ type
|
|||||||
CaseSensitiveSpeedButton: TSpeedButton;
|
CaseSensitiveSpeedButton: TSpeedButton;
|
||||||
AutoUpdateSpeedButton: TSpeedButton;
|
AutoUpdateSpeedButton: TSpeedButton;
|
||||||
DirectoriesComboBox: TComboBox;
|
DirectoriesComboBox: TComboBox;
|
||||||
DirsEditSpeedButton: TSpeedButton;
|
|
||||||
FileMaskComboBox: TComboBox;
|
FileMaskComboBox: TComboBox;
|
||||||
TextToFindCombobox: TComboBox;
|
TextToFindCombobox: TComboBox;
|
||||||
ShowReplaceSpeedButton: TSpeedButton;
|
ShowReplaceSpeedButton: TSpeedButton;
|
||||||
@ -51,11 +52,16 @@ type
|
|||||||
SynEdit1: TSynEdit;
|
SynEdit1: TSynEdit;
|
||||||
WholeWordsSpeedButton: TSpeedButton;
|
WholeWordsSpeedButton: TSpeedButton;
|
||||||
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||||
procedure ShowReplaceSpeedButtonClick(Sender: TObject);
|
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormDestroy(Sender: TObject);
|
procedure FormDestroy(Sender: TObject);
|
||||||
|
procedure ShowReplaceSpeedButtonClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
|
DirectoriesPathEditBtn: TPathEditorButton;
|
||||||
|
procedure DirectoriesPathEditBtnClick(Sender: TObject);
|
||||||
|
function DirectoriesPathEditBtnExecuted(Context: String; var NewPath: String
|
||||||
|
): Boolean;
|
||||||
protected
|
protected
|
||||||
|
function GetBaseDirectory: string; virtual;
|
||||||
procedure DoFirstShow; override;
|
procedure DoFirstShow; override;
|
||||||
procedure InitImageList; virtual;
|
procedure InitImageList; virtual;
|
||||||
procedure LoadHistory; virtual;
|
procedure LoadHistory; virtual;
|
||||||
@ -130,6 +136,27 @@ begin
|
|||||||
|
|
||||||
DirectoriesComboBox.TextHint:='folder1;folder2';
|
DirectoriesComboBox.TextHint:='folder1;folder2';
|
||||||
DirectoriesComboBox.Text:='';
|
DirectoriesComboBox.Text:='';
|
||||||
|
DirectoriesPathEditBtn := TPathEditorButton.Create(Self);
|
||||||
|
with DirectoriesPathEditBtn do
|
||||||
|
begin
|
||||||
|
Name := 'DirectoriesPathEditBtn';
|
||||||
|
Caption := '...';
|
||||||
|
AutoSize := true;
|
||||||
|
Anchors := [akRight, akTop, akBottom];
|
||||||
|
AnchorParallel(akTop, 0, DirectoriesComboBox);
|
||||||
|
AnchorParallel(akBottom, 0, DirectoriesComboBox);
|
||||||
|
AnchorParallel(akRight, 0, WherePanel);
|
||||||
|
ContextCaption := 'Search in directories';
|
||||||
|
Templates:='$(ProjPath)'+
|
||||||
|
';$(LazarusDir)' +
|
||||||
|
';$(FPCSrcDir)';
|
||||||
|
AssociatedComboBox:=DirectoriesComboBox;
|
||||||
|
OnClick := @DirectoriesPathEditBtnClick;
|
||||||
|
OnExecuted := @DirectoriesPathEditBtnExecuted;
|
||||||
|
Parent := WherePanel;
|
||||||
|
TabOrder := DirectoriesComboBox.TabOrder+1;
|
||||||
|
end;
|
||||||
|
DirectoriesComboBox.AnchorToNeighbour(akRight, 0, DirectoriesPathEditBtn);
|
||||||
|
|
||||||
SrcDividerBevel.Caption:='Preview';
|
SrcDividerBevel.Caption:='Preview';
|
||||||
SynEdit1.Lines.Text:='No source selected';
|
SynEdit1.Lines.Text:='No source selected';
|
||||||
@ -137,6 +164,18 @@ begin
|
|||||||
InitImageList;
|
InitImageList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazFindInFilesWindow.FormClose(Sender: TObject;
|
||||||
|
var CloseAction: TCloseAction);
|
||||||
|
begin
|
||||||
|
if CloseAction=caNone then ;
|
||||||
|
SaveHistory;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLazFindInFilesWindow.FormDestroy(Sender: TObject);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesWindow.ShowReplaceSpeedButtonClick(Sender: TObject);
|
procedure TLazFindInFilesWindow.ShowReplaceSpeedButtonClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
DisableAlign;
|
DisableAlign;
|
||||||
@ -154,16 +193,66 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesWindow.FormClose(Sender: TObject;
|
procedure TLazFindInFilesWindow.DirectoriesPathEditBtnClick(Sender: TObject);
|
||||||
var CloseAction: TCloseAction);
|
|
||||||
begin
|
begin
|
||||||
if CloseAction=caNone then ;
|
DirectoriesPathEditBtn.CurrentPathEditor.BaseDirectory := GetBaseDirectory;
|
||||||
SaveHistory;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesWindow.FormDestroy(Sender: TObject);
|
function TLazFindInFilesWindow.DirectoriesPathEditBtnExecuted(Context: String;
|
||||||
|
var NewPath: String): Boolean;
|
||||||
|
var
|
||||||
|
TrimmedPath, BaseDir, Dir: String;
|
||||||
|
p, r: Integer;
|
||||||
begin
|
begin
|
||||||
|
if Context='' then ;
|
||||||
|
TrimmedPath := TrimSearchPath(NewPath, '', true);
|
||||||
|
BaseDir:=GetBaseDirectory;
|
||||||
|
p:=1;
|
||||||
|
repeat
|
||||||
|
Dir:=GetNextDirectoryInSearchPath(TrimmedPath,p);
|
||||||
|
if Dir='' then break;
|
||||||
|
DebugLn(['TLazFindInFilesWindow.DirectoriesPathEditBtnExecuted Dir="',Dir,'"']);
|
||||||
|
if not IDEMacros.SubstituteMacros(Dir) then
|
||||||
|
begin
|
||||||
|
r:=IDEMessageDialog('Invalid Macro','Path "'+Dir+'" contains unknown macros',
|
||||||
|
mtError,[mbCancel,mbIgnore]);
|
||||||
|
if r<>mrIgnore then
|
||||||
|
exit(false);
|
||||||
|
end else begin
|
||||||
|
debugln(['TLazFindInFilesWindow.DirectoriesPathEditBtnExecuted macro resolved Dir="',Dir,'"']);
|
||||||
|
Dir:=ExpandFileNameUTF8(Dir,BaseDir);
|
||||||
|
debugln(['TLazFindInFilesWindow.DirectoriesPathEditBtnExecuted expanded Dir="',Dir,'"']);
|
||||||
|
if not DirectoryExists(Dir,true) then
|
||||||
|
begin
|
||||||
|
r:=IDEMessageDialog('Path not found','Path "'+Dir+'" not found',
|
||||||
|
mtError,[mbCancel,mbIgnore]);
|
||||||
|
if r<>mrIgnore then
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
|
||||||
|
NewPath:=TrimmedPath;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLazFindInFilesWindow.GetBaseDirectory: string;
|
||||||
|
var
|
||||||
|
Proj: TLazProject;
|
||||||
|
begin
|
||||||
|
Proj:=LazarusIDE.ActiveProject;
|
||||||
|
if Proj<>nil then
|
||||||
|
begin
|
||||||
|
Result:=Proj.Directory;
|
||||||
|
if FilenameIsAbsolute(Result) then
|
||||||
|
exit;
|
||||||
|
Result:=LazarusIDE.GetTestBuildDirectory;
|
||||||
|
if FilenameIsAbsolute(Result) then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result:='$(LazarusDir)';
|
||||||
|
if not IDEMacros.SubstituteMacros(Result) then
|
||||||
|
Result:=LazarusIDE.GetPrimaryConfigPath;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazFindInFilesWindow.DoFirstShow;
|
procedure TLazFindInFilesWindow.DoFirstShow;
|
||||||
@ -208,6 +297,18 @@ procedure TLazFindInFilesWindow.LoadHistory;
|
|||||||
AComboBox.Items.Insert(i,Filename);
|
AComboBox.Items.Insert(i,Filename);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure AddDir(Dir: string);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i:=0 to DirectoriesComboBox.Items.Count-1 do
|
||||||
|
begin
|
||||||
|
if CompareFilenames(ChompPathDelim(Dir),ChompPathDelim(DirectoriesComboBox.Items[i]))=0 then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
DirectoriesComboBox.Items.Add(Dir);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
SrcEdit: TSourceEditorInterface;
|
SrcEdit: TSourceEditorInterface;
|
||||||
begin
|
begin
|
||||||
@ -227,6 +328,8 @@ begin
|
|||||||
AssignToComboBox(DirectoriesComboBox, InputHistories.FindInFilesPathHistory);
|
AssignToComboBox(DirectoriesComboBox, InputHistories.FindInFilesPathHistory);
|
||||||
if (SrcEdit<>nil) and (FilenameIsAbsolute(SrcEdit.FileName)) then
|
if (SrcEdit<>nil) and (FilenameIsAbsolute(SrcEdit.FileName)) then
|
||||||
AddFileToComboBox(DirectoriesComboBox, ExtractFilePath(SrcEdit.FileName));
|
AddFileToComboBox(DirectoriesComboBox, ExtractFilePath(SrcEdit.FileName));
|
||||||
|
AddDir('$(FPCSrcDir)');
|
||||||
|
AddDir('$(LazarusDir)');
|
||||||
if DirectoriesComboBox.Items.Count>0 then
|
if DirectoriesComboBox.Items.Count>0 then
|
||||||
DirectoriesComboBox.Text:=DirectoriesComboBox.Items[0];
|
DirectoriesComboBox.Text:=DirectoriesComboBox.Items[0];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user