@@ -711,7 +711,7 @@ def get_tree_model(self):
711
711
712
712
713
713
def has_matching_children (self ,task :Task ):
714
- return any (self .task_filter .do_match (c ) for c in task .children )
714
+ return any (self .task_filter .match (c ) for c in task .children )
715
715
716
716
717
717
def set_filter (self ,new_filter :Gtk .Filter ):
@@ -738,13 +738,13 @@ def _find_root_tasks(self) -> None:
738
738
739
739
740
740
def _should_be_root_item (self ,t :Task ):
741
- if not self .task_filter .do_match (t ):
741
+ if not self .task_filter .match (t ):
742
742
return False
743
- return t .parent is None or not self .task_filter .do_match (t .parent )
743
+ return t .parent is None or not self .task_filter .match (t .parent )
744
744
745
745
746
746
def update_position_of (self ,t :Task ):
747
- if not self .task_filter .do_match (t ):
747
+ if not self .task_filter .match (t ):
748
748
self .remove (t )
749
749
return
750
750
if not self ._in_the_right_model (t ):
@@ -764,7 +764,7 @@ def _in_the_right_model(self,t:Task):
764
764
765
765
if current_model is None and correct_model is None :
766
766
return True
767
- if current_model == correct_model :
767
+ if current_model is correct_model :
768
768
assert correct_model is not None
769
769
pos = correct_model .find (t )
770
770
return pos [0 ]
@@ -793,7 +793,7 @@ def remove(self,task:Task):
793
793
794
794
def _get_correct_containing_model (self ,task :Task ) -> Optional [Gio .ListStore ]:
795
795
"""Return the ListStore that should contain the given task matching the filter."""
796
- if task .parent is None or not self .task_filter .do_match (task .parent ):
796
+ if task .parent is None or not self .task_filter .match (task .parent ):
797
797
return self .root_model
798
798
return self .tid_to_subtask_model .get (task .parent .id )
799
799
@@ -805,19 +805,21 @@ def _get_containing_model(self,task:Task) -> Optional[Gio.ListStore]:
805
805
806
806
def _model_expand (self , item ):
807
807
"""Return a ListStore with the matching children of the given task."""
808
- model = Gio .ListStore .new (Task )
809
-
810
808
if type (item ) == Gtk .TreeListRow :
811
809
item = item .get_item ()
810
+ if item .id not in self .tid_to_subtask_model :
811
+ self .tid_to_subtask_model [item .id ] = self ._create_model_for_children (item )
812
+ model = self .tid_to_subtask_model [item .id ]
813
+ return Gtk .TreeListModel .new (model , False , False , self ._model_expand )
814
+
812
815
816
+ def _create_model_for_children (self ,item ):
817
+ model = Gio .ListStore .new (Task )
813
818
for child in item .children :
814
- if self .task_filter is None or self . task_filter . do_match (child ):
819
+ if self .task_filter . match (child ):
815
820
model .append (child )
816
821
self .tid_to_containing_model [child .id ] = model
817
-
818
- self .tid_to_subtask_model [item .id ] = model
819
- return Gtk .TreeListModel .new (model , False , False , self ._model_expand )
820
-
822
+ return model
821
823
822
824
823
825
class TaskStore (BaseStore [Task ]):
@@ -831,8 +833,10 @@ class TaskStore(BaseStore[Task]):
831
833
def __init__ (self ) -> None :
832
834
super ().__init__ ()
833
835
834
- self .model = Gio .ListStore .new (Task )
835
836
self .managers : list [FilteredTaskTreeManager ] = []
837
+ self .always_true_filter = Gtk .CustomFilter ()
838
+ self .always_true_filter .set_filter_func (lambda x : True )
839
+ self .tree_model , manager = self .get_filtered_tree_model (self .always_true_filter )
836
840
837
841
838
842
def get_filtered_tree_model (self ,task_filter : Optional [Gtk .Filter ]):
0 commit comments