From 76e2d0914cede0a8ac11e4c74b9837aad312de1b Mon Sep 17 00:00:00 2001 From: rdbende Date: Sun, 7 Jan 2024 13:25:31 +0100 Subject: [PATCH] Always show the filter sidebar on desktop --- cozy/ui/headerbar.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/cozy/ui/headerbar.py b/cozy/ui/headerbar.py index f5a01e21..7bc71f24 100644 --- a/cozy/ui/headerbar.py +++ b/cozy/ui/headerbar.py @@ -6,7 +6,7 @@ from cozy.ui.widgets.progress_popover import ProgressPopover from cozy.view_model.headerbar_view_model import HeaderbarViewModel, HeaderBarState -from gi.repository import Adw, Gtk +from gi.repository import Adw, Gtk, GObject log = logging.getLogger("Headerbar") @@ -48,6 +48,8 @@ def __init__(self, main_window_builder: Gtk.Builder): self._connect_view_model() self._connect_widgets() + self._set_show_sidebar_button_visible() + def _connect_view_model(self): self._headerbar_view_model.bind_to("state", self._on_state_changed) self._headerbar_view_model.bind_to("work_progress", self._on_work_progress_changed) @@ -58,19 +60,39 @@ def _connect_widgets(self): self.split_view.connect("notify::show-sidebar", self._on_sidebar_toggle) self.show_sidebar_button.connect("notify::active", self._on_sidebar_toggle) self.mobile_view_switcher.connect("notify::reveal", self._on_mobile_view) - self.sort_stack.connect("notify::visible-child", self._on_sort_stack_changed) + self.sort_stack.connect("notify::visible-child", self._set_show_sidebar_button_visible) + + self.mobile_view_switcher.bind_property( + "reveal", self.split_view, "collapsed", GObject.BindingFlags.SYNC_CREATE + ) - def _on_sort_stack_changed(self, widget, _): - page = widget.props.visible_child_name + def _on_mobile(self) -> bool: + return self.mobile_view_switcher.props.reveal - self.show_sidebar_button.set_visible(page != "recent") + def _set_show_sidebar_button_visible(self, *_): + page = self.sort_stack.props.visible_child_name + + if not self._on_mobile(): + self.show_sidebar_button.set_visible(False) + self.split_view.set_collapsed(False) + self.split_view.set_show_sidebar(page != "recent") + return + + if self.mobile_view_switcher.props.reveal: + self.show_sidebar_button.set_visible(page != "recent") + else: + self.show_sidebar_button.set_visible(False) def _on_mobile_view(self, widget, _): + page = self.sort_stack.props.visible_child_name + if widget.props.reveal: self.headerbar.set_title_widget(Adw.WindowTitle(title="Cozy")) else: self.headerbar.set_title_widget(self.view_switcher) + self._set_show_sidebar_button_visible() + def _on_sidebar_toggle(self, widget, param): show_sidebar = widget.get_property(param.name)