Skip to content

Commit

Permalink
window: Move search bar to main window
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEvilSkeleton committed Jan 8, 2025
1 parent a4b13ff commit b927540
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
6 changes: 0 additions & 6 deletions bottles/frontend/ui/overview-list-page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ template $BottlesOverviewListPage: Adw.Bin {
vexpand: true;
orientation: vertical;

SearchBar search_bar {
SearchEntry entry_search {
placeholder-text: _("Search your bottles…");
}
}

Adw.PreferencesPage pref_page {
Adw.PreferencesGroup group_bottles {
ListBox list_bottles {
Expand Down
6 changes: 5 additions & 1 deletion bottles/frontend/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ template $BottlesWindow: Adw.ApplicationWindow {
}
}

SearchBar searchbar {}
SearchBar search_bar {
SearchEntry entry_search {
placeholder-text: _("Search your bottles…");
}
}

Adw.ViewStack stack_main {
vexpand: true;
Expand Down
12 changes: 0 additions & 12 deletions bottles/frontend/views/overview_list_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ class BottlesOverviewListPage(Adw.Bin):
pref_page = Gtk.Template.Child()
bottle_status = Gtk.Template.Child()
btn_create = Gtk.Template.Child()
entry_search = Gtk.Template.Child()
search_bar = Gtk.Template.Child()
no_bottles_found = Gtk.Template.Child()

# endregion
Expand All @@ -151,7 +149,6 @@ def __init__(self, window, arg_bottle=None, **kwargs):

# connect signals
self.btn_create.connect("clicked", self.window.show_add_view)
self.entry_search.connect("changed", self.__search_bottles)

# backend signals
SignalManager.connect(
Expand All @@ -162,15 +159,6 @@ def __init__(self, window, arg_bottle=None, **kwargs):

self.update_bottles_list()

def __search_bottles(self, widget, event=None, data=None):
"""
This function search in the list of bottles the
text written in the search entry.
"""
terms = widget.get_text()
self.list_bottles.set_filter_func(self.__filter_bottles, terms)
self.list_steam.set_filter_func(self.__filter_bottles, terms)

@staticmethod
def __filter_bottles(row, terms=None):
text = row.get_title().lower()
Expand Down
21 changes: 19 additions & 2 deletions bottles/frontend/windows/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class BottlesWindow(Adw.ApplicationWindow):
view_switcher_bar = Gtk.Template.Child()
main_leaf = Gtk.Template.Child()
toasts = Gtk.Template.Child()
entry_search = Gtk.Template.Child()
search_bar = Gtk.Template.Child()
# endregion

# Common variables
Expand Down Expand Up @@ -144,6 +146,7 @@ def response(dialog, response, *args):
self.btn_add.connect("clicked", self.show_add_view)
self.btn_noconnection.connect("clicked", self.check_for_connection)
self.stack_main.connect("notify::visible-child", self.__on_page_changed)
self.entry_search.connect("changed", self.__search_bottles)

# backend signal handlers
self.task_syncer = TaskSyncer(self)
Expand Down Expand Up @@ -238,10 +241,10 @@ def set_manager(result: Manager, error=None):
child=self.page_library, name="page_library", title=_("Library")
).set_icon_name("library-symbolic")

self.page_list.search_bar.set_key_capture_widget(self)
self.search_bar.set_key_capture_widget(self)
self.btn_search.bind_property(
"active",
self.page_list.search_bar,
self.search_bar,
"search-mode-enabled",
GObject.BindingFlags.BIDIRECTIONAL,
)
Expand Down Expand Up @@ -296,6 +299,20 @@ def get_manager():

self.check_crash_log()

def __search_bottles(self, widget, event=None, data=None):
"""
This function search in the list of bottles the
text written in the search entry.
"""
terms = widget.get_text()
self.page_list.list_bottles.set_filter_func(self.__filter_bottles, terms)
self.page_list.list_steam.set_filter_func(self.__filter_bottles, terms)

@staticmethod
def __filter_bottles(row, terms=None):
text = row.get_title().lower()
return terms.lower() in text

def send_notification(self, title, text, image="", ignore_user=False):
"""
This method is used to send a notification to the user using
Expand Down

0 comments on commit b927540

Please sign in to comment.