From fe9effe41f8f51ffa9c5e18b631d523a2dbd8bd3 Mon Sep 17 00:00:00 2001 From: heliguy4599 Date: Mon, 9 Oct 2023 04:33:29 -0400 Subject: [PATCH] Add sorting to left over data window --- src/orphans.blp | 20 +++++++++++++++----- src/orphans_window.py | 12 +++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/orphans.blp b/src/orphans.blp index 8b11efe..2e556a0 100644 --- a/src/orphans.blp +++ b/src/orphans.blp @@ -8,11 +8,21 @@ template OrphansWindow : Adw.Window { Adw.ToolbarView main_toolbar_view { [top] HeaderBar header_bar { - // [start] - // Button refresh_button { - // icon-name: "view-refresh-symbolic"; - // tooltip-text: _("Refresh the List of Installed Apps"); - // } + [start] + ToggleButton search_button { + icon-name: "system-search-symbolic"; + tooltip-text: _("Search for an Installed App"); + } + } + [top] + SearchBar search_bar { + search-mode-enabled: bind-property search_button.active bidirectional; + key-capture-widget: OrphansWindow; + Adw.Clamp{ + maximum-size: 577; + hexpand: true; + SearchEntry search_entry {} + } } content: Adw.ToastOverlay toast_overlay { diff --git a/src/orphans_window.py b/src/orphans_window.py index ecf87cd..ee92b1f 100644 --- a/src/orphans_window.py +++ b/src/orphans_window.py @@ -17,6 +17,8 @@ class OrphansWindow(Adw.Window): main_stack = Gtk.Template.Child() no_data = Gtk.Template.Child() action_bar = Gtk.Template.Child() + search_bar = Gtk.Template.Child() + search_entry = Gtk.Template.Child() window_title = _("Manage Leftover Data") host_home = str(pathlib.Path.home()) @@ -210,6 +212,10 @@ class OrphansWindow(Adw.Window): self.main_stack.set_visible_child(self.no_data) self.action_bar.set_visible(False) + def filter_func(self, row): + if (self.search_entry.get_text().lower() in row.get_title().lower()): + return True + def __init__(self, main_window, **kwargs): super().__init__(**kwargs) self.my_utils = myUtils(self) # Access common utils and set the window to this window @@ -234,4 +240,8 @@ class OrphansWindow(Adw.Window): self.install_button.set_visible(False) self.trash_button.connect("clicked", self.trashHandler) self.select_all_button.connect("toggled", self.selectAllHandler) - self.main_overlay.add_overlay(self.progress_bar) \ No newline at end of file + self.main_overlay.add_overlay(self.progress_bar) + + self.list_of_data.set_filter_func(self.filter_func) + self.search_entry.connect("search-changed", lambda *_: self.list_of_data.invalidate_filter()) + self.search_bar.connect_entry(self.search_entry) \ No newline at end of file