From 6e1adda7215203ad4c017337b8b1a0d3c35f094b Mon Sep 17 00:00:00 2001 From: Juha Date: Sun, 14 May 2023 16:08:17 +0300 Subject: [PATCH] IDE, LazControls: Improve TTreeFilterEdit behavior. Fix property ExpandAllInitially. Issue #40257. --- components/ideintf/objectinspector.lfm | 3 ++- components/lazcontrols/treefilteredit.pas | 17 +++++++----- ide/searchresultview.lfm | 2 ++ ide/toolbarconfig.lfm | 5 ++-- ide/toolbarconfig.pas | 33 +++++++++++------------ 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/components/ideintf/objectinspector.lfm b/components/ideintf/objectinspector.lfm index 4dbd6d252c..91c98b4fb4 100644 --- a/components/ideintf/objectinspector.lfm +++ b/components/ideintf/objectinspector.lfm @@ -12,7 +12,7 @@ object ObjectInspectorDlg: TObjectInspectorDlg ClientHeight = 818 ClientWidth = 293 KeyPreview = True - LCLVersion = '2.1.0.0' + LCLVersion = '2.3.0.0' object StatusBar: TStatusBar Left = 0 Height = 21 @@ -72,6 +72,7 @@ object ObjectInspectorDlg: TObjectInspectorDlg NumGlyphs = 1 MaxLength = 0 TabOrder = 0 + ExpandAllInitially = True end object CompFilterLabel: TLabel Left = 3 diff --git a/components/lazcontrols/treefilteredit.pas b/components/lazcontrols/treefilteredit.pas index 10f9f037a8..e32b8c0121 100644 --- a/components/lazcontrols/treefilteredit.pas +++ b/components/lazcontrols/treefilteredit.pas @@ -20,7 +20,7 @@ uses // LCL LCLType, Graphics, ComCtrls, EditBtn, // LazUtils - LazFileUtils, LazUTF8, AvgLvlTree; + LazFileUtils, LazUTF8, LazLoggerBase, AvgLvlTree; type TImageIndexEvent = function (Str: String; Data: TObject; @@ -476,21 +476,24 @@ var Pass, Done: Boolean; begin Result := False; + Pass := False; Done := False; - while (Node<>nil) and not Done do + while Node<>nil do begin // Filter with event handler if there is one. if Assigned(fOnFilterNode) then Pass := fOnFilterNode(Node, Done); - if not (Pass and Done) then + if not Done then Pass := DoFilterItem(Node.Text, Node.Data); if Pass and (fFirstPassedNode=Nil) then fFirstPassedNode:=Node; // Recursive call for child nodes. - Node.Visible:=FilterTree(Node.GetFirstChild) or Pass; - if Node.Visible then - Result:=True; - Node:=Node.GetNextSibling; + Node.Visible := FilterTree(Node.GetFirstChild) or Pass; + if Node.Visible then begin // Collapse all when Filter=''. + Node.Expanded := (Filter<>'') or fExpandAllInitially; + Result := True; + end; + Node := Node.GetNextSibling; end; end; diff --git a/ide/searchresultview.lfm b/ide/searchresultview.lfm index 6b4d1948b5..8985fc8a1a 100644 --- a/ide/searchresultview.lfm +++ b/ide/searchresultview.lfm @@ -13,6 +13,7 @@ object SearchResultsView: TSearchResultsView OnClose = FormClose OnCreate = Form1Create OnKeyDown = FormKeyDown + LCLVersion = '2.3.0.0' object ControlBar1: TPanel Left = 0 Height = 26 @@ -80,6 +81,7 @@ object SearchResultsView: TSearchResultsView MaxLength = 0 TabOrder = 1 OnChange = SearchInListChange + ExpandAllInitially = True end object CloseTabs: TToolBar Left = 616 diff --git a/ide/toolbarconfig.lfm b/ide/toolbarconfig.lfm index b432f3d8e6..52dbdc9042 100644 --- a/ide/toolbarconfig.lfm +++ b/ide/toolbarconfig.lfm @@ -12,7 +12,7 @@ object ToolBarConfig: TToolBarConfig OnCreate = FormCreate OnDestroy = FormDestroy Position = poScreenCenter - LCLVersion = '2.1.0.0' + LCLVersion = '2.3.0.0' object lblMenuTree: TLabel AnchorSideLeft.Control = TV AnchorSideLeft.Side = asrCenter @@ -115,6 +115,7 @@ object ToolBarConfig: TToolBarConfig BorderSpacing.Bottom = 6 ReadOnly = True ScrollBars = ssAutoBoth + ShowSeparators = False TabOrder = 1 OnDblClick = TVDblClick OnSelectionChanged = TVSelectionChanged @@ -137,7 +138,7 @@ object ToolBarConfig: TToolBarConfig ParentFont = False TabOrder = 0 FilteredTreeview = TV - ExpandAllInitially = True + OnFilterNode = FilterEditFilterNode end object Splitter1: TSplitter AnchorSideLeft.Control = TV diff --git a/ide/toolbarconfig.pas b/ide/toolbarconfig.pas index f5ece617e9..8babd8db34 100644 --- a/ide/toolbarconfig.pas +++ b/ide/toolbarconfig.pas @@ -63,6 +63,7 @@ type Splitter1: TSplitter; TV: TTreeView; procedure btnHelpClick(Sender: TObject); + function FilterEditFilterNode({%H-}ItemNode: TTreeNode; out Done: Boolean): Boolean; procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); @@ -79,7 +80,6 @@ type {%H-}Selected: Boolean); procedure TVSelectionChanged(Sender: TObject); private - Image: TBitMap; defImageIndex: integer; procedure AddCommand; procedure AddDivider; @@ -89,7 +89,6 @@ type procedure MoveUpDown(aOffset: integer); function NewLvItem(aCaption: string): TListItem; procedure RemoveCommand; - procedure SetupCaptions; procedure LoadCategories; procedure SortCategories(ACtgList: TStrings); procedure AddMenuItem(ParentNode: TTreeNode; CmdItem: TIDEButtonCommand); @@ -163,9 +162,9 @@ begin lvToolbar.SmallImages := IDEImages.Images_16; // default image to be used when none is available defImageIndex := IDEImages.LoadImage('execute'); - - Image := TBitmap.Create; - SetupCaptions; + Caption := lisToolbarConfiguration; + lblMenuTree.Caption := lisCoolbarAvailableCommands; + lblToolbar.Caption := lisCoolbarToolbarCommands; LoadCategories; IDEDialogLayoutList.ApplyLayout(Self); end; @@ -177,7 +176,7 @@ end; procedure TToolBarConfig.FormDestroy(Sender: TObject); begin - Image.Free; + ; end; procedure TToolBarConfig.lvToolbarDblClick(Sender: TObject); @@ -200,6 +199,12 @@ begin OpenUrl('http://wiki.freepascal.org/IDE_Window:_Toolbar_Config'); end; +function TToolBarConfig.FilterEditFilterNode(ItemNode: TTreeNode; out Done: Boolean): Boolean; +begin + Result := lvToolbar.FindCaption(0, ItemNode.Text, True, True, False) = Nil; + Done := not Result; +end; + procedure TToolBarConfig.UpdateButtonsState; var I: Integer; @@ -252,8 +257,7 @@ begin Node := TV.Selected; if (Node = Nil) or (Node.Data = Nil) then Exit; - CmdCaption := TIDEButtonCommand(Node.Data).Caption; - DeleteAmpersands(CmdCaption); + CmdCaption := TIDEButtonCommand(Node.Data).GetCaptionWithShortCut; lvItem := NewLvItem(CmdCaption); lvItem.Data := Node.Data; if Node.ImageIndex > -1 then @@ -344,13 +348,6 @@ begin MoveUpDown(-1); end; -procedure TToolBarConfig.SetupCaptions; -begin - Caption := lisToolbarConfiguration; - lblMenuTree.Caption := lisCoolbarAvailableCommands; - lblToolbar.Caption := lisCoolbarToolbarCommands; -end; - procedure TToolBarConfig.LoadCategories; var i, l: integer; @@ -424,7 +421,7 @@ var Node: TTreeNode; begin if CmdItem.Caption = '-' then Exit; // divider - Node := TV.Items.AddChild(ParentNode, Format('%s', [CmdItem.GetCaptionWithShortCut])); + Node := TV.Items.AddChild(ParentNode, CmdItem.GetCaptionWithShortCut); Node.ImageIndex := CmdItem.ImageIndex; Node.SelectedIndex := CmdItem.ImageIndex; Node.Data := CmdItem; @@ -500,8 +497,8 @@ begin begin Cmd := IDEToolButtonCategories.FindItemByMenuPathOrName(Value); AddToolBarItem(Cmd); // Add command. - if Value <> SL[I] then - DebugLn(['TToolBarConfig.LoadSettings: SL[I]=', SL[I], ', Value=', Value]); + //if Value <> SL[I] then + // DebugLn(['TToolBarConfig.LoadSettings: SL[I]=', SL[I], ', Value=', Value]); SL[I] := Value; end; end;