Recent

Author Topic: Search again  (Read 2465 times)

Paolo

  • Jr. Member
  • **
  • Posts: 61
Search again
« on: September 21, 2020, 07:13:02 pm »
hello, in delphi once a search is done, for example for a variable "x", all the found occurence of "x" are shown, and the same in lazarus. But in delphi if I modify or remove some "x in the code it is possible right click on the previous search result, very easy an clear, to update the search content, in lazarus I did not find such function and this means that after several code editing and search the message box is populated of the several tabs search result and the message list becomes ureadable. Can I achieve the same functionality as in Delphi ? Thank you

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3886
  • I like bugs.
Re: Search again
« Reply #1 on: September 21, 2020, 09:36:55 pm »
You can freely close any tabs in the Search Results window. In Lazarus trunk (development version) it even has buttons to close left, other, right or all tabs.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #2 on: September 21, 2020, 10:51:22 pm »
Thanks for the reply.

I think the delphi approach is more consistent.
I'll try to compare the lazarus way to delphi way.
Delphi
1) search, for example for X var,
2) the search result is showing the found Xs occurrences in the code
3) jump from one of X in search result to the code line
4) do the job, now the search result need to be updated
5) right click on the search result of X, on the popup do search update
6) repeat steps 3) to 5) as many times as needed, in the serch result list there is just one tab for X.
If you are working alternating on more variables, just go to the relevant tab and do search again, without risk of duplicated tabs around.

Lazarus
1) search, for example for X var,
2) the search result is showing the found Xs occurrences in the code
3) jump from one of X in search result to the code line
4) do the job, now the search result need to be updated
5) close the previous X search result
6) reopen the search dialog form, and press ok
7) repeat steps 3) to 6) as many times as needed, but..
If you forget step 5) you have a duplicated tab with different results
If you are working alternating search among more variables at step 6) you have to retype the var (or select it from the list of previously searched.

I think the delphi approch is clearer and more coherent.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6708
  • Debugger - SynEdit - and more
    • wiki
Re: Search again
« Reply #3 on: September 21, 2020, 11:32:47 pm »
I agree, it is a "nice to have".

For now, all there is, is the long way.

You can make it a feature request, but I do not know when (or even if) someone would pick it up...
Otherwise it is "patch welcome"

I don't know your skill level, but it may take less than you expect. If you are willing to put in the hours.

Each  new search is triggered from main.pp line 10886 (lazarus svn trunk)
   function TMainIDE.DoFindInFiles: TModalResult;

Units involved
  ide\findinfilesdlg.pas
  ide\SearchFrm.pas  // TSearchProgressForm
  ide\SearchResultView.pp  // TSearchResultsView


Look at TSearchProgressForm.
Any of the DoSearch*** methods end up calling DoSearchAndAddToSearchResults

Then you can modify the SearchResultsView add the contexct menu.
Make sure you have *ALL* the search options, in order to repeat the search, and re-use the existing tab.

In fact
procedure TSearchResultsView.SearchAgainButtonClick(Sender: TObject);
already shows you how to get the old search options.
But it either does not yet store all, or does not restore them all to the dialog (that could be fixed too). Also You want to skip the dialog.



It's only 2 (maybe 3) units that need to be looked at. So it does not require any deep knowledge. And also, there is no shame in asking further questions. If you want to give it a go, I am glad to answer questions.



JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3886
  • I like bugs.
Re: Search again
« Reply #4 on: September 23, 2020, 01:17:16 am »
+1
Yes, actually it is a good idea.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #5 on: September 23, 2020, 06:02:49 pm »
I think to try both:

1) How can I submit a "requested feature" ?
2) I don't know if I'll be able to accomplish the "patch" task, but I would try....

Thanks

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6708
  • Debugger - SynEdit - and more
    • wiki
Re: Search again
« Reply #6 on: September 23, 2020, 06:27:27 pm »
Feature request => on the bugtracker.

Patch => start looking at the code. If you have questions: ask.

Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #7 on: September 26, 2020, 05:35:54 pm »
Dear Martin_fr,

I started to modify the code, but before add "repeat search", I thought to modify two other steps (agian in the delphi style):

1) if search give "0" items found the searched string is not shwn in the tablist and a message is informing the user of failed search.

2) if the search was already done on the word "abc", the old tab is deleted and the new one shown.

Apparentlly I was succesful in doing both the above tasks... I'm testing, then I would like to share with you what  I ave done (maybe  I did something violating some coding rules in "Lazarus" team).

After that  I'll try to add the "repeat search" functionality.

From what  I see I have the feeling that code for pure search is mixed with code for showing results, so it is difficult to extrapolate only the search part, but I have just given alook at the code....

as soon as possible I'll show you what  I have done, maybe not so elegant but quite striaghtforward.

Ciao.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6708
  • Debugger - SynEdit - and more
    • wiki
Re: Search again
« Reply #8 on: September 26, 2020, 06:31:35 pm »
First of all: If you do more than one change try to make a separate patch for each changeset.

If you want to use git (which easily allows for this), you can clone my mirror at https://github.com/User4martin/lazarus
For the specific changes in regards to this thread you may create pull requests. (But patches are equally fine).

Pull requests for any other feature, not part of the search related changed, must be pre-agreed for pull requests.

I started to modify the code, but before add "repeat search", I thought to modify two other steps (agian in the delphi style):

1) if search give "0" items found the searched string is not shwn in the tablist and a message is informing the user of failed search.

2) if the search was already done on the word "abc", the old tab is deleted and the new one shown.
I am not much in favour of those two.

1) A search may take rather long. It is possible to carry on working during the search (I have done that). In such a case, I do not want to be interrupted by an alert about a failed search, as this would take the focus from the editor.
In that sense, I also much prefer, that the search result window opens when the search starts. So when the search ends, nothing takes away the focus.

2) It is ok, only if the search settings are 100% identical.
I may (and have in the past) search(ed) the same term, but with different settings (whole word or not / different dir).
I could see an option where they get grouped as different tree nodes into the same tab. That is, instead of having the directory tree nodes, at top level, there would be a new top level per search. (with some useful info, how the 2 or more searches differed).
That however is a lot more work.


Quote
Apparentlly I was succesful in doing both the above tasks... I'm testing, then I would like to share with you what  I ave done (maybe  I did something violating some coding rules in "Lazarus" team).
You can submit them, then I will review them.

Need to see, if the actual changes are desirable in the current proposed way.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3886
  • I like bugs.
Re: Search again
« Reply #9 on: September 26, 2020, 10:24:16 pm »
I am not much in favour of those two.
I agree.
1) Same reason as Martin has.
2) This does the same thing as the original "search update" feature but is less intuitive.
It is better to stick with the original plan. If a user wants to reuse the same old tab, he chooses "search update". Otherwise he does a new search with a dialog.
This is flexible and offers more choices.
« Last Edit: September 27, 2020, 09:34:59 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #10 on: October 05, 2020, 01:32:23 pm »
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.

lucamar

  • Hero Member
  • *****
  • Posts: 3188
Re: Search again
« Reply #11 on: October 05, 2020, 04:48:34 pm »
No comment about the feature (it's one I rarely use) but please, Paolo, read this section in the wiki: "Use code tags" and follow it; it makes easier for the rest of us to read code in posts like yours. Thanks! :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #12 on: October 05, 2020, 04:56:46 pm »
thanks a lot lucamar, here the more readable version

Code: Pascal  [Select][+][-]
  1.  
  2. In UNIT SEARCHESULTVIEW
  3.  
  4.   TSearchResultsView = class(TForm)
  5.   ..
  6.   public
  7.      function IfAlreadySearched(Index : integer; const SearchText : string): boolean;
  8.    ..
  9.    end;
  10.  
  11. the code implementation
  12.  
  13.  
  14.  
  15. function TSearchResultsView.IfAlreadySearched(Index : integer; const SearchText : string): boolean;
  16. var
  17.   CurrentTV: TLazSearchResultTV;
  18.   SearchObj: TLazSearch;
  19. begin
  20.   result:=false;
  21.   CurrentTV:= GetTreeView(Index);  
  22.   SearchObj:= CurrentTV.SearchObject;
  23.   if SearchObj.fSearchString = SearchText then begin
  24.     result:=(SearchObj.fSearchOptions = FindInFilesDialogSingleton.Options);
  25.   end;
  26. end;
  27.  
  28. In UNIT SEARCHFRM
  29.  
  30. procedure TSearchProgressForm.DoSearchAndAddToSearchResults;
  31. var
  32.   ListPage: TTabSheet;
  33.   Cnt: integer;
  34.   State: TIWGetFormState;
  35.   i : integer;
  36. begin
  37.   Cnt:= 0;
  38.   LazarusIDE.DoShowSearchResultsView(iwgfShow);
  39.  
  40. //here the "only" added block, if the same occurence of search is found it is deleted
  41. //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
  42. //better go through all the results
  43.   i:=0;
  44.   while i < SearchResultsView.ResultsNoteBook.PageCount do begin
  45.     if SearchResultsView.IfAlreadySearched(i, SearchText) then
  46.       SearchResultsView.ClosePage(i)
  47.     else
  48.       i:=i+1
  49.    end;
  50.  
  51.     ListPage:=SearchResultsView.AddSearch(SearchText,SearchText,
  52.                                 ReplaceText,SearchDirectories,SearchMask,SearchOptions);
  53.       try
  54.         (* BeginUpdate prevents ListPage from being closed,
  55.           other pages can still be closed or inserted, so PageIndex can change *)
  56.         SearchResultsView.BeginUpdate(ListPage.PageIndex);
  57.         ResultsList:= SearchResultsView.Items[ListPage.PageIndex];
  58.         ResultsList.Clear;
  59.         ResultsWindow:= ListPage;
  60.         try
  61.           Show; // floating window, not dockable
  62.           Cnt:= DoSearch;
  63.         except
  64.           on E: ERegExpr do
  65.             IDEMessageDialog(lisUEErrorInRegularExpression, E.Message,mtError,
  66.                        [mbCancel]);
  67.         end;
  68.       finally
  69.         ListPage.Caption:= Format('%s (%d)',[ListPage.Caption,Cnt]);
  70.         SearchResultsView.EndUpdate(ListPage.PageIndex);
  71.         // show, but bring to front only if Search Progress dialog was active
  72.         if fWasActive then
  73.           State:=iwgfShowOnTop
  74.         else
  75.           State:=iwgfShow;
  76.         LazarusIDE.DoShowSearchResultsView(State);
  77.       end;
  78. end;
  79.  

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6708
  • Debugger - SynEdit - and more
    • wiki
Re: Search again
« Reply #13 on: October 05, 2020, 05:41:49 pm »
Code tags is fine. But for changes to existing code, it needs to be a patch/diff.
https://wiki.lazarus.freepascal.org/Creating_A_Patch


Paolo

  • Jr. Member
  • **
  • Posts: 61
Re: Search again
« Reply #14 on: October 05, 2020, 07:37:18 pm »
As first step I have to download GIT (is it this one ? https://git-scm.com/)
« Last Edit: October 05, 2020, 07:40:07 pm by Paolo »

 

TinyPortal © 2005-2018