[gnome-games/wip/exalm/libhandy2: 26/28] ui: Use HdyTitleBar in preferences window



commit bae2e89d6c65fdae40251235a444c6bbfa0d577c
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Sep 12 14:49:02 2018 +0500

    ui: Use HdyTitleBar in preferences window

 data/ui/preferences-window.ui            | 93 ++++++++++++++++++--------------
 src/main.vala                            |  1 +
 src/ui/preferences-subpage-gamepad.vala  |  5 +-
 src/ui/preferences-subpage-keyboard.vala |  6 ++-
 src/ui/preferences-subpage.vala          |  1 +
 src/ui/preferences-window.vala           |  8 +++
 6 files changed, 69 insertions(+), 45 deletions(-)
---
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index ba96e399..b87914b4 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -8,59 +8,67 @@
     <property name="default-height">500</property>
     <property name="window-position">GTK_WIN_POS_CENTER_ON_PARENT</property>
     <child type="titlebar">
-      <object class="GtkStack" id="titlebar_stack">
+      <object class="HdyTitleBar" id="titlebar">
         <property name="visible">True</property>
-        <property name="transition-type">slide-left-right</property>
-        <property name="transition-duration">250</property>
         <child>
-          <object class="HdyLeaflet" id="titlebar_box">
+          <object class="GtkStack" id="titlebar_stack">
             <property name="visible">True</property>
-            <property name="mode_transition_type">slide</property>
-            <property name="child_transition_type">slide</property>
-            <property name="fold">unfolded</property>
+            <property name="transition-type">slide-left-right</property>
+            <property name="transition-duration">250</property>
             <child>
-              <object class="GtkHeaderBar" id="left_header_bar">
-                <property name="name">left_header_bar</property>
+              <object class="HdyLeaflet" id="titlebar_box">
                 <property name="visible">True</property>
-                <property name="title" translatable="yes">Preferences</property>
-                <property name="show-close-button">False</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkSeparator" id="header_separator">
-                <property name="orientation">vertical</property>
-                <property name="visible">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkHeaderBar" id="right_header_bar">
-                <property name="name">right_header_bar</property>
-                <property name="visible">True</property>
-                <property name="hexpand">True</property>
-                <property name="show-close-button">True</property>
+                <property name="mode_transition_type">slide</property>
+                <property name="child_transition_type">slide</property>
+                <property name="fold">unfolded</property>
                 <child>
-                  <object class="GtkButton" id="back_button">
-                    <property name="visible">False</property>
-                    <signal name="clicked" handler="on_back_clicked"/>
+                  <object class="GtkHeaderBar" id="left_header_bar">
+                    <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>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSeparator" id="header_separator">
+                    <property name="orientation">vertical</property>
+                    <property name="visible">True</property>
                     <style>
-                      <class name="image-button"/>
+                      <class name="sidebar"/>
                     </style>
-                    <child internal-child="accessible">
-                      <object class="AtkObject" id="a11y-back">
-                        <property name="accessible-name" translatable="yes">Back</property>
-                      </object>
-                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkHeaderBar" id="right_header_bar">
+                    <property name="name">right_header_bar</property>
+                    <property name="visible">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="show-close-button">True</property>
                     <child>
-                      <object class="GtkImage" id="back_image">
-                        <property name="visible">True</property>
-                        <property name="icon-name">go-previous-symbolic</property>
-                        <property name="icon-size">1</property>
+                      <object class="GtkButton" id="back_button">
+                        <property name="visible">False</property>
+                        <signal name="clicked" handler="on_back_clicked"/>
+                        <style>
+                          <class name="image-button"/>
+                        </style>
+                        <child internal-child="accessible">
+                          <object class="AtkObject" id="a11y-back">
+                            <property name="accessible-name" translatable="yes">Back</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkImage" id="back_image">
+                            <property name="visible">True</property>
+                            <property name="icon-name">go-previous-symbolic</property>
+                            <property name="icon-size">1</property>
+                          </object>
+                        </child>
                       </object>
+                      <packing>
+                        <property name="pack-type">start</property>
+                      </packing>
                     </child>
                   </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
                 </child>
               </object>
             </child>
@@ -97,6 +105,9 @@
               <object class="GtkSeparator" id="separator">
                 <property name="orientation">vertical</property>
                 <property name="visible">True</property>
+                <style>
+                  <class name="sidebar"/>
+                </style>
               </object>
             </child>
             <child>
diff --git a/src/main.vala b/src/main.vala
index 32b1a032..413171b0 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -9,6 +9,7 @@ int main (string[] args) {
 
        typeof (Hdy.Column).ensure ();
        typeof (Hdy.Leaflet).ensure ();
+       typeof (Hdy.TitleBar).ensure ();
 
        var app = new Games.Application ();
        var result = app.run (args);
diff --git a/src/ui/preferences-subpage-gamepad.vala b/src/ui/preferences-subpage-gamepad.vala
index 5ac7460d..492fdf27 100644
--- a/src/ui/preferences-subpage-gamepad.vala
+++ b/src/ui/preferences-subpage-gamepad.vala
@@ -68,6 +68,7 @@ private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
                        back_button.visible = (state == State.TEST);
                        cancel_button.visible = (state == State.CONFIGURE);
                        header_bar.show_close_button = (state == State.TEST);
+                       request_selection_mode = (state == State.CONFIGURE);
 
                        switch (value) {
                        case State.TEST:
@@ -75,7 +76,6 @@ private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
 
                                /* translators: testing a gamepad, %s is its name */
                                header_bar.title = _("Testing %s").printf (device.get_name ());
-                               header_bar.get_style_context ().remove_class ("selection-mode");
                                gamepad_view_stack.visible_child = tester;
                                action_bar_stack.visible_child = tester_action_bar;
 
@@ -87,7 +87,6 @@ private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
                        case State.CONFIGURE:
                                /* translators: configuring a gamepad, %s is its name */
                                header_bar.title = _("Configuring %s").printf (device.get_name ());
-                               header_bar.get_style_context ().add_class ("selection-mode");
                                gamepad_view_stack.visible_child = mapper;
                                action_bar_stack.visible_child = mapper_action_bar;
 
@@ -107,6 +106,8 @@ private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
                get { return _header_bar; }
        }
 
+       public bool request_selection_mode { get; set; }
+
        [GtkChild]
        private Gtk.Stack gamepad_view_stack;
        [GtkChild]
diff --git a/src/ui/preferences-subpage-keyboard.vala b/src/ui/preferences-subpage-keyboard.vala
index 2a3619c3..5a867446 100644
--- a/src/ui/preferences-subpage-keyboard.vala
+++ b/src/ui/preferences-subpage-keyboard.vala
@@ -59,13 +59,13 @@ private class Games.PreferencesSubpageKeyboard: Gtk.Box, PreferencesSubpage {
                        back_button.visible = (state == State.TEST);
                        cancel_button.visible = (state == State.CONFIGURE);
                        header_bar.show_close_button = (state == State.TEST);
+                       request_selection_mode = (state == State.CONFIGURE);
 
                        switch (value) {
                        case State.TEST:
                                reset_button.set_sensitive (!mapping_manager.is_default ());
 
                                header_bar.title = _("Testing Keyboard");
-                               header_bar.get_style_context ().remove_class ("selection-mode");
                                gamepad_view_stack.visible_child = tester;
                                action_bar_stack.visible_child = tester_action_bar;
 
@@ -76,7 +76,6 @@ private class Games.PreferencesSubpageKeyboard: Gtk.Box, PreferencesSubpage {
                                break;
                        case State.CONFIGURE:
                                header_bar.title = _("Configuring Keyboard");
-                               header_bar.get_style_context ().add_class ("selection-mode");
                                gamepad_view_stack.visible_child = mapper;
                                action_bar_stack.visible_child = mapper_action_bar;
 
@@ -94,6 +93,9 @@ private class Games.PreferencesSubpageKeyboard: Gtk.Box, PreferencesSubpage {
        public Gtk.HeaderBar header_bar {
                get { return _header_bar; }
        }
+
+       public bool request_selection_mode { get; set; }
+
        [GtkChild]
        private Gtk.Stack gamepad_view_stack;
        [GtkChild]
diff --git a/src/ui/preferences-subpage.vala b/src/ui/preferences-subpage.vala
index 64bffcc6..ad70e858 100644
--- a/src/ui/preferences-subpage.vala
+++ b/src/ui/preferences-subpage.vala
@@ -2,4 +2,5 @@
 
 private interface Games.PreferencesSubpage: Gtk.Widget {
        public abstract Gtk.HeaderBar header_bar { get; }
+       public abstract bool request_selection_mode { get; set; }
 }
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index a2442667..e0034b14 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -5,6 +5,8 @@ private class Games.PreferencesWindow : Gtk.Window {
        [GtkChild]
        private Gtk.Stack titlebar_stack;
        [GtkChild]
+       private Hdy.TitleBar titlebar;
+       [GtkChild]
        private Hdy.Leaflet titlebar_box;
        [GtkChild]
        private Gtk.HeaderBar left_header_bar;
@@ -33,6 +35,7 @@ private class Games.PreferencesWindow : Gtk.Window {
                                previous_subpage = subpage;
                                main_stack.visible_child = content_box;
                                titlebar_stack.visible_child = titlebar_box;
+                               selection_mode_binding.unbind ();
                        }
 
                        if (value != null) {
@@ -41,6 +44,10 @@ private class Games.PreferencesWindow : Gtk.Window {
                                main_stack.add (value);
                                main_stack.visible_child = value;
 
+                               selection_mode_binding = value.bind_property ("request-selection-mode",
+                                                                             titlebar, "selection-mode",
+                                                                             BindingFlags.SYNC_CREATE);
+
                                titlebar_stack.add (header_bar);
                                titlebar_stack.visible_child = header_bar;
 
@@ -57,6 +64,7 @@ private class Games.PreferencesWindow : Gtk.Window {
        private PreferencesSubpage previous_subpage;
 
        private Binding subpage_binding;
+       private Binding selection_mode_binding;
 
        public PreferencesWindow () {
                stack.notify["visible-child-name"].connect (visible_child_changed);


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