[gnome-usage] process-dialog: Initial port to Gtk+ widget template



commit 0e45df0bd8edd71635185d89e843cbdb729f084b
Author: Felipe Borges <felipeborges gnome org>
Date:   Sat Apr 22 17:33:11 2017 +0200

    process-dialog: Initial port to Gtk+ widget template
    
    Should port the GraphBlock and ProcessDialogHeaderBar to gtk+
    template widgets to fully decouple the ui code here.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781607

 data/org.gnome.Usage.gresource.xml |    1 +
 data/ui/process-dialog.ui          |   24 ++++++++++++++++++++++++
 src/process-dialog.vala            |   25 ++++++++-----------------
 3 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/data/org.gnome.Usage.gresource.xml b/data/org.gnome.Usage.gresource.xml
index d7434dd..7b6b5fa 100644
--- a/data/org.gnome.Usage.gresource.xml
+++ b/data/org.gnome.Usage.gresource.xml
@@ -5,6 +5,7 @@
         <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/process-dialog.ui</file>
         <file preprocess="xml-stripblanks">ui/window.ui</file>
     </gresource>
 </gresources>
diff --git a/data/ui/process-dialog.ui b/data/ui/process-dialog.ui
new file mode 100644
index 0000000..9a4b106
--- /dev/null
+++ b/data/ui/process-dialog.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+
+  <template class="UsageProcessDialog" parent="GtkDialog">
+    <property name="visible">True</property>
+    <property name="use-header-bar">1</property>
+    <property name="modal">True</property>
+    <property name="resizable">False</property>
+    <property name="window-position">center</property>
+    <property name="width-request">950</property>
+    <property name="height-request">350</property>
+    <property name="border-width">5</property>
+
+    <child internal-child="vbox">
+      <object class="GtkBox" id="content">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="margin">20</property>
+        <property name="margin-bottom">0</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/process-dialog.vala b/src/process-dialog.vala
index fb09df0..4cf7d7d 100644
--- a/src/process-dialog.vala
+++ b/src/process-dialog.vala
@@ -1,7 +1,9 @@
+using Gtk;
 using Posix;
 
 namespace Usage
 {
+    [GtkTemplate (ui = "/org/gnome/Usage/ui/process-dialog.ui")]
        public class ProcessDialog : Gtk.Dialog
        {
            ProcessDialogHeaderBar headerbar;
@@ -10,37 +12,26 @@ namespace Usage
         GraphBlock processor_graph_block;
         GraphBlock memory_graph_block;
 
+        [GtkChild]
+        private Gtk.Box content;
+
        public ProcessDialog(Pid pid, string app_name, string process)
        {
-           Object(use_header_bar: 1);
-           set_modal(true);
+            Object();
            set_transient_for((GLib.Application.get_default() as Application).get_window());
-           set_position(Gtk.WindowPosition.CENTER);
-           set_resizable(false);
            this.pid = pid;
                this.title = app_name;
                this.process = process;
-               this.border_width = 5;
-               set_default_size (900, 350);
                create_widgets();
        }
 
        private void create_widgets()
        {
-               Gtk.Box content = get_content_area() as Gtk.Box;
-
-            Gtk.Grid grid = new Gtk.Grid();
-            grid.margin_top = 20;
-            grid.margin_start = 20;
-            grid.margin_end = 20;
-
             processor_graph_block = new GraphBlock(GraphBlockType.PROCESSOR, _("Processor"), this.title);
             memory_graph_block = new GraphBlock(GraphBlockType.MEMORY, _("Memory"), this.title);
 
-            grid.attach(processor_graph_block, 0, 0, 1, 1);
-            grid.attach(memory_graph_block, 1, 0, 1, 1);
-            content.add(grid);
-            content.show_all();
+            content.add(processor_graph_block);
+            content.add(memory_graph_block);
 
             var stop_button = new Gtk.Button.with_label(_("Stop"));
             stop_button.get_style_context().add_class ("destructive-action");


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