[gnome-games/wip/exalm/buildable: 2/2] preferences-page: Add template



commit 9a3df109c81b10fe6e560720e836d7e80fb1c269
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Oct 14 17:19:09 2018 +0500

    preferences-page: Add template
    
    Move common parts from individual preferences pages to PreferencesPage and
    implement Gtk.Buildable to make it possible to add other children to it.

 data/org.gnome.Games.gresource.xml      |   1 +
 data/ui/preferences-page-controllers.ui | 103 ++++++++++++--------------------
 data/ui/preferences-page-plugins.ui     |  35 ++---------
 data/ui/preferences-page-video.ui       |  57 +++++-------------
 data/ui/preferences-page.ui             |  33 ++++++++++
 src/ui/preferences-page.vala            |  15 ++++-
 6 files changed, 105 insertions(+), 139 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index b9f080cb..3ba283c0 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -30,6 +30,7 @@
     <file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
     <file preprocess="xml-stripblanks">ui/media-selector.ui</file>
     <file preprocess="xml-stripblanks">ui/platform-list-item.ui</file>
+    <file preprocess="xml-stripblanks">ui/preferences-page.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-controllers.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
diff --git a/data/ui/preferences-page-controllers.ui b/data/ui/preferences-page-controllers.ui
index 256b76e5..e79b321a 100644
--- a/data/ui/preferences-page-controllers.ui
+++ b/data/ui/preferences-page-controllers.ui
@@ -3,74 +3,47 @@
   <template class="GamesPreferencesPageControllers" parent="GamesPreferencesPage">
     <property name="visible">True</property>
     <child>
-      <object class="GtkScrolledWindow">
+      <object class="GtkLabel" id="gamepads_label">
         <property name="visible">True</property>
-        <property name="hscrollbar-policy">never</property>
+        <property name="halign">start</property>
+        <property name="label" translatable="yes">Gamepads</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+        </attributes>
+      </object>
+    </child>
+    <child>
+      <object class="GtkFrame" id="gamepads_frame">
+        <property name="visible">True</property>
+        <property name="shadow_type">in</property>
+        <child>
+          <object class="GtkListBox" id="gamepads_list_box">
+            <property name="visible">True</property>
+            <property name="selection_mode">none</property>
+            <signal name="row-activated" handler="gamepads_list_box_row_activated"/>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <property name="label" translatable="yes">Keyboard</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+        </attributes>
+      </object>
+    </child>
+    <child>
+      <object class="GtkFrame">
+        <property name="visible">True</property>
+        <property name="shadow_type">in</property>
         <child>
-          <object class="GtkViewport">
+          <object class="GtkListBox" id="keyboard_list_box">
             <property name="visible">True</property>
-            <child>
-              <object class="HdyColumn">
-                <property name="visible">True</property>
-                <property name="expand">True</property>
-                <property name="maximum_width">600</property>
-                <property name="linear-growth-width">300</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
-                    <property name="margin">12</property>
-                    <property name="spacing">12</property>
-                    <child>
-                      <object class="GtkLabel" id="gamepads_label">
-                        <property name="visible">True</property>
-                        <property name="halign">start</property>
-                        <property name="label" translatable="yes">Gamepads</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkFrame" id="gamepads_frame">
-                        <property name="visible">True</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="gamepads_list_box">
-                            <property name="visible">True</property>
-                            <property name="selection_mode">none</property>
-                            <signal name="row-activated" handler="gamepads_list_box_row_activated"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">True</property>
-                        <property name="halign">start</property>
-                        <property name="label" translatable="yes">Keyboard</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="visible">True</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="keyboard_list_box">
-                            <property name="visible">True</property>
-                            <property name="selection_mode">none</property>
-                            <signal name="row-activated" handler="keyboard_list_box_row_activated"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
+            <property name="selection_mode">none</property>
+            <signal name="row-activated" handler="keyboard_list_box_row_activated"/>
           </object>
         </child>
       </object>
diff --git a/data/ui/preferences-page-plugins.ui b/data/ui/preferences-page-plugins.ui
index d768da1c..ff16fd4b 100644
--- a/data/ui/preferences-page-plugins.ui
+++ b/data/ui/preferences-page-plugins.ui
@@ -4,40 +4,13 @@
   <template class="GamesPreferencesPagePlugins" parent="GamesPreferencesPage">
     <property name="visible">True</property>
     <child>
-      <object class="GtkScrolledWindow" id="plugins">
+      <object class="GtkFrame">
         <property name="visible">true</property>
-        <property name="hscrollbar-policy">never</property>
+        <property name="shadow-type">in</property>
         <child>
-          <object class="GtkViewport">
+          <object class="GtkListBox" id="list_box">
+            <property name="selection-mode">none</property>
             <property name="visible">true</property>
-            <child>
-              <object class="HdyColumn">
-                <property name="visible">True</property>
-                <property name="expand">True</property>
-                <property name="maximum_width">600</property>
-                <property name="linear-growth-width">300</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
-                    <property name="margin">12</property>
-                    <property name="spacing">12</property>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="visible">true</property>
-                        <property name="shadow-type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="list_box">
-                            <property name="selection-mode">none</property>
-                            <property name="visible">true</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
           </object>
         </child>
       </object>
diff --git a/data/ui/preferences-page-video.ui b/data/ui/preferences-page-video.ui
index ccd9b01a..11751faf 100644
--- a/data/ui/preferences-page-video.ui
+++ b/data/ui/preferences-page-video.ui
@@ -3,51 +3,24 @@
   <template class="GamesPreferencesPageVideo" parent="GamesPreferencesPage">
     <property name="visible">True</property>
     <child>
-      <object class="GtkScrolledWindow">
+      <object class="GtkLabel">
         <property name="visible">True</property>
-        <property name="hscrollbar-policy">never</property>
+        <property name="halign">start</property>
+        <property name="label" translatable="yes">Filter</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+        </attributes>
+      </object>
+    </child>
+    <child>
+      <object class="GtkFrame">
+        <property name="visible">True</property>
+        <property name="shadow_type">in</property>
         <child>
-          <object class="GtkViewport">
+          <object class="GtkListBox" id="filter_list_box">
             <property name="visible">True</property>
-            <child>
-              <object class="HdyColumn">
-                <property name="visible">True</property>
-                <property name="expand">True</property>
-                <property name="maximum_width">600</property>
-                <property name="linear-growth-width">300</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
-                    <property name="margin">12</property>
-                    <property name="spacing">12</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">True</property>
-                        <property name="halign">start</property>
-                        <property name="label" translatable="yes">Filter</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="visible">True</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="filter_list_box">
-                            <property name="visible">True</property>
-                            <property name="selection_mode">none</property>
-                            <signal name="row-activated" handler="filter_list_box_row_activated"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
+            <property name="selection_mode">none</property>
+            <signal name="row-activated" handler="filter_list_box_row_activated"/>
           </object>
         </child>
       </object>
diff --git a/data/ui/preferences-page.ui b/data/ui/preferences-page.ui
new file mode 100644
index 00000000..34cb1aff
--- /dev/null
+++ b/data/ui/preferences-page.ui
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GamesPreferencesPage" parent="GtkBin">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">True</property>
+        <property name="hscrollbar-policy">never</property>
+        <child>
+          <object class="GtkViewport">
+            <property name="visible">True</property>
+            <child>
+              <object class="HdyColumn">
+                <property name="visible">True</property>
+                <property name="expand">True</property>
+                <property name="maximum_width">600</property>
+                <property name="linear-growth-width">300</property>
+                <child>
+                  <object class="GtkBox" id="box">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="margin">12</property>
+                    <property name="spacing">12</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/ui/preferences-page.vala b/src/ui/preferences-page.vala
index c92b77d8..bc6e1ad9 100644
--- a/src/ui/preferences-page.vala
+++ b/src/ui/preferences-page.vala
@@ -1,5 +1,18 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-private class Games.PreferencesPage: Gtk.Bin {
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page.ui")]
+private class Games.PreferencesPage: Gtk.Bin, Gtk.Buildable {
        public PreferencesSubpage subpage { get; protected set; }
+
+       [GtkChild]
+       private Gtk.Box box;
+
+       public void add_child (Gtk.Builder builder, Object child, string? type) {
+               var widget = child as Gtk.Widget;
+
+               if (box != null)
+                       box.add (widget);
+               else
+                       add (widget);
+       }
 }


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