diff --git a/bureau/content_page.py b/bureau/content_page.py index aa22fea..2758647 100644 --- a/bureau/content_page.py +++ b/bureau/content_page.py @@ -21,18 +21,36 @@ # SOFTWARE. # # SPDX-License-Identifier: MIT - - -from gi.repository import Gtk +import inject +from gi.repository import Gtk, GObject, Adw from bureau.components.sidebar.column import SidebarColumn +from bureau.providers.app_state import AppStateProvider @Gtk.Template(resource_path='/com/tenderowl/bureau/ui/content_page.ui') class ContentPage(Gtk.Box): __gtype_name__ = 'ContentPage' + outer: Adw.OverlaySplitView = Gtk.Template.Child() sidebar_column: SidebarColumn = Gtk.Template.Child() + toggle_sidebar_btn: Gtk.ToggleButton = Gtk.Template.Child() + + app_state: AppStateProvider - def __init__(self, **kwargs): + @inject.autoparams() + def __init__(self, app_state: AppStateProvider, **kwargs): super().__init__(**kwargs) + self.app_state = app_state + + self.app_state.bind_property('sidebar_collapsed', self.outer, 'collapsed', GObject.BindingFlags.BIDIRECTIONAL) + self.toggle_sidebar_btn.bind_property('visible', self.app_state, 'sidebar_collapsed', + GObject.BindingFlags.BIDIRECTIONAL) + self.toggle_sidebar_btn.bind_property('active', self.outer, 'show-sidebar', GObject.BindingFlags.BIDIRECTIONAL) + # self.sidebar_column.connect('notify::show-sidebar', self._on_sidebar_collapsed) + + # @Gtk.Template.Callback() + # def _on_sidebar_collapsed(self, state: bool): + # print('Collapsed ', state) + # self.app_state.sidebar_collapsed = state + # self.toggle_sidebar_btn.set_visible(state) diff --git a/bureau/main.py b/bureau/main.py index d631c7b..e399356 100644 --- a/bureau/main.py +++ b/bureau/main.py @@ -35,12 +35,14 @@ from .window import BureauWindow from bureau.providers.account import AccountProvider +from bureau.providers.app_state import AppStateProvider from bureau.providers.imap import ImapProvider def configure_providers(binder: inject.Binder): binder.bind(ImapProvider, ImapProvider('imap.yandex.ru')) binder.bind(AccountProvider, AccountProvider()) + binder.bind(AppStateProvider, AppStateProvider()) class BureauApplication(Adw.Application): @@ -74,12 +76,12 @@ def do_activate(self): def on_about_action(self, widget, _): """Callback for the app.about action.""" about = Adw.AboutWindow(transient_for=self.props.active_window, - application_name='bureau', + application_name='Bureau', application_icon='com.tenderowl.bureau', developer_name='TenderOwl', version=self.version or '0.1.0', developers=['Andrey Maksimov'], - copyright='© 2023 Andrey Maksimov') + copyright='© 2023 TenderOwl') about.present() def on_preferences_action(self, widget, _): diff --git a/bureau/providers/app_state.py b/bureau/providers/app_state.py new file mode 100644 index 0000000..76eb07b --- /dev/null +++ b/bureau/providers/app_state.py @@ -0,0 +1,17 @@ +from gi.repository import GObject + + +class AppStateProvider(GObject.GObject): + __gtype_name__ = "AppStateProvider" + + # Props + sidebar_collapsed = GObject.Property(type=bool, default=True) + mail_column_collapsed = GObject.Property(type=bool, default=True) + + # Signals + __gsignals__ = { + 'sidebar-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool,)) + } + + def __init__(self): + super().__init__() diff --git a/data/ui/content_page.blp b/data/ui/content_page.blp index 70c7d2c..5a8c366 100644 --- a/data/ui/content_page.blp +++ b/data/ui/content_page.blp @@ -30,7 +30,7 @@ template $ContentPage : Box { Adw.NavigationSplitView inner { min-sidebar-width: 360; - max-sidebar-width: 600; + max-sidebar-width: 500; sidebar-width-fraction: 0.40; sidebar: Adw.NavigationPage { @@ -43,6 +43,12 @@ template $ContentPage : Box { [top] Adw.HeaderBar { show-title: false; + + ToggleButton toggle_sidebar_btn { + icon-name: "sidebar-show-symbolic"; + tooltip-text: "Toggle Sidebar"; + visible: false; + } } } };