[gnome-usage] performance-view: Port to Gtk+ widget template



commit 5970ee80899c604f398c321ae4e8891d2fd0702e
Author: Felipe Borges <felipeborges gnome org>
Date:   Sat Apr 22 17:11:29 2017 +0200

    performance-view: Port to Gtk+ widget template
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781607

 data/org.gnome.Usage.gresource.xml |    1 +
 data/ui/performance-view.ui        |   56 +++++++++++++++++++++++++++++++++++
 src/performance-view.vala          |   57 ++++++++++++++++-------------------
 3 files changed, 83 insertions(+), 31 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index 5a7054b..d7434dd 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -4,6 +4,7 @@
         <file compressed="true">interface/adwaita.css</file>
         <file compressed="true">interface/adwaita-dark.css</file>
         <file preprocess="xml-stripblanks">ui/header-bar.ui</file>
+        <file preprocess="xml-stripblanks">ui/performance-view.ui</file>
         <file preprocess="xml-stripblanks">ui/window.ui</file>
     </gresource>
 </gresources>
diff --git a/data/ui/performance-view.ui b/data/ui/performance-view.ui
new file mode 100644
index 0000000..f6da7e0
--- /dev/null
+++ b/data/ui/performance-view.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+
+  <template class="UsagePerformanceView" parent="UsageView">
+    <property name="visible">True</property>
+
+    <child>
+
+      <object class="GtkPaned" id="paned">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+
+        <child>
+          <object class="GtkBox" id="switcher_box">
+            <property name="visible">True</property>
+            <property name="width-request">200</property>
+            <style>
+              <class name="sidebar"/>
+            </style>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+
+            <child>
+              <object class="GtkSearchBar" id="search_bar">
+                <property name="visible">True</property>
+
+                <child>
+                  <object class="GtkSearchEntry" id="search_entry">
+                    <property name="visible">True</property>
+                    <property name="width-request">350</property>
+                    <signal name="search-changed" handler="on_search_entry_changed"/>
+                  </object>
+                </child>
+              </object>
+            </child>
+
+            <child>
+              <object class="GtkStack" id="performance_stack">
+                <property name="visible">True</property>
+                <property name="transition-type">slide-up-down</property>
+                <property name="transition-duration">700</property>
+                <property name="vexpand">True</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/performance-view.vala b/src/performance-view.vala
index 184d7d3..0340d7f 100644
--- a/src/performance-view.vala
+++ b/src/performance-view.vala
@@ -1,17 +1,28 @@
+using Gtk;
+
 namespace Usage
 {
+    [GtkTemplate (ui = "/org/gnome/Usage/ui/performance-view.ui")]
     public class PerformanceView : View
     {
-        Gtk.Stack performance_stack;
-        Gtk.SearchBar search_bar;
+        [GtkChild]
+        private Gtk.Box switcher_box;
+
+        [GtkChild]
+        private Gtk.Stack performance_stack;
+
+        [GtkChild]
+        private Gtk.SearchBar search_bar;
+
+        [GtkChild]
+        private Gtk.SearchEntry search_entry;
+
         View[] sub_views;
 
-               public PerformanceView()
-               {
+        public PerformanceView ()
+        {
             name = "PERFORMANCE";
-                       title = _("Performance");
-
-            var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
+            title = _("Performance");
 
             sub_views = new View[]
             {
@@ -19,35 +30,19 @@ namespace Usage
                 new MemorySubView()
             };
 
-            search_bar = new Gtk.SearchBar();
-            var search_entry = new Gtk.SearchEntry();
-            search_entry.width_request = 350;
-            search_entry.search_changed.connect(() => {
-                foreach(View sub_view in sub_views)
-                    ((SubView) sub_view).search_in_processes(search_entry.get_text());
-            });
-            search_bar.add(search_entry);
-            search_bar.connect_entry(search_entry);
-
-            performance_stack = new Gtk.Stack();
-            performance_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
-            performance_stack.set_transition_duration(700);
-            performance_stack.vexpand = true;
-
-            box.add(search_bar);
-            box.add(performance_stack);
-
             foreach(var sub_view in sub_views)
                 performance_stack.add_titled(sub_view, sub_view.name, sub_view.name);
 
                    var stackSwitcher = new GraphStackSwitcher(performance_stack, sub_views);
-                   stackSwitcher.set_size_request(200, -1);
-                   stackSwitcher.get_style_context().add_class("sidebar");
+            switcher_box.add (stackSwitcher);
+
+            show_all ();
+        }
 
-           var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
-           paned.add1(stackSwitcher);
-           paned.add2(box);
-                   add(paned);
+        [GtkCallback]
+        private void on_search_entry_changed () {
+            foreach(View sub_view in sub_views)
+                ((SubView) sub_view).search_in_processes(search_entry.get_text());
         }
 
         public void set_search_mode(bool enable)


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