mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 10:19:16 +02:00
IDE: Show the amount of matches in search results window.
git-svn-id: trunk@28773 -
This commit is contained in:
parent
da7f03a254
commit
2cd2c885ed
@ -90,12 +90,12 @@ type
|
|||||||
procedure SearchFile(const aFilename: string);
|
procedure SearchFile(const aFilename: string);
|
||||||
procedure SetFlag(Flag: TSrcEditSearchOption; AValue: boolean);
|
procedure SetFlag(Flag: TSrcEditSearchOption; AValue: boolean);
|
||||||
procedure DoSearchAndAddToSearchResults;
|
procedure DoSearchAndAddToSearchResults;
|
||||||
|
function DoSearch: integer;
|
||||||
public
|
public
|
||||||
procedure DoSearchOpenFiles;
|
procedure DoSearchOpenFiles;
|
||||||
procedure DoSearchDir;
|
procedure DoSearchDir;
|
||||||
procedure DoSearchProject(AProject: TProject);
|
procedure DoSearchProject(AProject: TProject);
|
||||||
public
|
public
|
||||||
procedure DoSearch;
|
|
||||||
property SearchDirectory: string read fTheDirectory write fTheDirectory;
|
property SearchDirectory: string read fTheDirectory write fTheDirectory;
|
||||||
property SearchText: string read fSearchFor write fSearchFor;
|
property SearchText: string read fSearchFor write fSearchFor;
|
||||||
property ReplaceText: string read FReplaceText write FReplaceText;
|
property ReplaceText: string read FReplaceText write FReplaceText;
|
||||||
@ -688,8 +688,10 @@ begin
|
|||||||
if fSearchFiles then include(Result,fifSearchDirectories);
|
if fSearchFiles then include(Result,fifSearchDirectories);
|
||||||
end;//GetOptions
|
end;//GetOptions
|
||||||
|
|
||||||
procedure TSearchForm.DoSearch;
|
function TSearchForm.DoSearch: integer;
|
||||||
|
// Search the text and then return the number of found items.
|
||||||
begin
|
begin
|
||||||
|
Result:= 0;
|
||||||
PromptOnReplace:=true;
|
PromptOnReplace:=true;
|
||||||
fAborting:=false;
|
fAborting:=false;
|
||||||
Progress.Abort:=false;
|
Progress.Abort:=false;
|
||||||
@ -703,13 +705,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
try
|
try
|
||||||
if fSearchFiles then
|
if fSearchFiles then
|
||||||
begin
|
|
||||||
DoFindInFiles(fTheDirectory);
|
DoFindInFiles(fTheDirectory);
|
||||||
end;//if
|
|
||||||
if fSearchProject or fSearchOpen then
|
if fSearchProject or fSearchOpen then
|
||||||
DoFindInSearchList;
|
DoFindInSearchList;
|
||||||
if Assigned(fResultsList) and (fResultsList.Count = 0) then
|
if Assigned(fResultsList) then begin
|
||||||
fResultsList.Add(Format(lisUESearchStringNotFound,[dbgstr(fSearchFor)]));
|
Result:=fResultsList.Count; // Return the real item count.
|
||||||
|
if fResultsList.Count = 0 then // Add a note to the list if no items found.
|
||||||
|
fResultsList.Add(Format(lisUESearchStringNotFound,[dbgstr(fSearchFor)]));
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
if fResultsListUpdating then begin
|
if fResultsListUpdating then begin
|
||||||
fResultsListUpdating:=false;
|
fResultsListUpdating:=false;
|
||||||
@ -878,32 +881,31 @@ end;
|
|||||||
procedure TSearchForm.DoSearchAndAddToSearchResults;
|
procedure TSearchForm.DoSearchAndAddToSearchResults;
|
||||||
var
|
var
|
||||||
ListPage: TTabSheet;
|
ListPage: TTabSheet;
|
||||||
|
Cnt: integer;
|
||||||
begin
|
begin
|
||||||
ListPage:=SearchResultsView.AddSearch(SearchText,
|
Cnt:= 0;
|
||||||
SearchText,
|
ListPage:=SearchResultsView.AddSearch(SearchText, SearchText,
|
||||||
ReplaceText,
|
ReplaceText,SearchDirectory,
|
||||||
SearchDirectory,
|
SearchMask, SearchOptions);
|
||||||
SearchMask,
|
|
||||||
SearchOptions);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
(* BeginUpdate prevents ListPage from being closed,
|
(* BeginUpdate prevents ListPage from being closed,
|
||||||
other pages can stil be closed or inserted, so PageIndex can change *)
|
other pages can stil be closed or inserted, so PageIndex can change *)
|
||||||
SearchResultsView.BeginUpdate(ListPage.PageIndex);
|
SearchResultsView.BeginUpdate(ListPage.PageIndex);
|
||||||
ResultsList := SearchResultsView.Items[ListPage.PageIndex];
|
ResultsList:= SearchResultsView.Items[ListPage.PageIndex];
|
||||||
ResultsList.Clear;
|
ResultsList.Clear;
|
||||||
ResultsWindow:= ListPage;
|
ResultsWindow:= ListPage;
|
||||||
try
|
try
|
||||||
Show; // floating window, not dockable
|
Show; // floating window, not dockable
|
||||||
// update Window Menu, the OnIdle event does not occur while searching
|
// update Window Menu, the OnIdle event does not occur while searching
|
||||||
MainIDEInterface.UpdateWindowMenu;
|
MainIDEInterface.UpdateWindowMenu;
|
||||||
DoSearch;
|
Cnt:= DoSearch;
|
||||||
except
|
except
|
||||||
on E: ERegExpr do
|
on E: ERegExpr do
|
||||||
MessageDlg(lisUEErrorInRegularExpression, E.Message,mtError,
|
MessageDlg(lisUEErrorInRegularExpression, E.Message,mtError,
|
||||||
[mbCancel],0);
|
[mbCancel],0);
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
ListPage.Caption:= Format('%s (%d)',[SearchResultsView.WorkedSearchText,Cnt]);
|
||||||
SearchResultsView.EndUpdate(ListPage.PageIndex);
|
SearchResultsView.EndUpdate(ListPage.PageIndex);
|
||||||
// bring to front
|
// bring to front
|
||||||
IDEWindowCreators.ShowForm(SearchResultsView,true);
|
IDEWindowCreators.ShowForm(SearchResultsView,true);
|
||||||
|
@ -38,7 +38,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs,
|
||||||
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus,
|
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus, strutils,
|
||||||
IDEWindowIntf, IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts,
|
IDEWindowIntf, IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts,
|
||||||
InputHistory, IDEProcs, Project, MainIntf, Clipbrd;
|
InputHistory, IDEProcs, Project, MainIntf, Clipbrd;
|
||||||
|
|
||||||
@ -171,10 +171,10 @@ type
|
|||||||
procedure FilterButtonClick (Sender: TObject );
|
procedure FilterButtonClick (Sender: TObject );
|
||||||
private
|
private
|
||||||
FMaxItems: integer;
|
FMaxItems: integer;
|
||||||
|
FWorkedSearchText: string;
|
||||||
FOnSelectionChanged: TNotifyEvent;
|
FOnSelectionChanged: TNotifyEvent;
|
||||||
FMouseOverIndex: integer;
|
FMouseOverIndex: integer;
|
||||||
function BeautifyPageName(const APageName: string): string;
|
function BeautifyPageName(const APageName: string): string;
|
||||||
function PageExists(const APageName: string): boolean;
|
|
||||||
function GetPageIndex(const APageName: string): integer;
|
function GetPageIndex(const APageName: string): integer;
|
||||||
function GetTreeView(APageIndex: integer): TLazSearchResultTV;
|
function GetTreeView(APageIndex: integer): TLazSearchResultTV;
|
||||||
procedure TreeViewClicked(Sender: TObject);
|
procedure TreeViewClicked(Sender: TObject);
|
||||||
@ -194,7 +194,6 @@ type
|
|||||||
function GetSourceFileName: string;
|
function GetSourceFileName: string;
|
||||||
function GetSelectedText: string;
|
function GetSelectedText: string;
|
||||||
function GetSelectedMatchPos: TLazSearchMatchPos;
|
function GetSelectedMatchPos: TLazSearchMatchPos;
|
||||||
procedure BringResultsToFront(const APageName: string);
|
|
||||||
procedure AddMatch(const APageIndex: integer;
|
procedure AddMatch(const APageIndex: integer;
|
||||||
const Filename: string; const StartPos, EndPos: TPoint;
|
const Filename: string; const StartPos, EndPos: TPoint;
|
||||||
const TheText: string;
|
const TheText: string;
|
||||||
@ -203,11 +202,13 @@ type
|
|||||||
procedure EndUpdate(APageIndex: integer);
|
procedure EndUpdate(APageIndex: integer);
|
||||||
procedure Parse_Search_Phrases(var slPhrases: TStrings);
|
procedure Parse_Search_Phrases(var slPhrases: TStrings);
|
||||||
procedure ClosePage(PageIndex: integer);
|
procedure ClosePage(PageIndex: integer);
|
||||||
|
|
||||||
|
property MaxItems: integer read FMaxItems write SetMaxItems;
|
||||||
|
property WorkedSearchText: string read FWorkedSearchText;
|
||||||
property OnSelectionChanged: TNotifyEvent read fOnSelectionChanged
|
property OnSelectionChanged: TNotifyEvent read fOnSelectionChanged
|
||||||
write fOnSelectionChanged;
|
write fOnSelectionChanged;
|
||||||
property Items[Index: integer]: TStrings read GetItems write SetItems;
|
property Items[Index: integer]: TStrings read GetItems write SetItems;
|
||||||
property MaxItems: integer read FMaxItems write SetMaxItems;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
function SearchResultsView: TSearchResultsView;
|
function SearchResultsView: TSearchResultsView;
|
||||||
|
|
||||||
@ -564,7 +565,7 @@ end;
|
|||||||
|
|
||||||
function TSearchResultsView.BeautifyPageName(const APageName: string): string;
|
function TSearchResultsView.BeautifyPageName(const APageName: string): string;
|
||||||
const
|
const
|
||||||
MaxPageName = 25;
|
MaxPageName = 22;
|
||||||
begin
|
begin
|
||||||
Result:=SpecialCharsToHex(APageName);
|
Result:=SpecialCharsToHex(APageName);
|
||||||
if UTF8Length(Result)>MaxPageName then
|
if UTF8Length(Result)>MaxPageName then
|
||||||
@ -694,16 +695,6 @@ begin
|
|||||||
Hide;
|
Hide;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{Brings the results tab named APageName to front.
|
|
||||||
If APageName does not exist, does nothing}
|
|
||||||
procedure TSearchResultsView.BringResultsToFront(const APageName: string);
|
|
||||||
begin
|
|
||||||
if PageExists(APageName) then
|
|
||||||
begin
|
|
||||||
ResultsNoteBook.PageIndex:= GetPageIndex(APageName);
|
|
||||||
end;//if
|
|
||||||
end;//BringResultsToFront
|
|
||||||
|
|
||||||
{Sets the Items from the treeview on the currently selected page in the
|
{Sets the Items from the treeview on the currently selected page in the
|
||||||
TNoteBook}
|
TNoteBook}
|
||||||
procedure TSearchResultsView.SetItems(Index: integer; Value: TStrings);
|
procedure TSearchResultsView.SetItems(Index: integer; Value: TStrings);
|
||||||
@ -782,25 +773,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{Searched the notebook control for a page with APageName name, returns true if
|
|
||||||
found}
|
|
||||||
function TSearchResultsView.PageExists(const APageName: string): boolean;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
CurPagename: String;
|
|
||||||
begin
|
|
||||||
Result:= false;
|
|
||||||
CurPagename:=BeautifyPageName(APageName);
|
|
||||||
for i:= 0 to ResultsNoteBook.PageCount - 1 do
|
|
||||||
begin
|
|
||||||
if (ResultsNoteBook.Page[i].Caption = CurPageName) then
|
|
||||||
begin
|
|
||||||
Result:= true;
|
|
||||||
exit;
|
|
||||||
end;//if
|
|
||||||
end;//for
|
|
||||||
end;//PageExists
|
|
||||||
|
|
||||||
procedure TSearchResultsView.TreeViewKeyDown(Sender: TObject; var Key: Word;
|
procedure TSearchResultsView.TreeViewKeyDown(Sender: TObject; var Key: Word;
|
||||||
Shift: TShiftState);
|
Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
@ -824,20 +796,17 @@ var
|
|||||||
NewPage: LongInt;
|
NewPage: LongInt;
|
||||||
i: integer;
|
i: integer;
|
||||||
SearchObj: TLazSearch;
|
SearchObj: TLazSearch;
|
||||||
NewPageName: String;
|
|
||||||
begin
|
begin
|
||||||
Result:= nil;
|
Result:= nil;
|
||||||
if Assigned(ResultsNoteBook) then
|
if Assigned(ResultsNoteBook) then
|
||||||
begin
|
|
||||||
NewPageName:=BeautifyPageName(ResultsName);
|
|
||||||
//DebugLn(['TSearchResultsView.AddSearch NewPageName=',dbgstr(NewPageName),' ResultsName="',dbgstr(ResultsName),'"']);
|
|
||||||
with ResultsNoteBook do
|
with ResultsNoteBook do
|
||||||
begin
|
begin
|
||||||
i:= GetPageIndex(NewPageName);
|
FWorkedSearchText:=BeautifyPageName(ResultsName);
|
||||||
|
i:= GetPageIndex(FWorkedSearchText);
|
||||||
if i>=0 then
|
if i>=0 then
|
||||||
begin
|
begin
|
||||||
NewTreeView:= GetTreeView(i);
|
NewTreeView:= GetTreeView(i);
|
||||||
ResultsNoteBook.PageIndex:= i;
|
PageIndex:= i;
|
||||||
//Free backup objects and list since its a new search with the same TreeView
|
//Free backup objects and list since its a new search with the same TreeView
|
||||||
NewTreeView.FreeObjects(NewTreeView.BackUpStrings);
|
NewTreeView.FreeObjects(NewTreeView.BackUpStrings);
|
||||||
NewTreeView.BackUpStrings.Clear;
|
NewTreeView.BackUpStrings.Clear;
|
||||||
@ -845,9 +814,9 @@ begin
|
|||||||
end//if
|
end//if
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
NewPage:= TCustomNotebook(ResultsNoteBook).Pages.Add(NewPageName);
|
NewPage:= TCustomNotebook(ResultsNoteBook).Pages.Add(FWorkedSearchText);
|
||||||
ResultsNoteBook.PageIndex:= NewPage;
|
PageIndex:= NewPage;
|
||||||
ResultsNoteBook.Page[ResultsNoteBook.PageIndex].OnKeyDown := @TreeViewKeyDown;
|
Page[PageIndex].OnKeyDown := @TreeViewKeyDown;
|
||||||
if NewPage > -1 then
|
if NewPage > -1 then
|
||||||
begin
|
begin
|
||||||
NewTreeView:= TLazSearchResultTV.Create(Page[NewPage]);
|
NewTreeView:= TLazSearchResultTV.Create(Page[NewPage]);
|
||||||
@ -864,26 +833,25 @@ begin
|
|||||||
OnMouseMove:= @LazTVMousemove;
|
OnMouseMove:= @LazTVMousemove;
|
||||||
OnMouseWheel:= @LazTVMouseWheel;
|
OnMouseWheel:= @LazTVMouseWheel;
|
||||||
ShowHint:= true;
|
ShowHint:= true;
|
||||||
RowSelect := True;
|
RowSelect := True; // we are using custom draw
|
||||||
Options := Options + [tvoAllowMultiselect] - [tvoThemedDraw]; // we are using custom draw
|
Options := Options + [tvoAllowMultiselect] - [tvoThemedDraw];
|
||||||
PopupMenu := popList;
|
PopupMenu := popList;
|
||||||
NewTreeView.Canvas.Brush.Color:= clWhite;
|
NewTreeView.Canvas.Brush.Color:= clWhite;
|
||||||
end;//with
|
end;//with
|
||||||
end;//if
|
end;//if
|
||||||
end;//else
|
end;//else
|
||||||
|
SearchObj:=NewTreeView.SearchObject;
|
||||||
|
if SearchObj<>nil then begin
|
||||||
|
SearchObj.SearchString:= SearchText;
|
||||||
|
SearchObj.ReplaceText := ReplaceText;
|
||||||
|
SearchObj.SearchDirectory:= ADirectory;
|
||||||
|
SearchObj.SearchMask:= AMask;
|
||||||
|
SearchObj.SearchOptions:= TheOptions;
|
||||||
|
end;
|
||||||
|
NewTreeView.Skipped:=0;
|
||||||
|
Result:= Pages[PageIndex];
|
||||||
|
SearchInListEdit.Clear;
|
||||||
end;//with
|
end;//with
|
||||||
SearchObj:=NewTreeView.SearchObject;
|
|
||||||
if SearchObj<>nil then begin
|
|
||||||
SearchObj.SearchString:= SearchText;
|
|
||||||
SearchObj.ReplaceText := ReplaceText;
|
|
||||||
SearchObj.SearchDirectory:= ADirectory;
|
|
||||||
SearchObj.SearchMask:= AMask;
|
|
||||||
SearchObj.SearchOptions:= TheOptions;
|
|
||||||
end;
|
|
||||||
NewTreeView.Skipped:=0;
|
|
||||||
Result:= ResultsNoteBook.Pages[ResultsNoteBook.PageIndex];
|
|
||||||
SearchInListEdit.Clear;
|
|
||||||
end;//if
|
|
||||||
end;//AddResult
|
end;//AddResult
|
||||||
|
|
||||||
procedure TSearchResultsView.LazTVShowHint(Sender: TObject;
|
procedure TSearchResultsView.LazTVShowHint(Sender: TObject;
|
||||||
@ -1066,14 +1034,17 @@ end;
|
|||||||
|
|
||||||
function TSearchResultsView.GetPageIndex(const APageName: string): integer;
|
function TSearchResultsView.GetPageIndex(const APageName: string): integer;
|
||||||
var
|
var
|
||||||
i: integer;
|
Paren, i: integer;
|
||||||
CurPagename: String;
|
PN: String;
|
||||||
begin
|
begin
|
||||||
Result:= -1;
|
Result:= -1;
|
||||||
CurPagename:=BeautifyPageName(APageName);
|
|
||||||
for i:= 0 to ResultsNoteBook.PageCount - 1 do
|
for i:= 0 to ResultsNoteBook.PageCount - 1 do
|
||||||
begin
|
begin
|
||||||
if (ResultsNoteBook.Page[i].Caption = CurPageName) then
|
PN:= ResultsNoteBook.Page[i].Caption;
|
||||||
|
Paren:= Pos(' (', PN);
|
||||||
|
if (Paren>0) and (PosEx(')', PN, Paren+2)>0) then
|
||||||
|
PN:= LeftStr(PN, Paren-1);
|
||||||
|
if PN = APageName then
|
||||||
begin
|
begin
|
||||||
Result:= i;
|
Result:= i;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user