[glade/composite-templates-new] Added Composite template toplevel option in Project properties to choose wich toplevel should be use



commit 4b4b785b48801450fd8796883ab23127ae6369e3
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Sun Mar 31 01:46:47 2013 -0300

    Added Composite template toplevel option in Project properties to choose wich toplevel should be used as 
a template

 gladeui/glade-project-properties.ui |   43 ++++++++++++
 gladeui/glade-project.c             |  128 ++++++++++++++++++++++++++++++++++-
 2 files changed, 170 insertions(+), 1 deletions(-)
---
diff --git a/gladeui/glade-project-properties.ui b/gladeui/glade-project-properties.ui
index f8fdf63..d16cc6b 100644
--- a/gladeui/glade-project-properties.ui
+++ b/gladeui/glade-project-properties.ui
@@ -27,10 +27,12 @@
                 <property name="margin_top">6</property>
                 <property name="row_spacing">4</property>
                 <property name="column_spacing">4</property>
+                <property name="row_homogeneous">True</property>
                 <child>
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
                     <property name="label" translatable="yes">Translation domain:</property>
                   </object>
                   <packing>
@@ -53,6 +55,47 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkComboBox" id="template_combobox">
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkCellRendererPixbuf" id="cellrenderertext1"/>
+                      <attributes>
+                        <attribute name="icon-name">0</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                      <attributes>
+                        <attribute name="text">1</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkCheckButton" id="template_checkbutton">
+                    <property name="label" translatable="yes">Composite template toplevel:</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="xalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
               </object>
             </child>
             <child type="label">
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index caad456..80a6acc 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -148,6 +148,8 @@ struct _GladeProjectPrivate
   GtkWidget *relative_path_entry;
   GtkWidget *full_path_button;
   GtkWidget *domain_entry;
+  GtkWidget *template_combobox;
+  GtkWidget *template_checkbutton;
 
   /* Store previews, so we can kill them on close */
   GHashTable *previews;
@@ -1598,6 +1600,57 @@ glade_project_check_target_version (GladeProject *project)
 }
 
 static gboolean
+toplevel_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+  GtkTreeIter parent;
+  return !gtk_tree_model_iter_parent (model, &parent, iter);
+}
+
+static GtkTreeModel *
+glade_project_toplevel_model_filter_new (GladeProject *project)
+{
+  GtkTreeModel *model = gtk_tree_model_filter_new (GTK_TREE_MODEL (project), NULL);
+  gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
+                                          toplevel_visible_func, NULL, NULL);
+  return model;
+}
+
+static void
+glade_project_fix_template (GladeProject *project)
+{
+  GtkTreeModel *model = glade_project_toplevel_model_filter_new (project);
+  GladeProjectPrivate *priv = project->priv;
+  GtkTreeIter iter;
+  gboolean valid;
+
+  valid = gtk_tree_model_get_iter_first (model, &iter);
+  while (valid)
+    {
+      gchar *template_parent;
+      GladeWidget *gwidget;
+      GObject *obj;
+      
+      gtk_tree_model_get (model, &iter,
+                          GLADE_PROJECT_MODEL_COLUMN_OBJECT, &obj,
+                          -1);
+
+      gwidget = glade_widget_get_from_gobject (obj);
+      g_object_get (gwidget, "template-parent", &template_parent, NULL);
+
+      if (template_parent)
+        {
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->template_checkbutton), TRUE);
+          gtk_combo_box_set_model (GTK_COMBO_BOX (priv->template_combobox), model);
+          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->template_combobox), &iter);
+        }
+
+      valid = gtk_tree_model_iter_next (model, &iter);
+    }
+
+  g_object_unref (model);
+}
+
+static gboolean
 glade_project_load_internal (GladeProject *project)
 {
   GladeProjectPrivate *priv = project->priv;
@@ -1694,6 +1747,8 @@ glade_project_load_internal (GladeProject *project)
    */
   glade_project_fix_object_props (project);
 
+  glade_project_fix_template (project);
+
   /* Emit "parse-finished" signal */
   g_signal_emit (project, glade_project_signals[PARSE_FINISHED], 0);
 
@@ -3995,7 +4050,72 @@ on_domain_entry_activate (GtkWidget *entry, GladeProject *project)
   glade_project_set_translation_domain (project, gtk_entry_get_text (GTK_ENTRY (entry)));
 }
 
-#define GET_OBJECT(b,c,o) c(gtk_builder_get_object(b,o));g_warn_if_fail(gtk_builder_get_object(b,o))
+static void
+glade_project_template_parent_clear (GladeProject *project)
+{
+  GladeProjectPrivate *priv = project->priv;
+  GList *l;
+
+  for (l = priv->tree; l; l = g_list_next (l))
+    {
+      GladeWidget *gwidget = glade_widget_get_from_gobject (l->data);
+      g_object_set (gwidget, "template-parent", NULL, NULL);
+    }
+}
+
+static void
+on_template_combo_box_changed (GtkComboBox *combo, GladeProject *project)
+{
+  GtkTreeIter iter;
+
+  glade_project_template_parent_clear (project);
+
+  if (gtk_combo_box_get_active_iter (combo, &iter))
+    {
+      GladeWidgetAdaptor *adaptor;
+      GladeWidget *gwidget;
+      GObject *object;
+
+      gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
+                          GLADE_PROJECT_MODEL_COLUMN_OBJECT, &object, -1);
+      
+      gwidget = glade_widget_get_from_gobject (object);
+      adaptor = glade_widget_get_adaptor (gwidget);
+      
+      g_object_set (gwidget, "template-parent",
+                    glade_widget_adaptor_get_name (adaptor),
+                    NULL);
+    }
+}
+
+static void
+on_template_checkbutton_toggled (GtkToggleButton *togglebutton,
+                                 GladeProject    *project)
+{
+  GtkComboBox *combobox = GTK_COMBO_BOX (project->priv->template_combobox);
+  gboolean active = gtk_toggle_button_get_active (togglebutton);
+
+  glade_project_template_parent_clear (project);
+
+  if (gtk_combo_box_get_model (combobox))
+    gtk_combo_box_set_active_iter (combobox, NULL);
+  
+  if (active)
+    {
+      GtkTreeModel *model = glade_project_toplevel_model_filter_new (project);
+      GladeProjectPrivate *priv = project->priv;
+
+      gtk_combo_box_set_model (combobox, model);
+
+      if (priv->tree && !g_list_next (priv->tree))
+        gtk_combo_box_set_active (combobox, 0);
+    }
+
+  gtk_widget_set_sensitive (GTK_WIDGET (combobox), active);
+}
+
+
+#define GET_OBJECT(b,c,o) c(gtk_builder_get_object(b,o));
 
 static GtkWidget *
 glade_project_build_prefs_dialog (GladeProject *project)
@@ -4023,6 +4143,12 @@ glade_project_build_prefs_dialog (GladeProject *project)
   priv->relative_path_entry = GET_OBJECT (builder, GTK_WIDGET, "relative_path_entry");
   priv->full_path_button = GET_OBJECT (builder, GTK_WIDGET, "full_path_button");
   priv->domain_entry = GET_OBJECT (builder, GTK_WIDGET, "domain_entry");
+  priv->template_checkbutton = GET_OBJECT (builder, GTK_WIDGET, "template_checkbutton");
+  priv->template_combobox = GET_OBJECT (builder, GTK_WIDGET, "template_combobox");
+  g_signal_connect (priv->template_combobox, "changed",
+                    G_CALLBACK (on_template_combo_box_changed), project);
+  g_signal_connect (priv->template_checkbutton, "toggled",
+                    G_CALLBACK (on_template_checkbutton_toggled), project);
 
   verify_button = GET_OBJECT (builder, GTK_WIDGET, "verify_button");
   toolkit_box = GET_OBJECT (builder, GTK_WIDGET, "toolkit_box");


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