[glade] GladeEditor: Ported to define the UI in templates.



commit a57a999a6b4762dbade62e6aa2be7f4c02a57c91
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Apr 12 21:01:13 2013 +0900

    GladeEditor: Ported to define the UI in templates.

 gladeui/Makefile.am                     |    5 +-
 gladeui/glade-editor.c                  |  171 +++---------------
 gladeui/glade-editor.ui                 |  300 +++++++++++++++++++++++++++++++
 gladeui/gladeui-resources.gresource.xml |    1 +
 po/POTFILES.in                          |    1 +
 5 files changed, 331 insertions(+), 147 deletions(-)
---
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am
index 188da9d..8cd39e5 100644
--- a/gladeui/Makefile.am
+++ b/gladeui/Makefile.am
@@ -50,8 +50,9 @@ BUILT_SOURCES = \
        gladeui-resources.c \
        gladeui-resources.h
 
-UI_FILES = \
-       glade-project-properties.ui \
+UI_FILES =                             \
+       glade-editor.ui                 \
+       glade-project-properties.ui     \
        glade-property-label.ui
 
 GRAPHICS_FILES = \
diff --git a/gladeui/glade-editor.c b/gladeui/glade-editor.c
index 8c0ec57..9f49df9 100644
--- a/gladeui/glade-editor.c
+++ b/gladeui/glade-editor.c
@@ -52,6 +52,11 @@
 #include "glade-utils.h"
 #include "glade-editor-property.h"
 
+static void glade_editor_switch_page (GtkNotebook     *notebook,
+                                     GtkWidget       *page,
+                                     guint            page_num,
+                                     GladeEditor     *editor);
+
 enum
 {
   PROP_0,
@@ -96,7 +101,6 @@ struct _GladeEditorPrivate
   GtkWidget *page_widget;
   GtkWidget *page_packing;
   GtkWidget *page_common;
-  GtkWidget *page_signals;
   GtkWidget *page_atk;
 
   GladeSignalEditor *signal_editor; /* The signal editor packed into vbox_signals
@@ -133,7 +137,6 @@ struct _GladeEditorPrivate
 
   GtkWidget *class_icon; /* An image with the current widget's class icon.  */
   GtkWidget *class_label; /* A label with the current class label. */
-  GtkWidget *widget_label; /* A label with the current widget name. */
 
   gboolean show_class_field; /* Whether or not to show the class field at the top */
 };
@@ -216,10 +219,8 @@ glade_editor_dispose (GObject *object)
 static void
 glade_editor_class_init (GladeEditorClass *klass)
 {
-  GObjectClass *object_class;
-
-  glade_editor_parent_class = g_type_class_peek_parent (klass);
-  object_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->dispose      = glade_editor_dispose;
   object_class->set_property = glade_editor_set_property;
@@ -258,66 +259,23 @@ glade_editor_class_init (GladeEditorClass *klass)
   /* Install all properties */
   g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 
-  g_type_class_add_private (klass, sizeof (GladeEditorPrivate));
-}
-
-static GtkWidget *
-glade_editor_notebook_page (GladeEditor *editor,
-                            GladeEditorPageType type,
-                            const gchar *name)
-{
-  GtkWidget *label_widget;
-  GtkWidget *container;
-  static gint page = 0;
+  /* Bind to template */
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/gladeui/glade-editor.ui");
 
-  /* construct tab label widget */
-  if (type == GLADE_PAGE_ATK)
-    {
-      GtkWidget *image = gtk_image_new_from_resource ("/org/gnome/gladeui/atk.png");
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, notebook);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, page_widget);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, page_packing);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, page_common);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, page_atk);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, class_field);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, class_icon);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, class_label);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, warning);
+  gtk_widget_class_bind_child (widget_class, GladeEditorPrivate, signal_editor);
 
-      label_widget = gtk_event_box_new ();
-      gtk_container_add (GTK_CONTAINER (label_widget), image);
-      gtk_widget_show (label_widget);
-      gtk_widget_show (image);
+  gtk_widget_class_bind_callback (widget_class, glade_editor_switch_page);
 
-      gtk_widget_set_tooltip_text (label_widget, name);
-    }
-  else
-    {
-      label_widget = gtk_label_new_with_mnemonic (name);
-    }
-
-  /* configure page container */
-  if (type == GLADE_PAGE_SIGNAL)
-    {
-      container = gtk_alignment_new (.5, .5, 1, 1);
-      gtk_notebook_insert_page (GTK_NOTEBOOK (editor->priv->notebook), container,
-                                label_widget, page++);
-    }
-  else
-    {
-      GtkWidget *sw;
-      
-      container = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-      
-      gtk_widget_set_margin_top (container, 2);
-      gtk_widget_set_margin_left (container, 4);
-      gtk_widget_set_margin_right (container, 2);
-      
-      gtk_container_set_border_width (GTK_CONTAINER (container), 2);
-      /* wrap the alignment in a scrolled window */
-      sw = gtk_scrolled_window_new (NULL, NULL);
-      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
-                                      GTK_POLICY_AUTOMATIC,
-                                      GTK_POLICY_AUTOMATIC);
-      gtk_container_add (GTK_CONTAINER (sw), container);
-
-      gtk_notebook_insert_page (GTK_NOTEBOOK (editor->priv->notebook), sw,
-                                label_widget, page++);
-    }
-
-  gtk_widget_show (container);
-  return container;
+  g_type_class_add_private (klass, sizeof (GladeEditorPrivate));
 }
 
 static void
@@ -379,40 +337,6 @@ glade_editor_update_widget_name_cb (GladeWidget *widget,
   glade_editor_update_class_field (editor);
 }
 
-static GtkWidget *
-glade_editor_setup_class_field (GladeEditor *editor)
-{
-  GladeEditorPrivate *priv = GLADE_EDITOR_PRIVATE (editor);
-  GtkWidget *hbox;
-  gint       icon_height;
-
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
-
-  priv->class_icon = gtk_image_new ();
-  priv->class_label = gtk_label_new (NULL);
-  priv->warning = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
-                                            GTK_ICON_SIZE_MENU);
-
-  gtk_widget_set_no_show_all (priv->warning, TRUE);
-  gtk_widget_set_no_show_all (priv->class_icon, TRUE);
-
-  gtk_misc_set_alignment (GTK_MISC (priv->class_label), 0.0, 0.5);
-  gtk_label_set_ellipsize (GTK_LABEL (priv->class_label), PANGO_ELLIPSIZE_END);
-
-  gtk_box_pack_start (GTK_BOX (hbox), priv->warning, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (hbox), priv->class_icon, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (hbox), priv->class_label, TRUE, TRUE, 0);
-
-  gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, NULL, &icon_height);
-  gtk_widget_set_size_request (priv->class_label, -1, icon_height + 2);
-
-  glade_editor_update_class_field (editor);
-  gtk_widget_show_all (hbox);
-
-  return hbox;
-}
-
-
 static void
 glade_editor_switch_page (GtkNotebook     *notebook,
                          GtkWidget       *page,
@@ -447,45 +371,16 @@ static void
 glade_editor_init (GladeEditor *editor)
 {
   GladeEditorPrivate *priv;
-  GtkWidget    *hbox;
-
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), GTK_ORIENTATION_VERTICAL);
+  gint                icon_height;
 
   editor->priv = priv = GLADE_EDITOR_GET_PRIVATE (editor);
 
-  priv->notebook = gtk_notebook_new ();
-  priv->page_widget = glade_editor_notebook_page (editor, GLADE_PAGE_GENERAL, _("_General"));
-  priv->page_packing = glade_editor_notebook_page (editor, GLADE_PAGE_PACKING, _("_Packing"));
-  priv->page_common = glade_editor_notebook_page (editor, GLADE_PAGE_COMMON, _("_Common"));
-  priv->page_signals = glade_editor_notebook_page (editor, GLADE_PAGE_SIGNAL, _("_Signals"));
-  priv->page_atk = glade_editor_notebook_page (editor, GLADE_PAGE_ATK, _("Accessibility"));
-  priv->editables = NULL;
-  priv->loading = FALSE;
-  priv->show_class_field = TRUE;
-
-  g_signal_connect (G_OBJECT (priv->notebook), "switch-page",
-                   G_CALLBACK (glade_editor_switch_page), editor);
-
-  priv->class_field = glade_editor_setup_class_field (editor);
-
-  gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 0);
-
-  gtk_notebook_set_scrollable (GTK_NOTEBOOK (priv->notebook), TRUE);
-
-  gtk_box_pack_start (GTK_BOX (editor), priv->class_field, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (editor), priv->notebook, TRUE, TRUE, 0);
+  gtk_widget_init_template (GTK_WIDGET (editor));
 
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_widget_set_hexpand (hbox, FALSE);
-
-  gtk_notebook_set_action_widget (GTK_NOTEBOOK (priv->notebook), hbox, GTK_PACK_END);
-  gtk_widget_show_all (hbox);
-  
-  gtk_widget_show_all (GTK_WIDGET (editor));
-
-  gtk_widget_hide (GTK_WIDGET (editor));
+  gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, NULL, &icon_height);
+  gtk_widget_set_size_request (priv->class_label, -1, icon_height + 2);
 
-  gtk_widget_set_no_show_all (GTK_WIDGET (editor), TRUE);
+  glade_editor_update_class_field (editor);
 }
 
 static GtkWidget *
@@ -611,19 +506,6 @@ glade_editor_load_editable_in_page (GladeEditor *editor,
 }
 
 static void
-glade_editor_load_signal_page (GladeEditor *editor)
-{
-  GladeEditorPrivate *priv = GLADE_EDITOR_PRIVATE (editor);
-
-  if (priv->signal_editor == NULL)
-    {
-      priv->signal_editor = glade_signal_editor_new ();
-      gtk_container_add (GTK_CONTAINER (priv->page_signals),
-                         GTK_WIDGET (priv->signal_editor));
-    }
-}
-
-static void
 glade_editor_load_widget_class (GladeEditor *editor,
                                 GladeWidgetAdaptor *adaptor)
 {
@@ -632,7 +514,6 @@ glade_editor_load_widget_class (GladeEditor *editor,
   glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_COMMON);
   glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_ATK);
   glade_editor_load_editable_in_page (editor, NULL, GLADE_PAGE_PACKING);
-  glade_editor_load_signal_page (editor);
 
   editor->priv->loaded_adaptor = adaptor;
 }
diff --git a/gladeui/glade-editor.ui b/gladeui/glade-editor.ui
new file mode 100644
index 0000000..413aba2
--- /dev/null
+++ b/gladeui/glade-editor.ui
@@ -0,0 +1,300 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="glade">
+  <!-- interface-requires gladeui 0.0 -->
+  <!-- interface-requires gtk+ 3.8 -->
+  <template class="GladeEditor" parent="GtkBox">
+    <property name="can_focus">False</property>
+    <property name="no_show_all">True</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkBox" id="class_field">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">4</property>
+        <child>
+          <object class="GtkImage" id="warning">
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="stock">gtk-dialog-warning</property>
+            <property name="icon_size">1</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="class_icon">
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="stock">gtk-missing-image</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="class_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label">Class Title Label</property>
+            <property name="ellipsize">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkNotebook" id="notebook">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="scrollable">True</property>
+        <signal name="select-page" handler="glade_editor_switch_page" swapped="no"/>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkViewport" id="viewport1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkBox" id="page_widget">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">6</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="margin_bottom">2</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">_General</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow2">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkViewport" id="viewport2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkBox" id="page_packing">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">6</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="margin_bottom">2</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">_Packing</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="position">1</property>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow3">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkViewport" id="viewport3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkBox" id="page_common">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">6</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="margin_bottom">2</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">_Common</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="position">2</property>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkAlignment" id="page_signals">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GladeSignalEditor" id="signal_editor">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">3</property>
+          </packing>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label4">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">_Signals</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="position">3</property>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow4">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkViewport" id="viewport4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkBox" id="page_atk">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">6</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="margin_bottom">2</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">4</property>
+          </packing>
+        </child>
+        <child type="tab">
+          <object class="GtkEventBox" id="eventbox1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="tooltip_text" translatable="yes">Accessibility</property>
+            <child>
+              <object class="GtkImage" id="image1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="resource">/org/gnome/gladeui/atk.png</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">4</property>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/gladeui/gladeui-resources.gresource.xml b/gladeui/gladeui-resources.gresource.xml
index 03aea4f..2b811e2 100644
--- a/gladeui/gladeui-resources.gresource.xml
+++ b/gladeui/gladeui-resources.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/gladeui">
     <file>atk.png</file>
+    <file compressed="true" preprocess="xml-stripblanks">glade-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-project-properties.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-property-label.ui</file>
   </gresource>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ca51ee6..152e40e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,7 @@ gladeui/glade-debug.c
 gladeui/glade-design-layout.c
 gladeui/glade-design-view.c
 gladeui/glade-editor.c
+[type: gettext/glade]gladeui/glade-editor.ui
 gladeui/glade-editor-property.c
 gladeui/glade-editor-table.c
 gladeui/glade-inspector.c


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