glade3 r1739 - in trunk: . gladeui



Author: tvb
Date: Mon Mar 10 23:54:04 2008
New Revision: 1739
URL: http://svn.gnome.org/viewvc/glade3?rev=1739&view=rev

Log:

	* gladeui/glade-widget.c, gladeui/glade-project.c: Moved
	  widget name policing to gladeproject.

	* gladeui/glade-editor.c: Dont commit name values if name
	  already exists in the project.



Modified:
   trunk/ChangeLog
   trunk/gladeui/glade-editor.c
   trunk/gladeui/glade-id-allocator.c
   trunk/gladeui/glade-project.c
   trunk/gladeui/glade-widget.c

Modified: trunk/gladeui/glade-editor.c
==============================================================================
--- trunk/gladeui/glade-editor.c	(original)
+++ trunk/gladeui/glade-editor.c	Mon Mar 10 23:54:04 2008
@@ -412,7 +412,8 @@
 
 	widget = editor->loaded_widget;
 	new_name = gtk_editable_get_chars (GTK_EDITABLE (editable), 0, -1);
-	glade_command_set_name (widget, new_name);
+	if (!glade_project_get_widget_by_name (widget->project, new_name))
+		glade_command_set_name (widget, new_name);
 	g_free (new_name);
 }
 

Modified: trunk/gladeui/glade-id-allocator.c
==============================================================================
--- trunk/gladeui/glade-id-allocator.c	(original)
+++ trunk/gladeui/glade-id-allocator.c	Mon Mar 10 23:54:04 2008
@@ -154,7 +154,7 @@
 {
 	g_return_if_fail (allocator != NULL);
 
-	id--;
+	id = id > 0 ? id - 1 : 0;
 	allocator->data[id >> 5] |= 1 << (id & 31);
 }
 

Modified: trunk/gladeui/glade-project.c
==============================================================================
--- trunk/gladeui/glade-project.c	(original)
+++ trunk/gladeui/glade-project.c	Mon Mar 10 23:54:04 2008
@@ -937,6 +937,7 @@
 	if (GLADE_IS_PLACEHOLDER (object)) 
 		return;
 
+
 	/* Only widgets accounted for in the catalog or widgets declared
 	 * in the plugin with glade_widget_new_for_internal_child () are
 	 * usefull in the project.
@@ -947,6 +948,16 @@
 	/* Dont add widgets that are already in the project */
 	if (glade_project_has_object (project, object))
 		return;
+
+
+	/* Police widget names here (just rename them on the way in the project)
+	 */
+	if (glade_project_get_widget_by_name (project, gwidget->name) != NULL)
+	{ 
+		gchar *name = glade_project_new_widget_name (project, gwidget->name);
+		glade_widget_set_name (gwidget, name);
+		g_free (name);
+	}
 		
 	/* Code body starts here */
 	reentrancy_count++;
@@ -1127,10 +1138,28 @@
 void
 glade_project_widget_name_changed (GladeProject *project, GladeWidget *widget, const char *old_name)
 {
+	GladeWidget *iter;
+	GList       *l;
 	g_return_if_fail (GLADE_IS_PROJECT (project));
 	g_return_if_fail (GLADE_IS_WIDGET (widget));
 
 	glade_project_release_widget_name (project, widget, old_name);
+
+	/* Police widget names here (just rename them on the way in the project)
+	 */
+	for (l = project->priv->objects; l; l = l->next)
+	{
+		iter = glade_widget_get_from_gobject (l->data);
+		
+		if (widget != iter &&
+		    !strcmp (widget->name, iter->name))
+		{ 
+			gchar *name = glade_project_new_widget_name (project, widget->name);
+			glade_widget_set_name (widget, name);
+			g_free (name);
+		}
+		
+	}
 	
 	g_signal_emit (G_OBJECT (project),
 		       glade_project_signals [WIDGET_NAME_CHANGED],

Modified: trunk/gladeui/glade-widget.c
==============================================================================
--- trunk/gladeui/glade-widget.c	(original)
+++ trunk/gladeui/glade-widget.c	Mon Mar 10 23:54:04 2008
@@ -1348,14 +1348,7 @@
 	}
 	else
 	{
-		gchar *name;
-
-		if (exact)
-			name = g_strdup (template_widget->name);
-		else
-			name = glade_project_new_widget_name (template_widget->project,
-							      template_widget->name);
-		
+		gchar *name = g_strdup (template_widget->name);
 		gwidget = glade_widget_adaptor_create_widget
 			(template_widget->adaptor, FALSE,
 			 "name", name,
@@ -2172,7 +2165,7 @@
 	GtkWidget *layout;
 
 	g_return_if_fail (GLADE_IS_WIDGET (widget));
-
+	
 	/* Position window at saved coordinates or in the center */
 	if (GTK_IS_WINDOW (widget->object) && glade_widget_embed (widget))
 	{
@@ -2613,8 +2606,17 @@
 {
 	g_return_if_fail (GLADE_IS_WIDGET (widget));
 	if (widget->name != name) {
+
+		if (widget->project && 
+		    glade_project_get_widget_by_name (widget->project, name))
+		{
+			/* print a warning ? */
+			return;
+		}
+
 		if (widget->name)
 			g_free (widget->name);
+		
 		widget->name = g_strdup (name);
 		g_object_notify (G_OBJECT (widget), "name");
 	}



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