[devhelp/wip/stuff: 11/13] assistant: use a template



commit ea9bce840c19288c6b4fda6d5b5cab319b7ef0b6
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Thu Jul 25 11:48:04 2013 +0200

    assistant: use a template

 src/dh-assistant.c   |   20 +++++++-------------
 src/dh-assistant.ui  |   16 ++++++++++++++++
 src/dh.gresource.xml |    1 +
 3 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index 5b36852..af6e050 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -98,6 +98,11 @@ dh_assistant_class_init (DhAssistantClass *klass)
 
         widget_class->key_press_event = dh_assistant_key_press_event;
         widget_class->configure_event = dh_assistant_configure_event;
+
+        /* Bind class to template */
+        gtk_widget_class_set_template_from_resource (widget_class,
+                                                     "/org/gnome/devhelp/dh-assistant.ui");
+        gtk_widget_class_bind_child (widget_class, DhAssistant, view);
 }
 
 static void
@@ -105,25 +110,14 @@ dh_assistant_init (DhAssistant *assistant)
 {
         DhAssistantPrivate *priv = dh_assistant_get_instance_private (assistant);
 
-        priv->settings = dh_settings_get ();
-        priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-        gtk_widget_show (priv->main_box);
-        gtk_container_add (GTK_CONTAINER (assistant), priv->main_box);
-
-        /* i18n: Please don't translate "Devhelp". */
-        gtk_window_set_title (GTK_WINDOW (assistant), _("Devhelp — Assistant"));
-        gtk_window_set_icon_name (GTK_WINDOW (assistant), "devhelp");
+        gtk_widget_init_template (GTK_WIDGET (assistant));
 
-        priv->view = dh_assistant_view_new ();
+        priv->settings = dh_settings_get ();
 
         g_signal_connect (priv->view, "open-uri",
                           G_CALLBACK (assistant_view_open_uri_cb),
                           assistant);
 
-        gtk_box_pack_start (GTK_BOX (priv->main_box),
-                            priv->view, TRUE, TRUE, 0);
-        gtk_widget_show (priv->view);
-
         dh_util_window_settings_restore (GTK_WINDOW (assistant),
                                          dh_settings_peek_assistant_settings (priv->settings),
                                          FALSE);
diff --git a/src/dh-assistant.ui b/src/dh-assistant.ui
new file mode 100644
index 0000000..7803a4c
--- /dev/null
+++ b/src/dh-assistant.ui
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.8 -->
+  <template class="DhAssistant" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
+    <property name="has_focus">False</property>
+    <property name="is_focus">False</property>
+    <property name="title" translatable="yes" comments="Please don't translate &quot;Devhelp&quot;">Devhelp 
— Assistant</property>
+    <property name="icon_name">devhelp</property>
+    <child>
+      <object class="DhAssistantView" id="view">
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
index 1893e08..8ff708c 100644
--- a/src/dh.gresource.xml
+++ b/src/dh.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/devhelp">
     <file>devhelp.ui</file>
+    <file preprocess="xml-stripblanks">dh-assistant.ui</file>
     <file preprocess="xml-stripblanks">dh-window.ui</file>
   </gresource>
 </gresources>


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