[gnome-boxes] editable-entry: Move UI setup to .ui file



commit 0781fb906f5da4b1edd651fd4fcb5beae957f948
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Feb 5 15:37:38 2014 +0000

    editable-entry: Move UI setup to .ui file

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/editable-entry.ui      |   59 ++++++++++++++++++++++
 src/editable-entry.vala        |  106 ++++++++++++++++++---------------------
 3 files changed, 109 insertions(+), 57 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index bc4f35a..61c2a65 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -8,6 +8,7 @@
     <file>icons/boxes-gray.png</file>
     <file preprocess="xml-stripblanks">ui/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/editable-entry.ui</file>
     <file preprocess="xml-stripblanks">ui/mini-graph.ui</file>
     <file preprocess="xml-stripblanks">ui/searchbar.ui</file>
     <file preprocess="xml-stripblanks">ui/selectionbar.ui</file>
diff --git a/data/ui/editable-entry.ui b/data/ui/editable-entry.ui
new file mode 100644
index 0000000..98ad67b
--- /dev/null
+++ b/data/ui/editable-entry.ui
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesEditableEntry" parent="GtkAlignment">
+    <property name="visible">True</property>
+
+    <child>
+      <object class="GtkNotebook" id="notebook">
+        <property name="visible">True</property>
+        <property name="show-tabs">False</property>
+        <property name="show-border">False</property>
+        <property name="page">0</property>
+
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="visible">True</property>
+            <property name="ellipsize">end</property>
+            <property name="xalign">0.0</property>
+            <property name="yalign">0.5</property>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="button">
+            <property name="visible">True</property>
+            <property name="receives_default">True</property>
+            <property name="relief">none</property>
+            <property name="xalign">0.0</property>
+            <property name="yalign">0.5</property>
+            <signal name="clicked" handler="on_button_clicked"/>
+
+            <child>
+              <object class="GtkLabel" id="button_label">
+                <property name="visible">True</property>
+                <property name="ellipsize">end</property>
+                <signal name="size-allocate"
+                        handler="on_button_label_size_allocate"/>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkEntry" id="entry">
+            <property name="visible">True</property>
+            <property name="ellipsize">end</property>
+            <property name="xalign">0.0</property>
+            <property name="yalign">0.5</property>
+            <signal name="activate" handler="on_entry_activated"/>
+            <signal name="focus-out-event" handler="on_entry_focused_out"/>
+            <signal name="key-press-event" handler="on_entry_key_press_event"/>
+            <signal name="style-updated" handler="on_entry_style_updated"/>
+          </object>
+        </child>
+      </object>
+    </child>
+
+  </template>
+</interface>
diff --git a/src/editable-entry.vala b/src/editable-entry.vala
index 3b1c8a8..ea8c2ee 100644
--- a/src/editable-entry.vala
+++ b/src/editable-entry.vala
@@ -5,6 +5,7 @@ using Gtk;
 
 private const string EMPTY_TEXT = "\xe2\x80\x94";
 
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/editable-entry.ui")]
 private class Boxes.EditableEntry: Alignment {
     private enum Page {
         LABEL,
@@ -25,7 +26,7 @@ private class Boxes.EditableEntry: Alignment {
                 value = EMPTY_TEXT;
 
             label.label = value;
-            (button.get_child () as Label).label = value;
+            button_label.label = value;
         }
     }
 
@@ -86,9 +87,13 @@ private class Boxes.EditableEntry: Alignment {
     }
     public bool scale_set { get; set; }
 
+    [GtkChild]
     private Gtk.Notebook notebook;
+    [GtkChild]
     private Gtk.Label label;
-    private Gtk.Button button;
+    [GtkChild]
+    private Gtk.Label button_label;
+    [GtkChild]
     private Gtk.Entry entry;
 
     private void update_entry_font (Gtk.Entry entry) {
@@ -117,7 +122,7 @@ private class Boxes.EditableEntry: Alignment {
             attrs.insert (Pango.attr_weight_new (_weight));
 
         label.set_attributes (attrs);
-        (button.get_child () as Label).set_attributes (attrs);
+        button_label.set_attributes (attrs);
         update_entry_font (entry);
     }
 
@@ -145,59 +150,46 @@ private class Boxes.EditableEntry: Alignment {
     }
 
     public EditableEntry () {
-        notebook = new Gtk.Notebook ();
-        notebook.show_tabs = false;
-        notebook.show_border = false;
-
-        label = new Gtk.Label (EMPTY_TEXT);
-        label.set_ellipsize (Pango.EllipsizeMode.END);
-        label.set_alignment (0.0f, 0.5f);
-        notebook.append_page (label, null);
-
-        button = new Gtk.Button.with_label (EMPTY_TEXT);
-        (button.get_child () as Label).set_ellipsize (Pango.EllipsizeMode.END);
-        button.receives_default = true;
-        button.relief = Gtk.ReliefStyle.NONE;
-        button.set_alignment (0.0f, 0.5f);
-        notebook.append_page (button, null);
-        button.clicked.connect (() => {
-            start_editing ();
-        });
-
-        (button.get_child ()).size_allocate.connect ((widget, allocation) => {
-                Gtk.Allocation alloc;
-
-                widget.get_parent ().get_allocation (out alloc);
-                var offset = allocation.x - alloc.x;
-                if (offset != label.xpad)
-                    label.set_padding (offset, 0);
-
-        });
-
-        entry = new Gtk.Entry ();
-        notebook.append_page (entry, null);
-        entry.activate.connect (() => {
-            stop_editing ();
-        });
-
-        entry.focus_out_event.connect (() => {
-            stop_editing ();
-            return false;
-        });
-
-        entry.key_press_event.connect ((widget, event) => {
-            if (event.keyval == Gdk.Key.Escape)
-                cancel_editing ();
-
-            return false;
-        });
-
-        entry.style_updated.connect ((entry) => {
-            update_entry_font (entry as Gtk.Entry);
-        });
-
-        notebook.page = Page.LABEL;
-        this.add (notebook);
-        this.show_all ();
+        label.label = EMPTY_TEXT;
+        button_label.label = EMPTY_TEXT;
+    }
+
+    [GtkCallback]
+    private void on_button_clicked () {
+        start_editing ();
+    }
+
+    [GtkCallback]
+    private void on_button_label_size_allocate (Gtk.Widget widget, Gtk.Allocation allocation) {
+        Gtk.Allocation alloc;
+
+        widget.get_parent ().get_allocation (out alloc);
+        var offset = allocation.x - alloc.x;
+        if (offset != label.xpad)
+            label.set_padding (offset, 0);
+    }
+
+    [GtkCallback]
+    private void on_entry_activated () {
+        stop_editing ();
+    }
+
+    [GtkCallback]
+    private bool on_entry_focused_out () {
+        stop_editing ();
+        return false;
+    }
+
+    [GtkCallback]
+    private bool on_entry_key_press_event (Gtk.Widget widget, Gdk.EventKey event) {
+        if (event.keyval == Gdk.Key.Escape)
+            cancel_editing ();
+
+        return false;
+    }
+
+    [GtkCallback]
+    private void on_entry_style_updated () {
+        update_entry_font (entry as Gtk.Entry);
     }
 }


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