Skip to content

Commit

Permalink
Filter by text or notes
Browse files Browse the repository at this point in the history
Signed-off-by: Simó Albert i Beltran <[email protected]>
  • Loading branch information
sim6 committed May 25, 2024
1 parent 5adbd62 commit 0c31b58
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions errands/widgets/base/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from errands.widgets.base.base_page_name import BasePageName
from errands.widgets.page_task import PageTask
from errands.widgets.shared.components.boxes import ErrandsBox
from errands.widgets.shared.components.entries import ErrandsEntryRow
from errands.widgets.shared.components.toolbar_view import ErrandsToolbarView
from errands.widgets.task_data_list_view import TaskDataListView

Expand All @@ -19,6 +20,7 @@ def __init__(self):
super().__init__()
Log.debug(f"{self.title} Page: Load")
setattr(State, f"{self.page_name}_page", self)
self.filter_text = ""
self.__build_ui()
self.update_ui()

Expand All @@ -35,9 +37,14 @@ def __build_ui(self):

# Task List
self.task_list = Gio.ListStore(item_type=TaskDataListView)
self.task_list_filter = Gtk.CustomFilter.new(self.filter, None)
task_list_filter_model = Gtk.FilterListModel(
model=self.task_list, filter=self.task_list_filter
)
self.task_list_sorter = Gtk.CustomSorter.new(self.sort)
task_list_sort_model = Gtk.SortListModel(model=self.task_list)
task_list_sort_model.set_sorter(self.task_list_sorter)
task_list_sort_model = Gtk.SortListModel(
model=task_list_filter_model, sorter=self.task_list_sorter
)
factory = Gtk.SignalListItemFactory()
factory.connect(
"setup", lambda factory, list_item: list_item.set_child(PageTask(self))
Expand Down Expand Up @@ -73,7 +80,22 @@ def __build_ui(self):
self.set_child(
ErrandsToolbarView(
top_bars=[
Adw.HeaderBar(title_widget=Adw.WindowTitle(title=_(self.title)))
Adw.HeaderBar(title_widget=Adw.WindowTitle(title=_(self.title))),
Adw.Clamp(
maximum_size=1000,
tightening_threshold=300,
child=ErrandsEntryRow(
margin_top=3,
margin_bottom=3,
margin_end=12,
margin_start=12,
title=_("Filter by text or notes"),
activatable=False,
height_request=60,
css_classes=["card"],
on_entry_activated=self._on_filter_text_entry,
),
),
],
content=ErrandsBox(
orientation=Gtk.Orientation.VERTICAL,
Expand Down Expand Up @@ -134,5 +156,12 @@ def update_ui(self):
self.task_list_sorter.changed(Gtk.SorterChange.DIFFERENT)
self.update_status()

def _on_filter_text_entry(self, entry: Adw.EntryRow) -> None:
self.filter_text = entry.get_text().strip()
self.task_list_filter.changed(Gtk.FilterChange.DIFFERENT)

def filter(self, task, user_data) -> bool:
return self.filter_text in task.text or self.filter_text in task.notes

def sort(self, task1, task2, user_data) -> GObject.TYPE_INT:
raise NotImplementedError

0 comments on commit 0c31b58

Please sign in to comment.