diff --git a/comp/src/gb.gui.base/.project b/comp/src/gb.gui.base/.project index d3bb57034..648a2fad7 100644 --- a/comp/src/gb.gui.base/.project +++ b/comp/src/gb.gui.base/.project @@ -1,6 +1,6 @@ # Gambas Project File 3.0 Title=Common controls and classes for GUI components -Startup=FTestGridView +Startup=FTestTreeView Icon=.hidden/window.png Version=3.18.90 VersionFile=1 diff --git a/comp/src/gb.gui.base/.src/Test/FTestTreeView.class b/comp/src/gb.gui.base/.src/Test/FTestTreeView.class index 6ff52508d..03a140938 100644 --- a/comp/src/gb.gui.base/.src/Test/FTestTreeView.class +++ b/comp/src/gb.gui.base/.src/Test/FTestTreeView.class @@ -34,7 +34,7 @@ Public Sub Form_Open() If sParent = sDir Then sParent = "" With tvwTest.Add(sPath, File.Name(sPath), If(IsDir(sPath), hDirPict, hFilePict), sParent) .Span = IsDir(sPath) - .Selectable = Not IsDir(sPath) + '.Selectable = Not IsDir(sPath) .[1] = Stat(sPath).Size bDark = Not bDark If bDark Then .Background = Color.RGB(0, 0, 0, 240) @@ -183,3 +183,9 @@ Public Sub Button7_Click() tvwTest.Enabled = Not tvwTest.Enabled End + +Public Sub Button8_Click() + + tvwTest.Current.Visible = False + +End diff --git a/comp/src/gb.gui.base/.src/Test/FTestTreeView.form b/comp/src/gb.gui.base/.src/Test/FTestTreeView.form index 993b23c66..f9aac127c 100644 --- a/comp/src/gb.gui.base/.src/Test/FTestTreeView.form +++ b/comp/src/gb.gui.base/.src/Test/FTestTreeView.form @@ -1,7 +1,7 @@ # Gambas Form File 3.0 { Form Form - MoveScaled(0,0,121,84) + MoveScaled(0,0,156,84) Arrangement = Arrange.Vertical Margin = True { mnuPopup Menu @@ -21,7 +21,7 @@ } } { HBox1 HBox - MoveScaled(1,9,116,4) + MoveScaled(1,9,145,4) { Button1 Button MoveScaled(0,0,14,4) Text = ("Delete") @@ -50,8 +50,9 @@ MoveScaled(90,0,14,4) Text = ("Enabled") } - { CheckBox1 CheckBox - MoveScaled(105,0,24,4) + { Button8 Button + MoveScaled(105,0,14,4) + Text = ("Hide") } } { Separator1 Separator @@ -61,7 +62,6 @@ MoveScaled(13,22,42,26) Drop = True Expand = True - Mode = Select.Multiple Sorted = True Editable = True Resizable = True diff --git a/comp/src/gb.gui.base/.src/TreeView/_TreeView.class b/comp/src/gb.gui.base/.src/TreeView/_TreeView.class index d49ce5b32..403ce7a94 100644 --- a/comp/src/gb.gui.base/.src/TreeView/_TreeView.class +++ b/comp/src/gb.gui.base/.src/TreeView/_TreeView.class @@ -81,6 +81,15 @@ Event Scroll Event Draw(X As Integer, Y As Integer, Width As Integer, Height As Integer, Key As String, Column As Integer) +'' {@since 3.19} +'' +'' This event is raised to filter a specific item. +'' +'' Stop the event to prevent the item from being visible. + +Event Filter(Key As String) + + Static Private $iNoEvent As Integer Private $hView As GridView @@ -1129,6 +1138,7 @@ Public Sub _EnsureVisible(hItem As _TreeView_Item, Optional bChild As Boolean) Dim iRow As Integer + If Not hItem.Visible Then Return SetItemVisible(hItem) iRow = _ItemToRow(hItem) @@ -1948,3 +1958,24 @@ Public Sub UpdateSpan_Timer() End +'' @{since 3.19} +'' +'' Filter the items according to the [../.filter] event. +'' +'' You must call this method as soon as the filtering state changes. + +Public Sub Filter() + + Dim hItem As _TreeView_Item + Dim bCancel As Boolean + + If Not Object.CanRaise(Me, "Filter") Then Return + + _Begin() + For Each hItem In $cItem + bCancel = Raise Filter(hItem.Key) + hItem.Visible = Not bCancel + Next + _End() + +End diff --git a/comp/src/gb.gui.base/.src/TreeView/_TreeView_Item.class b/comp/src/gb.gui.base/.src/TreeView/_TreeView_Item.class index 6f4984781..5dc20ec3d 100644 --- a/comp/src/gb.gui.base/.src/TreeView/_TreeView_Item.class +++ b/comp/src/gb.gui.base/.src/TreeView/_TreeView_Item.class @@ -56,6 +56,13 @@ Property Tag As Variant Property Read Depth As Integer +'' @{since 3.19} +'' +'' Return or set if the item is visible. + +Property Visible As Boolean + + Private $sKey As String Private $sParent As String Private $sText As String @@ -68,6 +75,7 @@ Private $iBg As Integer = Color.Default Private $iFg As Integer = Color.Default Private $hFont As Font Private $vTag As Variant +Private $bHidden As Boolean Private $aChildren As String[] Private $aText As String[] @@ -383,6 +391,7 @@ Public Sub _GetHeight() As Integer Dim PH As Integer Dim hFont As Font + If $bHidden Then Return 0 If $H > 0 Then Return $H hFont = $hFont @@ -691,3 +700,26 @@ Private Sub Span_Write(Value As Boolean) GetTree()._UpdateSpan() End + +Private Function Visible_Read() As Boolean + + Return Not $bHidden + +End + +Private Sub Visible_Write(Value As Boolean) + + Dim hTree As _TreeView + + If $bHidden <> Value Then Return + + $bHidden = Not Value + + hTree = GetTree() + hTree._UpdateItemHeight(Me) + + If $bExpanded Then Expanded_Write(False) + + hTree._RefreshView + +End