[gnome-games/wip/exalm/platform-preferences: 8/8] preferences-window: Add pages programmatically



commit e17017e9363530a64ca1f33b0b9ca5da2071abed
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Sep 19 22:43:55 2018 +0500

    preferences-window: Add pages programmatically
    
    Since platforms will do this, it makes sense to do it for fixed pages as
    well.

 data/ui/preferences-window.ui  | 28 ----------------------------
 src/ui/preferences-window.vala | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 28 deletions(-)
---
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 3e10d978..77bc5b05 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -84,35 +84,7 @@
               <object class="GtkStack" id="stack">
                 <property name="visible">True</property>
                 <property name="expand">True</property>
-                <property name="visible-child">video_page</property>
                 <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
-                <child>
-                  <object class="GamesPreferencesPageVideo" id="video_page">
-                    <property name="visible">True</property>
-                  </object>
-                  <packing>
-                    <property name="name">video</property>
-                    <property name="title" translatable="yes">Video</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GamesPreferencesPageControllers" id="controllers_page">
-                    <property name="visible">True</property>
-                  </object>
-                  <packing>
-                    <property name="name">controllers</property>
-                    <property name="title" translatable="yes">Controllers</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GamesPreferencesPagePlugins" id="plugins_page">
-                    <property name="visible">True</property>
-                  </object>
-                  <packing>
-                    <property name="name">plugins</property>
-                    <property name="title" translatable="yes">Extensions</property>
-                  </packing>
-                </child>
               </object>
             </child>
           </object>
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 54d86c48..13b35c47 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -16,6 +16,8 @@ private class Games.PreferencesWindow : Gtk.Window {
        private Gtk.Box content_box;
        [GtkChild]
        private Gtk.Stack stack;
+       [GtkChild]
+       private Gtk.StackSidebar sidebar;
 
        private PreferencesSubpage _subpage;
        public PreferencesSubpage subpage {
@@ -49,6 +51,8 @@ private class Games.PreferencesWindow : Gtk.Window {
                }
        }
 
+       private PreferencesPage[] pages;
+
        // The previous subpage instance must be kept around during the transition
        private PreferencesSubpage previous_subpage;
 
@@ -56,10 +60,24 @@ private class Games.PreferencesWindow : Gtk.Window {
        private Binding selection_mode_binding;
 
        public PreferencesWindow () {
+               build_sidebar ();
+
                stack.notify["visible-child-name"].connect (visible_child_changed);
                visible_child_changed ();
        }
 
+       private void build_sidebar () {
+               pages = {};
+               pages += new PreferencesPageVideo ();
+               pages += new PreferencesPageControllers ();
+               pages += new PreferencesPagePlugins ();
+
+               foreach (var page in pages)
+                       stack.add_with_properties (page, "title", page.title, null);
+
+               sidebar.stack = stack;
+       }
+
        private void visible_child_changed () {
                var page = stack.visible_child as PreferencesPage;
                if (page == null) {


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