IDE: Add "Active File" to Search in Files where-selections. Issue #7686

git-svn-id: trunk@38924 -
This commit is contained in:
juha 2012-09-30 16:09:09 +00:00
parent 4593c8f87f
commit 0839a029db
6 changed files with 141 additions and 107 deletions

View File

@ -1,18 +1,18 @@
object LazFindInFilesDialog: TLazFindInFilesDialog
Left = 408
Height = 400
Height = 437
Top = 154
Width = 441
Width = 461
ActiveControl = TextToFindComboBox
AutoSize = True
Caption = 'Find in files'
ClientHeight = 400
ClientWidth = 441
Constraints.MinHeight = 380
ClientHeight = 437
ClientWidth = 461
Constraints.MinHeight = 430
Constraints.MinWidth = 400
OnClose = FormClose
OnCreate = FormCreate
LCLVersion = '0.9.31'
LCLVersion = '1.1'
object OptionsCheckGroupBox: TCheckGroup
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ReplaceTextComboBox
@ -20,9 +20,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 70
Top = 60
Width = 429
Height = 83
Top = 76
Width = 449
Anchors = [akTop, akLeft, akRight]
AutoFill = True
AutoSize = True
@ -38,6 +38,8 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 62
ClientWidth = 441
Columns = 2
Items.Strings = (
'Case sensitive'
@ -57,9 +59,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 93
Top = 136
Width = 429
Height = 83
Top = 165
Width = 449
Anchors = [akTop, akLeft, akRight]
AutoFill = True
AutoSize = True
@ -74,14 +76,16 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 75
ClientWidth = 425
ChildSizing.ControlsPerLine = 2
ClientHeight = 62
ClientWidth = 441
Columns = 2
ItemIndex = 1
Items.Strings = (
'search all files in project'
'search all open files'
'search in directories'
'search in active file'
)
OnClick = WhereRadioGroupClick
TabOrder = 4
@ -93,15 +97,15 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 110
Top = 235
Width = 429
Height = 131
Top = 254
Width = 449
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Around = 6
Caption = 'Directory Options'
ClientHeight = 92
ClientWidth = 425
ClientHeight = 110
ClientWidth = 441
Enabled = False
TabOrder = 5
object DirectoryLabel: TLabel
@ -109,9 +113,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = DirectoryComboBox
AnchorSideTop.Side = asrCenter
Left = 6
Height = 14
Top = 9
Width = 49
Height = 17
Top = 12
Width = 61
BorderSpacing.Left = 6
Caption = 'Directory:'
FocusControl = DirectoryComboBox
@ -122,9 +126,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = DirectoryComboBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 14
Top = 39
Width = 44
Height = 17
Top = 47
Width = 59
BorderSpacing.Left = 6
BorderSpacing.Top = 12
Caption = 'File mask'
@ -136,15 +140,15 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = DirectoryOptionsGroupBox
AnchorSideRight.Control = DirectoryBrowse
Left = 61
Height = 21
Left = 73
Height = 29
Top = 6
Width = 314
Width = 330
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
ItemHeight = 13
ItemHeight = 0
TabOrder = 0
end
object DirectoryBrowse: TBitBtn
@ -152,16 +156,15 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = DirectoryComboBox
AnchorSideRight.Control = DirectoryOptionsGroupBox
AnchorSideRight.Side = asrBottom
Left = 381
Height = 23
Left = 409
Height = 28
Top = 6
Width = 38
Width = 26
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Right = 6
Caption = '...'
Layout = blGlyphTop
NumGlyphs = 0
OnClick = DirectoryBrowseClick
TabOrder = 1
end
@ -172,13 +175,13 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = DirectoryComboBox
AnchorSideRight.Side = asrBottom
Left = 56
Height = 21
Top = 36
Width = 319
Left = 71
Height = 29
Top = 41
Width = 332
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6
ItemHeight = 13
ItemHeight = 0
TabOrder = 2
Text = '*.pas;*.pp;*.inc'
end
@ -187,9 +190,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = FileMaskComboBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 17
Top = 69
Width = 126
Height = 22
Top = 82
Width = 170
BorderSpacing.Left = 6
BorderSpacing.Top = 12
BorderSpacing.Bottom = 6
@ -201,16 +204,20 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 26
Top = 368
Width = 429
Height = 33
Top = 398
Width = 449
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
OKButton.OnClick = OKButtonClick
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
HelpButton.OnClick = HelpButtonClick
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CloseButton.Enabled = False
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 6
ShowButtons = [pbOK, pbCancel, pbHelp]
ShowBevel = False
@ -222,9 +229,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 68
Height = 21
Top = 33
Left = 88
Height = 29
Top = 41
Width = 367
Anchors = [akTop, akLeft, akRight]
AutoComplete = True
@ -234,7 +241,7 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
Enabled = False
ItemHeight = 13
ItemHeight = 0
TabOrder = 2
end
object ReplaceCheckBox: TCheckBox
@ -242,9 +249,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = ReplaceTextComboBox
AnchorSideTop.Side = asrCenter
Left = 6
Height = 17
Top = 35
Width = 56
Height = 22
Top = 44
Width = 76
BorderSpacing.Left = 6
Caption = 'Replace'
Enabled = False
@ -256,9 +263,9 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = TextToFindComboBox
AnchorSideTop.Side = asrCenter
Left = 6
Height = 14
Top = 9
Width = 65
Height = 17
Top = 12
Width = 75
BorderSpacing.Left = 6
Caption = 'Text To Find:'
ParentColor = False
@ -269,17 +276,17 @@ object LazFindInFilesDialog: TLazFindInFilesDialog
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 77
Height = 21
Left = 87
Height = 29
Top = 6
Width = 358
Width = 368
Anchors = [akTop, akLeft, akRight]
AutoComplete = True
AutoCompleteText = [cbactEnabled, cbactEndOfLineComplete, cbactRetainPrefixCase, cbactSearchAscending]
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
ItemHeight = 13
ItemHeight = 0
TabOrder = 0
end
object SelectDirectoryDialog: TSelectDirectoryDialog

View File

@ -83,6 +83,12 @@ function FindInFilesDialog: TLazFindInFilesDialog;
implementation
const // WhereRadioGroup's ItemIndex in a more informative form.
ItemIndProject = 0;
ItemIndOpenFiles = 1;
ItemIndDirectories = 2;
ItemIndActiveFile = 3;
var
FindInFilesDialogSingleton: TLazFindInFilesDialog = nil;
@ -116,7 +122,7 @@ end;
procedure TLazFindInFilesDialog.WhereRadioGroupClick(Sender: TObject);
begin
DirectoryOptionsGroupBox.Enabled := (WhereRadioGroup.ItemIndex = 2)
DirectoryOptionsGroupBox.Enabled := (WhereRadioGroup.ItemIndex = ItemIndDirectories)
end;
procedure TLazFindInFilesDialog.DirectoryBrowseClick(Sender: TObject);
@ -154,9 +160,10 @@ begin
OptionsCheckGroupBox.Items[3] := lisFindFileMultiLinePattern;
WhereRadioGroup.Caption:=lisFindFileWhere;
WhereRadioGroup.Items[0] := lisFindFilesearchAllFilesInProject;
WhereRadioGroup.Items[1] := lisFindFilesearchAllOpenFiles;
WhereRadioGroup.Items[2] := lisFindFilesearchInDirectories;
WhereRadioGroup.Items[ItemIndProject] := lisFindFilesearchAllFilesInProject;
WhereRadioGroup.Items[ItemIndOpenFiles] := lisFindFilesearchAllOpenFiles;
WhereRadioGroup.Items[ItemIndDirectories] := lisFindFilesearchInDirectories;
WhereRadioGroup.Items[ItemIndActiveFile] := lisFindFilesearchInActiveFile;
DirectoryOptionsGroupBox.Caption := lisFindFileDirectoryOptions;
DirectoryLabel.Caption := lisFindFileDirectory;
@ -170,7 +177,7 @@ begin
ReplaceCheckBox.Enabled:=true;
UpdateReplaceCheck;
DirectoryOptionsGroupBox.Enabled:=WhereRadioGroup.ItemIndex=2;
DirectoryOptionsGroupBox.Enabled:=WhereRadioGroup.ItemIndex=ItemIndDirectories;
AutoSize:=IDEDialogLayoutList.Find(Self,false)=nil;
IDEDialogLayoutList.ApplyLayout(Self);
@ -186,7 +193,7 @@ var
Dir: String;
begin
Dir:=GetResolvedDirectory;
if (WhereRadioGroup.ItemIndex=2) and (not DirectoryExistsUTF8(Dir)) then
if (WhereRadioGroup.ItemIndex=ItemIndDirectories) and not DirectoryExistsUTF8(Dir) then
begin
MessageDlg(lisEnvOptDlgDirectoryNotFound,
Format(dlgSeachDirectoryNotFound,[Dir]),
@ -210,9 +217,10 @@ begin
IncludeSubDirsCheckBox.Checked := fifIncludeSubDirs in NewOptions;
ReplaceCheckBox.Checked := [fifReplace,fifReplaceAll]*NewOptions<>[];
if fifSearchProject in NewOptions then WhereRadioGroup.ItemIndex := 0;
if fifSearchOpen in NewOptions then WhereRadioGroup.ItemIndex := 1;
if fifSearchDirectories in NewOptions then WhereRadioGroup.ItemIndex := 2;
if fifSearchProject in NewOptions then WhereRadioGroup.ItemIndex := ItemIndProject;
if fifSearchOpen in NewOptions then WhereRadioGroup.ItemIndex := ItemIndOpenFiles;
if fifSearchDirectories in NewOptions then WhereRadioGroup.ItemIndex := ItemIndDirectories;
if fifSearchActive in NewOptions then WhereRadioGroup.ItemIndex := ItemIndActiveFile;
UpdateReplaceCheck;
end;
@ -228,9 +236,10 @@ begin
if ReplaceCheckBox.Checked then Include(Result, fifReplace);
case WhereRadioGroup.ItemIndex of
0: Include(Result, fifSearchProject);
1: Include(Result, fifSearchOpen);
2: Include(Result, fifSearchDirectories);
ItemIndProject : Include(Result, fifSearchProject);
ItemIndOpenFiles : Include(Result, fifSearchOpen);
ItemIndDirectories: Include(Result, fifSearchDirectories);
ItemIndActiveFile : Include(Result, fifSearchActive);
end;//case
end;
@ -373,8 +382,7 @@ begin
FileMaskComboBox.Text:= TLazSearch(Sender).SearchMask;
end;
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject;
const AFindText: string);
procedure TLazFindInFilesDialog.FindInFiles(AProject: TProject; const AFindText: string);
var
SearchForm: TSearchProgressForm;
begin
@ -392,22 +400,23 @@ begin
begin
SaveHistory;
SearchForm:= TSearchProgressForm.Create(SearchResultsView);
with SearchForm do begin
SearchOptions := self.Options;
SearchText := self.FindText;
ReplaceText := self.ReplaceText;
SearchMask := self.FileMaskComboBox.Text;
SearchDirectory := self.GetResolvedDirectory;
end;
SearchForm:= TSearchProgressForm.Create(SearchResultsView);
with SearchForm do begin
SearchOptions := self.Options;
SearchText := self.FindText;
ReplaceText := self.ReplaceText;
SearchMask := self.FileMaskComboBox.Text;
SearchDirectory := self.GetResolvedDirectory;
end;
try
if FindText <> '' then
begin
case WhereRadioGroup.ItemIndex of
0: SearchForm.DoSearchProject(AProject);
1: SearchForm.DoSearchOpenFiles;
2: SearchForm.DoSearchDir;
ItemIndProject : SearchForm.DoSearchProject(AProject);
ItemIndOpenFiles : SearchForm.DoSearchOpenFiles;
ItemIndDirectories: SearchForm.DoSearchDir;
ItemIndActiveFile : SearchForm.DoSearchActiveFile;
end;
end;
finally

View File

@ -166,9 +166,10 @@ type
fifMultiLine,
fifSearchProject, // search in all project files
fifSearchOpen, // search in all open files in editor
fifSearchActive, // search in active open file in editor
fifSearchDirectories,// search in directories
fifIncludeSubDirs,
fifReplace, // replace and ask user before each replace
fifReplace, // replace and ask user before each replace
fifReplaceAll // replace without asking user
);
TLazFindInFileSearchOptions = set of TLazFindInFileSearchOption;

View File

@ -3682,6 +3682,7 @@ resourcestring
lisFindFileWhere = 'Where';
lisFindFilesearchAllFilesInProject = 'search all files in &project';
lisFindFilesearchAllOpenFiles = 'search all &open files';
lisFindFilesearchInActiveFile = 'search in &active file';
lisFindFilesearchInDirectories = 'search in &directories';
lisFindFileDirectoryOptions = 'Directory options';
lisFindFileDirectory = 'D&irectory';

View File

@ -10,7 +10,7 @@ object SearchProgressForm: TSearchProgressForm
OnCreate = SearchFormCREATE
OnDestroy = SearchFormDESTROY
Position = poScreenCenter
LCLVersion = '0.9.31'
LCLVersion = '1.1'
Visible = True
object Panel2: TPanel
Left = 0
@ -29,7 +29,7 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideTop.Side = asrCenter
Left = 121
Height = 1
Top = 91
Top = 98
Width = 1
ParentColor = False
ShowAccelChar = False
@ -38,9 +38,9 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideTop.Control = SearchingLabel
AnchorSideTop.Side = asrBottom
Left = 16
Height = 14
Top = 84
Width = 41
Height = 17
Top = 90
Width = 54
BorderSpacing.Top = 18
Caption = 'Matches'
ParentColor = False
@ -50,7 +50,7 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideTop.Side = asrCenter
Left = 121
Height = 1
Top = 59
Top = 63
Width = 1
ParentColor = False
ShowAccelChar = False
@ -59,9 +59,9 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideTop.Control = SearchTextLabel
AnchorSideTop.Side = asrBottom
Left = 16
Height = 14
Top = 52
Width = 52
Height = 17
Top = 55
Width = 68
BorderSpacing.Top = 18
Caption = 'Searching:'
ParentColor = False
@ -69,9 +69,9 @@ object SearchProgressForm: TSearchProgressForm
object SearchTextLabel: TLabel
AnchorSideTop.Control = Panel2
Left = 16
Height = 14
Height = 17
Top = 20
Width = 63
Width = 78
BorderSpacing.Top = 18
Caption = 'Search Text:'
ParentColor = False
@ -81,7 +81,7 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideTop.Side = asrCenter
Left = 121
Height = 1
Top = 27
Top = 28
Width = 1
ParentColor = False
ShowAccelChar = False
@ -93,10 +93,10 @@ object SearchProgressForm: TSearchProgressForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel2
AnchorSideBottom.Side = asrBottom
Left = 312
Height = 26
Top = 133
Width = 77
Left = 306
Height = 31
Top = 128
Width = 89
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Top = 12
@ -105,7 +105,6 @@ object SearchProgressForm: TSearchProgressForm
Caption = 'Cancel'
Kind = bkCancel
ModalResult = 2
NumGlyphs = 0
OnClick = btnAbortCLICK
TabOrder = 0
end

View File

@ -75,9 +75,10 @@ type
fSearchFileList: TStringList;
fSearchFiles: boolean;
fSearchFor: String;
fSearchOpen: boolean;
fSearchProject: boolean;
fTheDirectory: string;
fSearchOpen: boolean;
fSearchActive: boolean;
fSearchProject: boolean;
fAborting: boolean;
fLastUpdateProgress: DWORD;
procedure DoFindInFiles(ADirectory: string);
@ -94,6 +95,7 @@ type
function DoSearch: integer;
public
procedure DoSearchOpenFiles;
procedure DoSearchActiveFile;
procedure DoSearchDir;
procedure DoSearchProject(AProject: TProject);
public
@ -675,6 +677,7 @@ begin
fRecursive:= (fifIncludeSubDirs in TheOptions);
fSearchProject:= (fifSearchProject in TheOptions);
fSearchOpen:= (fifSearchOpen in TheOptions);
fSearchActive:= (fifSearchActive in TheOptions);
fSearchFiles:= (fifSearchDirectories in TheOptions);
end;//SetOptions
@ -690,6 +693,7 @@ begin
if fRecursive then include(Result,fifIncludeSubDirs);
if fSearchProject then include(Result, fifSearchProject);
if fSearchOpen then include(Result,fifSearchOpen);
if fSearchActive then include(Result,fifSearchActive);
if fSearchFiles then include(Result,fifSearchDirectories);
end;//GetOptions
@ -711,7 +715,7 @@ begin
try
if fSearchFiles then
DoFindInFiles(fTheDirectory);
if fSearchProject or fSearchOpen then
if fSearchProject or fSearchOpen or fSearchActive then
DoFindInSearchList;
if Assigned(fResultsList) then begin
Result:=fResultsList.Count; // Return the real item count.
@ -942,8 +946,7 @@ begin
//only if file exists on disk
SrcEdit := SourceEditorManagerIntf.UniqueSourceEditors[i];
if FilenameIsAbsolute(SrcEdit.FileName)
and (not FileExistsCached(SrcEdit.FileName))
then
and (not FileExistsCached(SrcEdit.FileName)) then
continue;
TheFileList.Add(SrcEdit.FileName);
end;
@ -954,6 +957,20 @@ begin
end;
end;
procedure TSearchProgressForm.DoSearchActiveFile;
var
TheFileList: TStringList;
begin
try
TheFileList:= TStringList.Create; // Add a single file to the list
TheFileList.Add(SourceEditorManagerIntf.ActiveEditor.FileName);
SearchFileList:= TheFileList;
DoSearchAndAddToSearchResults;
finally
FreeAndNil(TheFileList);
end;
end;
procedure TSearchProgressForm.DoSearchDir;
begin
SearchFileList:= Nil;