Hello,
here my first step attempting to follow the original plan (JuhaManninen : "It is better to stick with the original plan")
The plan is:
user do a search with some selected options
then
a) it is a new search, and a new tab is added to the search result
b) the search has been already done (same text, same options), here we can follow to path:
b1) update a previous search
b2) remove the old search and add a new tab.
I selected the b1) that seems has less impact on the already availabe code and offers some other advantages..
But at this stage the first step was that even the user go through "find in file dialog" the behaviour has to be as above described, then will follow the other part of the code in case of just "search again" on the relevant tab (to be completed).
Here my proposal and code modification of fisrt stage of this topi when the user goes through the dialogform:
In UNIT SEARCHESULTVIEW
TSearchResultsView = class(TForm)
..
public
function IfAlreadySearched(Index : integer; const SearchText : string): boolean;
..
end;
the code implementation
function TSearchResultsView.IfAlreadySearched(Index : integer; const SearchText : string): boolean;
var
CurrentTV: TLazSearchResultTV;
SearchObj: TLazSearch;
begin
result:=false;
CurrentTV:= GetTreeView(Index);
SearchObj:= CurrentTV.SearchObject;
if SearchObj.fSearchString = SearchText then begin
result:=(SearchObj.fSearchOptions = FindInFilesDialogSingleton.Options);
end;
end;
In UNIT SEARCHFRM
procedure TSearchProgressForm.DoSearchAndAddToSearchResults;
var
ListPage: TTabSheet;
Cnt: integer;
State: TIWGetFormState;
i : integer;
begin
Cnt:= 0;
LazarusIDE.DoShowSearchResultsView(iwgfShow);
//here the "only" added block, if the same occurence of search is found it is deleted
//It could be (in the future imic the curretn lazarus behaviour) a user option to have separate tabs result for same results, so it is
//better go through all the results
i:=0;
while i < SearchResultsView.ResultsNoteBook.PageCount do begin
if SearchResultsView.IfAlreadySearched(i, SearchText) then
SearchResultsView.ClosePage(i)
else
i:=i+1
end;
ListPage:=SearchResultsView.AddSearch(SearchText,SearchText,
ReplaceText,SearchDirectories,SearchMask,SearchOptions);
try
(* BeginUpdate prevents ListPage from being closed,
other pages can still be closed or inserted, so PageIndex can change *)
SearchResultsView.BeginUpdate(ListPage.PageIndex);
ResultsList:= SearchResultsView.Items[ListPage.PageIndex];
ResultsList.Clear;
ResultsWindow:= ListPage;
try
Show; // floating window, not dockable
Cnt:= DoSearch;
except
on E: ERegExpr do
IDEMessageDialog(lisUEErrorInRegularExpression, E.Message,mtError,
[mbCancel]);
end;
finally
ListPage.Caption:= Format('%s (%d)',[ListPage.Caption,Cnt]);
SearchResultsView.EndUpdate(ListPage.PageIndex);
// show, but bring to front only if Search Progress dialog was active
if fWasActive then
State:=iwgfShowOnTop
else
State:=iwgfShow;
LazarusIDE.DoShowSearchResultsView(State);
end;
end;
Dear Martin_Fr and JuhaManninen comments are welcome (maybe I am very far from the "right solution"). If it is ok we can move on the search again without passing through dialog box.