From 4c03e6b1db646f0d88b080503d373080daace5b5 Mon Sep 17 00:00:00 2001 From: Juha Date: Mon, 5 Jun 2023 16:13:20 +0300 Subject: [PATCH] IDE: Show full path, relative path or no path of found files in search results. Mark found text with BOLD. Patch by BrunoK. --- ide/lazarusidestrconsts.pas | 2 +- ide/searchresultview.lfm | 2 -- ide/searchresultview.pp | 46 +++++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 8123aee964..a50d87eadf 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -5447,7 +5447,7 @@ resourcestring rsFoundButNotListedHere = 'Found but not listed here: '; rsRefreshTheSearch = 'Refresh the search'; rsNewSearchWithSameCriteria = 'New search with same criteria'; - rsShowPath = 'Show path'; + rsShowPath = 'Toggle show path modes (Ctrl+P)'; rsCloseCurrentPage = 'Close current page'; rsFilterTheListWithString = 'Filter the lines in list with a string'; rsCloseLeft = 'Close page(s) on the left'; diff --git a/ide/searchresultview.lfm b/ide/searchresultview.lfm index 541bf00304..f7f68a1074 100644 --- a/ide/searchresultview.lfm +++ b/ide/searchresultview.lfm @@ -58,9 +58,7 @@ object SearchResultsView: TSearchResultsView Left = 47 Top = 0 Caption = 'ShowPathButton' - Down = True OnClick = ShowPathButtonClick - Style = tbsCheck end end object SearchInListEdit: TTreeFilterEdit diff --git a/ide/searchresultview.pp b/ide/searchresultview.pp index 92a1b12f91..421c47ecef 100644 --- a/ide/searchresultview.pp +++ b/ide/searchresultview.pp @@ -208,7 +208,8 @@ type Shift: TShiftState; X, Y: Integer); private type - TOnSide = (osLeft, osOthers, osRight); { Handling of multi tab closure } + TOnSide = (osLeft, osOthers, osRight); { Handling of multi tab closure } + TFilePathShow = (fpsFull, fpsRelative, fpsNone); { Parts of path to show } private FAsyncUpdateCloseButtons: TSVCloseButtonsState; FMaxItems: integer; @@ -218,6 +219,7 @@ type FOnSelectionChanged: TNotifyEvent; FMouseOverIndex: integer; FClosingTabs: boolean; + FFilePathShow: TFilePathShow; {~bk} function BeautifyPageName(const APageName: string): string; function GetPageIndex(const APageName: string): integer; function GetTreeView(APageIndex: integer): TLazSearchResultTV; @@ -400,7 +402,6 @@ begin if (Key = VK_P) and (Shift = [ssCtrl]) then begin Key := VK_UNKNOWN; - ShowPathButton.Down := not ShowPathButton.Down; ShowPathButtonClick(Sender); end; if (Key = VK_N) and (Shift = [ssCtrl]) then @@ -517,6 +518,12 @@ procedure TSearchResultsView.ShowPathButtonClick(Sender: TObject); var lTree: TLazSearchResultTV; begin + { Toggle thru the 3 states } {~bk} + if FFilePathShow = High(TFilePathShow) then + FFilePathShow := Low(TFilePathShow) + else + inc(FFilePathShow); + ShowPathButton.Down := False; lTree := GetCurrentTreeView; if lTree = nil then exit; lTree.Invalidate; @@ -1207,8 +1214,8 @@ begin // draw found text if [cdsSelected,cdsMarked] * State <> [] - then DrawNextText(lPart, clHighlightText) - else DrawNextText(lPart, clHighlight); + then DrawNextText(lPart, clHighlightText, [fsBold]) + else DrawNextText(lPart, clHighlight, [fsBold]); // remaining normal text if lMatch.NextInThisLine = nil then @@ -1221,31 +1228,36 @@ begin lMatch := lMatch.NextInThisLine; end; - end else begin { filename } + end + else begin { filename } lTextX := lRect.Left; - // show path or file name lRelPath := ExtractRelativePath( IncludeTrailingPathDelimiter(lTree.SearchObject.SearchDirectories), Node.Text ); - if ShowPathButton.Down then - begin - DrawNextText(lRelPath, clNone, [fsBold]); - end else begin - if [cdsSelected,cdsMarked] * State <> [] then - begin - DrawNextText(ExtractFileName(lRelPath), clNone, [fsBold]); - DrawNextText(' (' + lRelPath + ')', clHighlightText); - end else begin - DrawNextText(ExtractFileName(lRelPath), clNone, [fsBold]); + + // show path or file name + if FFilePathShow = fpsFull then { <= 2.2.6 } + DrawNextText(Node.Text, clNone, [fsBold]) + else begin + if FFilePathShow = fpsRelative then + DrawNextText(lRelPath, clNone, [fsBold]) + else begin + if [cdsSelected,cdsMarked] * State <> [] then begin + DrawNextText(ExtractFileName(lRelPath), clNone, [fsBold]); + DrawNextText(' (' + lRelPath + ')', clHighlightText); + end + else begin + DrawNextText(ExtractFileName(lRelPath), clNone, [fsBold]); + end; end; end; // show a warning that this is a backup folder // strip path delimiter and filename, then check if last directory is 'backup' lPart := ExcludeTrailingPathDelimiter(ExtractFilePath(lRelPath)); - if CompareText('backup', ExtractFileNameOnly(lPart)) = 0 then + if CompareText('backup', ExtractFileName(lPart)) = 0 then DrawNextText(' [BACKUP]', clRed); end;