[gnome-usage] storage-view: Port to Gtk+ composite templates



commit a7a8ae9cc61b50eef7977867332ef429eba8fc55
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Sep 6 13:47:09 2017 +0200

    storage-view: Port to Gtk+ composite templates
    
    It simplifies the StorageView code a lot by decoupling the Gtk+
    specific bits.
    
    In terms of logic, we now switch stack pages to present the
    "loading", "content", and "empty" states. This is simpler than
    the addition and removal of widgets on callbacks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787357

 data/org.gnome.Usage.gresource.xml |    1 +
 data/ui/storage-view.ui            |   82 ++++++++++++++++++++++++++++++++++++
 src/storage-view.vala              |   71 +++++++++----------------------
 3 files changed, 104 insertions(+), 50 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index 0da135d..651b9d4 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -6,5 +6,6 @@
         <file preprocess="xml-stripblanks">ui/header-bar.ui</file>
         <file preprocess="xml-stripblanks">ui/performance-view.ui</file>
         <file preprocess="xml-stripblanks">ui/process-dialog.ui</file>
+        <file preprocess="xml-stripblanks">ui/storage-view.ui</file>
     </gresource>
 </gresources>
diff --git a/data/ui/storage-view.ui b/data/ui/storage-view.ui
new file mode 100644
index 0000000..00b1974
--- /dev/null
+++ b/data/ui/storage-view.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="UsageStorageView" parent="UsageView">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkStack" id="stack">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkSpinner">
+            <property name="visible">True</property>
+            <property name="active">True</property>
+          </object>
+          <packing>
+            <property name="name">spinner</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkPaned" id="paned">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <property name="position">300</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolled_window">
+                    <property name="visible">True</property>
+                    <property name="vexpand">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkRevealer" id="revealer">
+                <property name="visible">True</property>
+                <property name="transition-type">slide-up</property>
+                <property name="transition-duration">400</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="name">content</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="valign">center</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">folder-symbolic</property>
+                <property name="pixel-size">128</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="margin-top">10</property>
+                <property name="label" translatable="yes">No content here</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                  <attribute name="scale" value="1.66"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="name">empty</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+
+  </template>
+</interface>
diff --git a/src/storage-view.vala b/src/storage-view.vala
index d0ac896..3ab1d0b 100644
--- a/src/storage-view.vala
+++ b/src/storage-view.vala
@@ -16,87 +16,58 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Petr Štětka <pstetka redhat com>
+ *          Felipe Borges <felipeborges gnome org>
  */
 
 namespace Usage
 {
+    [GtkTemplate (ui = "/org/gnome/Usage/ui/storage-view.ui")]
     public class StorageView : View
     {
         private StorageListBox storage_list_box;
-        private Gtk.Revealer revealer;
         private StorageActionBar action_bar;
 
+        [GtkChild]
+        private Gtk.Revealer revealer;
+
+        [GtkChild]
+        private Gtk.Stack stack;
+
+        [GtkChild]
+        private Gtk.ScrolledWindow scrolled_window;
+
+        [GtkChild]
+        private Gtk.Paned paned;
+
         public StorageView ()
         {
             name = "STORAGE";
             title = _("Storage");
 
+            /* It would be nice being able to this in the template file. */
             storage_list_box = new StorageListBox();
-            var scrolled_window = new Gtk.ScrolledWindow(null, null);
             scrolled_window.add(storage_list_box);
 
-            var spinner = new Gtk.Spinner();
-            spinner.active = true;
-            spinner.margin_top = 30;
-            spinner.margin_bottom = 20;
-
             var graph = new StorageGraph();
-            var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
-            paned.position = 300;
-            paned.add2(spinner);
-
-            var center_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 12);
-            var image = new Gtk.Image.from_icon_name("folder-symbolic", Gtk.IconSize.DIALOG );
-            image.pixel_size = 128;
-            center_box.add(image);
+            paned.add2(graph);
 
-            Gtk.Label empty_label = new Gtk.Label("<span size='xx-large' font_weight='bold'>" + _("No 
content here") + "</span>");
-            empty_label.set_use_markup (true);
-            empty_label.margin_top = 10;
-            center_box.add(empty_label);
-            center_box.get_style_context().add_class("dim-label");
-            var empty_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
-            empty_box.set_center_widget(center_box);
-            empty_box.show_all();
+            action_bar = new StorageActionBar();
+            revealer.add(action_bar);
 
             storage_list_box.loading.connect(() =>
             {
-                paned.remove(empty_box);
-                paned.remove(scrolled_window);
-                paned.remove(graph);
-                paned.add2(spinner);
+                stack.set_visible_child_name("spinner");
             });
 
             storage_list_box.loaded.connect(() =>
             {
-                paned.add1(scrolled_window);
-                scrolled_window.show();
-
-                paned.remove(spinner);
-                paned.add2(graph);
-                graph.show();
+                stack.set_visible_child_name("content");
             });
 
             storage_list_box.empty.connect(() =>
             {
-                paned.remove(scrolled_window);
-                paned.remove(graph);
-                paned.remove(spinner);
-                paned.add2(empty_box);
-                empty_label.show();
+                stack.set_visible_child_name("empty");
             });
-
-            action_bar = new StorageActionBar();
-
-            revealer = new Gtk.Revealer();
-            revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
-            revealer.transition_duration = 400;
-            revealer.add(action_bar);
-
-            var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
-            box.pack_start(paned, true);
-            box.pack_end(revealer, false);
-            add(box);
         }
 
         public StorageListBox get_storage_list_box()


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