@@ -218,15 +218,35 @@ def display_VPK(self):
218
218
219
219
def search_files (self , event = None ):
220
220
"""
221
- Search for files in the Treeview based on the entry text.
221
+ Display only files in the Treeview that contain the search text.
222
222
"""
223
223
search_text = self .search_entry .get ().lower ()
224
224
if search_text :
225
- for item in self .tree .get_children ():
226
- if search_text in self .tree .item (item , "text" ).lower ():
227
- self .tree .selection_set (item )
228
- self .tree .focus (item )
229
- self .tree .see (item )
225
+ self .clear_selections () # Clear previous selections
226
+ self .search_tree (self .tree .get_children (), search_text )
230
227
else :
231
- for item in self .tree .get_children ():
232
- self .tree .selection_remove (item )
228
+ self .clear_selections () # Clear selections if search text is empty
229
+
230
+ def search_tree (self , items , search_text ):
231
+ """
232
+ Recursively search through the tree and select items containing the search text.
233
+
234
+ Args:
235
+ items (list): A list of items in the tree.
236
+ search_text (str): The text to search for.
237
+ """
238
+ for item in items :
239
+ item_text = self .tree .item (item , "text" ).lower ()
240
+ if search_text in item_text :
241
+ self .tree .selection_add (item )
242
+ self .tree .focus (item )
243
+ self .tree .see (item )
244
+ self .search_tree (self .tree .get_children (item ), search_text ) # Recursively search subitems
245
+
246
+ def clear_selections (self ):
247
+ """
248
+ Clear all selections in the Treeview.
249
+ """
250
+ for item in self .tree .selection ():
251
+ self .tree .selection_remove (item )
252
+
0 commit comments