[POS-commit] r247 - in libglade: . examples

Johan Dahlin jdahlin at async.com.br
Wed Mar 30 21:39:24 BRT 2005


Author: jdahlin
Date: 2005-03-30 21:39:24 -0300 (Wed, 30 Mar 2005)
New Revision: 247

Modified:
   libglade/examples/uimanager.glade
   libglade/glade-xml.c
Log:
Add support for fetching merge_id, to make lorenzo happy. Update UIManager example.

Modified: libglade/examples/uimanager.glade
===================================================================
--- libglade/examples/uimanager.glade	2005-03-30 21:51:52 UTC (rev 246)
+++ libglade/examples/uimanager.glade	2005-03-31 00:39:24 UTC (rev 247)
@@ -23,8 +23,6 @@
                           <property name="label">_Copy</property>
                           <property name="short-label">_Copy</property>
                           <property name="stock-id">gtk-copy</property>
-<!--                          <property name="accelerator">&lt;control&gt;c</property>
--->
                       </object>
                   </child>
                   <child>
@@ -33,8 +31,6 @@
                           <property name="label">_Cut</property>
                           <property name="short-label">_Cut</property>
                           <property name="stock-id">gtk-cut</property>
-<!--                          <property name="accelerator">&lt;control&gt;x</property>
--->
                       </object>
                   </child>
                   <child>
@@ -43,8 +39,6 @@
                           <property name="label">_Paste</property>
                           <property name="short-label">_Paste</property>
                           <property name="stock-id">gtk-paste</property>
-<!--                          <property name="accelerator">&lt;control&gt;v</property>
--->
                       </object>
                   </child>
                   <child>
@@ -54,8 +48,6 @@
                           <property name="short-label">_Save</property>
                           <property name="tooltip">Save your files!</property>
                           <property name="stock-id">gtk-save</property>
-<!--                          <property name="accelerator">&lt;control&gt;s</property>
--->
                       </object>
                   </child>
                   <child>
@@ -72,8 +64,6 @@
                           <property name="short-label">_New</property>
                           <property name="tooltip">New file</property>
                           <property name="stock-id">gtk-new</property>
-<!--                          <property name="accelerator">&lt;control&gt;k</property>
--->
                       </object>
                   </child>
                   <child>
@@ -89,8 +79,6 @@
                           <property name="label">_Open</property>
                           <property name="short-label">_Open</property>
                           <property name="stock-id">gtk-open</property>
-<!--                          <property name="accelerator">&lt;control&gt;o</property>
--->
                       </object>
                   </child>
              </object>
@@ -105,28 +93,19 @@
         <property name="events">0</property>
         <property name="title">UIManager</property>
         <property name="role"></property>
-<!--        <signal handler="on_window1__destroy" name="destroy" after="True"/>
-  -->
         <child>
             <object class="GtkVBox" id="vbox1">
                 <property name="visible">True</property>
                 <property name="events">0</property>
                 <child>
-                    <object class="GtkMenuBar" id="menubar1" constructor="uimanager">
-                        <property name="visible">True</property>
-                        <property name="events">0</property>
-                    </object>
+                    <object class="GtkMenuBar" id="menubar1" constructor="ui1"/>
                     <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
                     </packing>
                 </child>
                 <child>
-                    <object class="GtkToolbar" id="toolbar1" constructor="uimanager">
-                        <property name="visible">True</property>
-                        <property name="events">0</property>
-                        <property name="toolbar_style">2</property>
-                    </object>
+                    <object class="GtkToolbar" id="toolbar1" constructor="ui1"/>
                     <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>

Modified: libglade/glade-xml.c
===================================================================
--- libglade/glade-xml.c	2005-03-30 21:51:52 UTC (rev 246)
+++ libglade/glade-xml.c	2005-03-31 00:39:24 UTC (rev 247)
@@ -72,6 +72,9 @@
      * and get freed with those widgets. */
     GHashTable *name_hash;
 	
+    /* hash tables of ui manager ids. */
+    GHashTable *ui_hash;
+
     /* hash table of signals.  The Data is a GList of GladeSignalData
      * structures which get freed when the GladeXML object is
      * destroyed */
@@ -112,6 +115,11 @@
     gpointer user_data;
 } connect_data_data;
 
+typedef struct {
+    gint merge_id;
+    GObject *ui_manager;
+} merge_data;
+
 typedef struct _GladeObjectBuildData GladeObjectBuildData;
 struct _GladeObjectBuildData {
     GladeBuildChildrenFunc build_children;
@@ -200,6 +208,7 @@
     gtk_object_sink(GTK_OBJECT(priv->tooltips));
     priv->name_hash = g_hash_table_new(g_str_hash, g_str_equal);
     priv->signals = g_hash_table_new(g_str_hash, g_str_equal);
+    priv->ui_hash  = g_hash_table_new(g_str_hash, g_str_equal);
     priv->toplevel = NULL;
     priv->accel_group = NULL;
     priv->default_widget = NULL;
@@ -689,6 +698,22 @@
 /**
  * glade_xml_handle_object_prop
  * @self: the GladeXML object
+ * @name: name of widget 
+ *
+ * Returns: 
+ */
+gint
+glade_xml_get_merge_id(GladeXML *self, const gchar *name)
+{
+    merge_data *data;
+    
+    data = g_hash_table_lookup(self->priv->ui_hash, name);
+    return (gint)data->merge_id;
+}
+
+/**
+ * glade_xml_handle_object_prop
+ * @self: the GladeXML object
  * @object: the property the object widgetto set the property on.
  * @prop_name: the name of the property.
  * @value_name: the name of the object used as the value for the property.
@@ -1635,7 +1660,7 @@
 	    continue;
 	}
 
-	    if (glade_xml_set_value_from_string(xml, pspec,
+	if (glade_xml_set_value_from_string(xml, pspec,
 					    info->properties[i].value,
 					    &param.value)) {
 	    param.name = info->properties[i].name;
@@ -1648,7 +1673,6 @@
 					    &info->properties[i]);
 	}
     }
-    g_print("building %s %d\n", info->name, info->n_uis);
     object = g_object_newv(widget_type, props_array->len,
 			   (GParameter *)props_array->data);
 
@@ -1844,22 +1868,27 @@
 	ret = custom_new(self, info);
     } else if (info->constructor != NULL) {
 	GObject *constructor;
-	constructor = glade_xml_get_object(self, info->constructor);
-	if (!constructor) {
-	    g_warning("unknown constructor object '%s'", constructor);
-	} else if (GTK_IS_UI_MANAGER(constructor)) {
-	    gchar *tmp;
-	    tmp = g_strdup_printf("ui/%s", info->name);
-	    g_print("Constructing %s... from %s\n",
-		    tmp, info->constructor);
-	    ret = G_OBJECT(gtk_ui_manager_get_widget(GTK_UI_MANAGER(constructor),
-						     tmp));
-	    g_assert(ret != NULL);
-	    g_free(tmp);
-	} else {
+	merge_data *data;
+	gchar *tmp;
+
+	data = g_hash_table_lookup(self->priv->ui_hash,
+				   info->constructor);
+	if (!data) {
+	    g_warning("unknown constructor object '%s'", info->constructor);
+	    return NULL;
+	}
+
+	if (!GTK_IS_UI_MANAGER(data->ui_manager)) {
 	    g_warning("constructor object of type '%s' is not suported",
-		      g_type_name(G_OBJECT_TYPE(constructor)));
-	}
+		      g_type_name(G_OBJECT_TYPE(data->ui_manager)));
+	    return NULL;
+	} 
+
+	tmp = g_strdup_printf("ui/%s", info->name);
+	ret = G_OBJECT(gtk_ui_manager_get_widget(GTK_UI_MANAGER(data->ui_manager),
+						 tmp));
+	g_assert(ret != NULL);
+	g_free(tmp);
     } else {
 	/* Call GladeXml's lookup_type() virtual function to get the gtype: */
 	type = (* GLADE_XML_GET_CLASS(self)->lookup_type)(self, info->classname);
@@ -2096,28 +2125,39 @@
     }
 
     if (GTK_IS_UI_MANAGER(object)) {
-	int i;
+	int i, merge_id;
 	gchar *filename;
 	
 	for (i = 0; i < info->n_uis; i++) {
 	    GladeUIInfo ui = info->uis[i];
-
+	    merge_data *data;
+	    
 	    if (ui.filename) {
 		GError *error = NULL;
 		
 		filename = glade_xml_relative_file(self, ui.filename);
-		gtk_ui_manager_add_ui_from_file(GTK_UI_MANAGER(object),
-						filename,
-						&error);
+		
+		merge_id = gtk_ui_manager_add_ui_from_file(GTK_UI_MANAGER(object),
+							   filename,
+							   &error);
 		g_free(filename);
 		if (error) {
 		    g_warning("Error: %s", error->message);
 		    g_error_free(error);
 		}
+
+		data = g_new0(merge_data, 1);
+		data->merge_id = merge_id;
+		data->ui_manager = object;
+
+		g_hash_table_insert(self->priv->ui_hash,
+				    ui.id,
+				    data);
 	    }
-	    
-	    gtk_ui_manager_ensure_update(GTK_UI_MANAGER(object));
 	}
+	
+	/* When we're done, tell the GtkUIManager to update */
+	gtk_ui_manager_ensure_update(GTK_UI_MANAGER(object));
     }
 
     if (visible_id == 0)



More information about the POS-commit mailing list