[gnome-games/wip/exalm/libhandy2: 12/12] preferences-window: Manage window buttons via HdyHeaderGroup



commit 20a7a7042e467157f903d2e7c0a799879106a31a
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Oct 21 03:00:27 2018 +0500

    preferences-window: Manage window buttons via HdyHeaderGroup

 data/ui/preferences-window.ui  |  8 +++++++-
 src/main.vala                  |  1 +
 src/ui/preferences-window.vala | 16 +++++++++++++++-
 3 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index e2e52bcc..e3fb9afd 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -25,7 +25,7 @@
                     <property name="name">left_header_bar</property>
                     <property name="visible">True</property>
                     <property name="title" translatable="yes">Preferences</property>
-                    <property name="show-close-button">False</property>
+                    <property name="show-close-button">True</property>
                   </object>
                 </child>
                 <child>
@@ -148,4 +148,10 @@
       <widget name="stack"/>
     </widgets>
   </object>
+  <object class="HdyHeaderGroup" id="header_group">
+    <headerbars>
+      <headerbar name="left_header_bar"/>
+      <headerbar name="right_header_bar"/>
+    </headerbars>
+  </object>
 </interface>
diff --git a/src/main.vala b/src/main.vala
index 413171b0..3e5e23f0 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -8,6 +8,7 @@ int main (string[] args) {
        Grl.init (ref args);
 
        typeof (Hdy.Column).ensure ();
+       typeof (Hdy.HeaderGroup).ensure ();
        typeof (Hdy.Leaflet).ensure ();
        typeof (Hdy.TitleBar).ensure ();
 
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 7d24e394..453ff9bf 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -20,6 +20,8 @@ private class Games.PreferencesWindow : Gtk.Window {
        private PreferencesSidebar sidebar;
        [GtkChild]
        private Gtk.Stack stack;
+       [GtkChild]
+       private Hdy.HeaderGroup header_group;
 
        [GtkChild]
        private Gtk.Button back_button;
@@ -73,6 +75,7 @@ private class Games.PreferencesWindow : Gtk.Window {
        private void sidebar_row_selected () {
                content_box.visible_child = stack;
                titlebar_box.visible_child = right_header_bar;
+               update_header_group ();
 
                update_ui ();
        }
@@ -106,13 +109,14 @@ private class Games.PreferencesWindow : Gtk.Window {
        private void on_back_clicked () {
                content_box.visible_child = sidebar;
                titlebar_box.visible_child = left_header_bar;
+               update_header_group ();
        }
 
        [GtkCallback]
        private void on_folded_changed (Object object, ParamSpec paramSpec) {
                var folded = content_box.folded;
 
-               left_header_bar.show_close_button = folded;
+               update_header_group ();
                back_button.visible = folded;
                sidebar.show_selection = !folded;
 
@@ -121,4 +125,14 @@ private class Games.PreferencesWindow : Gtk.Window {
                else
                        stack.transition_type = Gtk.StackTransitionType.CROSSFADE;
        }
+
+       private void update_header_group () {
+               var folded = content_box.folded;
+               var visible_header_bar = titlebar_box.visible_child as Gtk.HeaderBar;
+
+               if (folded)
+                       header_group.focus = visible_header_bar;
+               else
+                       header_group.focus = null;
+       }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]