[glade/glade-3-8] * plugins/gtk+/glade-gtk.c: Fixed add/remove parent commands so that they work with parentless wid



commit 8eaae6b309bb87d291f4d4848c60615f516b0a0f
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sun Jan 9 11:41:38 2011 +0900

    	* plugins/gtk+/glade-gtk.c: Fixed add/remove parent commands so that they work with
    	parentless widget references (i.e. you can add a parent to a GtkToolItemGroup's label widget
    	or a GtkButton's image widget, or remove the parent of a child of a label-widget, etc).

 ChangeLog                |    4 +
 plugins/gtk+/glade-gtk.c |  252 +++++++++++++++++++++++++--------------------
 2 files changed, 144 insertions(+), 112 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7b4dc21..1891283 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,10 @@
 	plugins can create command groups that play with adding/removing widgets inline without
 	creating copies of them.
 
+	* plugins/gtk+/glade-gtk.c: Fixed add/remove parent commands so that they work with
+	parentless widget references (i.e. you can add a parent to a GtkToolItemGroup's label widget
+	or a GtkButton's image widget, or remove the parent of a child of a label-widget, etc).
+
 2011-04-29  Javier JardÃn <jjardon gnome org>
 
 	* gladeui/glade-utils.c: Correctly detect the required devhelp version
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 67fc953..aa8b517 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -1035,152 +1035,180 @@ create_command_property_list (GladeWidget *gnew, GList *saved_props)
 	return g_list_reverse (command_properties);
 }
 
-
 void
 glade_gtk_widget_action_activate (GladeWidgetAdaptor *adaptor,
 				  GObject *object,
 				  const gchar *action_path)
 {
 	GladeWidget *gwidget = glade_widget_get_from_gobject (object), *gparent;
-	GList       this_widget = { 0, }, that_widget = { 0, };
-	GtkWidget   *parent = gtk_widget_get_parent (GTK_WIDGET (object));
+	GList this_widget = { 0, }, that_widget = { 0,};
+	GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (object));
+	GladeProject *project;
 
 	if (parent)
 		gparent = glade_widget_get_from_gobject (parent);
 	else
 		gparent = NULL;
 
+	project = glade_widget_get_project (gwidget);
+
 	if (strcmp (action_path, "edit_separate") == 0)
 	{
-		GtkWidget *dialog = 
-			glade_editor_dialog_for_widget (gwidget);
+		GtkWidget *dialog = glade_editor_dialog_for_widget (gwidget);
 		gtk_widget_show_all (dialog);
 	}
 	else if (strcmp (action_path, "remove_parent") == 0)
 	{
 		GladeWidget *new_gparent;
+		GladeProperty *property;
 
 		g_return_if_fail (gparent);
-		new_gparent = gparent->parent;
-		
-		glade_command_push_group (_("Removing parent of %s"), 
-					  gwidget->name);
 
-		/* Remove "this" widget */
+		property = glade_widget_get_parentless_widget_ref (gparent);
+		new_gparent = glade_widget_get_parent (gparent);
+
+		glade_command_push_group (_("Removing parent of %s"), glade_widget_get_name (gwidget));
+
+		/* Remove "this" widget, If the parent we're removing is a parentless 
+		 * widget reference, the reference will be implicitly broken by the 'cut' command */
 		this_widget.data = gwidget;
-		glade_command_cut (&this_widget);
-		
+		glade_command_delete (&this_widget);
+
 		/* Delete the parent */
 		that_widget.data = gparent;
 		glade_command_delete (&that_widget);
 
-		/* Add "this" widget to the new parent */
-		glade_command_paste(&this_widget, new_gparent, NULL);
-		
+		/* Add "this" widget to the new parent, if there is no new parent this will re-add
+		 * the widget to the project at the toplevel without a parent
+		 */
+		glade_command_add (&this_widget, new_gparent, NULL, project, FALSE);
+
+		/* If the parent had a parentless widget reference, undoably add the child
+		 * as the new parentless widget reference here */
+		if (property)
+			glade_command_set_property (property, glade_widget_get_object (gwidget));
+
 		glade_command_pop_group ();
 	}
 	else if (strncmp (action_path, "add_parent/", 11) == 0)
 	{
 		GType new_type = 0;
-		
-		if (strcmp (action_path + 11, "alignment") == 0)
-			new_type = GTK_TYPE_ALIGNMENT;
-		else if (strcmp (action_path + 11, "viewport") == 0)
-			new_type = GTK_TYPE_VIEWPORT;
-		else if (strcmp (action_path + 11, "eventbox") == 0)
-			new_type = GTK_TYPE_EVENT_BOX;
-		else if (strcmp (action_path + 11, "frame") == 0)
-			new_type = GTK_TYPE_FRAME;
-		else if (strcmp (action_path + 11, "aspect_frame") == 0)
-			new_type = GTK_TYPE_ASPECT_FRAME;
-		else if (strcmp (action_path + 11, "scrolled_window") == 0)
-			new_type = GTK_TYPE_SCROLLED_WINDOW;
-		else if (strcmp (action_path + 11, "expander") == 0)
-			new_type = GTK_TYPE_EXPANDER;
-		else if (strcmp (action_path + 11, "table") == 0)
-			new_type = GTK_TYPE_TABLE;
-		else if (strcmp (action_path + 11, "hbox") == 0)
-			new_type = GTK_TYPE_HBOX;
-		else if (strcmp (action_path + 11, "vbox") == 0)
-			new_type = GTK_TYPE_VBOX;
-		else if (strcmp (action_path + 11, "hpaned") == 0)
-			new_type = GTK_TYPE_HPANED;
-		else if (strcmp (action_path + 11, "vpaned") == 0)
-			new_type = GTK_TYPE_VPANED;
-
-		
-		if (new_type)
-		{
-			GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (new_type);
-			GList              *saved_props, *prop_cmds;
-			GladeProject       *project;
-
-			/* Dont add non-scrollable widgets to scrolled windows... */
-			if (gparent &&
-			    glade_util_check_and_warn_scrollable (gparent, adaptor, glade_app_get_window()))
-				return;
-			
-			glade_command_push_group (_("Adding parent %s for %s"), 
-						  adaptor->title, gwidget->name);
-
-			/* Record packing properties */
-			saved_props = glade_widget_dup_properties (gwidget, gwidget->packing_properties, FALSE, FALSE, FALSE);
-			
-			/* Remove "this" widget */
-			this_widget.data = gwidget;
-			glade_command_cut (&this_widget);
-
-			if (gparent)
-				project = glade_widget_get_project (gparent);
-			else
-				project = glade_app_get_project ();
-			
-			/* Create new widget and put it where the placeholder was */
-			if ((that_widget.data =
-			     glade_command_create (adaptor, gparent, NULL, project)) != NULL)
-			{
-			
-				/* Remove the alignment that we added in the frame's post_create... */
-				if (new_type == GTK_TYPE_FRAME)
-				{
-					GObject     *frame = glade_widget_get_object (that_widget.data);
-					GladeWidget *galign = glade_widget_get_from_gobject (gtk_bin_get_child (GTK_BIN (frame)));
-					GList        to_delete = { 0, };
-					
-					to_delete.data = galign;
-					glade_command_delete (&to_delete);
-				}
-				
-				/* Create heavy-duty glade-command properties stuff */
-				prop_cmds = create_command_property_list (that_widget.data, saved_props);
-				g_list_foreach (saved_props, (GFunc)g_object_unref, NULL);
-				g_list_free (saved_props);
-				
-				/* Apply the properties in an undoable way */
-				if (prop_cmds)
-					glade_command_set_properties_list (glade_widget_get_project (gparent), prop_cmds);
-				
-				/* Add "this" widget to the new parent */
-				glade_command_paste(&this_widget, GLADE_WIDGET (that_widget.data), NULL);
-			}
-			else
-				/* Create parent was cancelled, paste back to parent */
-				glade_command_paste(&this_widget, gparent, NULL);
+		GladeProperty *property;
 
-			glade_command_pop_group ();
-		}
-	}
-	else if (strcmp (action_path, "sizegroup_add") == 0)
-	{
-		/* Ignore dummy */
-	}
-	else
-		GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
-								object,
-								action_path);
+      if (strcmp (action_path + 11, "alignment") == 0)
+        new_type = GTK_TYPE_ALIGNMENT;
+      else if (strcmp (action_path + 11, "viewport") == 0)
+        new_type = GTK_TYPE_VIEWPORT;
+      else if (strcmp (action_path + 11, "eventbox") == 0)
+        new_type = GTK_TYPE_EVENT_BOX;
+      else if (strcmp (action_path + 11, "frame") == 0)
+        new_type = GTK_TYPE_FRAME;
+      else if (strcmp (action_path + 11, "aspect_frame") == 0)
+        new_type = GTK_TYPE_ASPECT_FRAME;
+      else if (strcmp (action_path + 11, "scrolled_window") == 0)
+        new_type = GTK_TYPE_SCROLLED_WINDOW;
+      else if (strcmp (action_path + 11, "expander") == 0)
+        new_type = GTK_TYPE_EXPANDER;
+      else if (strcmp (action_path + 11, "table") == 0)
+        new_type = GTK_TYPE_TABLE;
+      else if (strcmp (action_path + 11, "hbox") == 0)
+        new_type = GTK_TYPE_HBOX;
+      else if (strcmp (action_path + 11, "vbox") == 0)
+        new_type = GTK_TYPE_VBOX;
+      else if (strcmp (action_path + 11, "hpaned") == 0)
+        new_type = GTK_TYPE_HPANED;
+      else if (strcmp (action_path + 11, "vpaned") == 0)
+        new_type = GTK_TYPE_VPANED;
+
+      if (new_type)
+        {
+          GladeWidgetAdaptor *adaptor =
+              glade_widget_adaptor_get_by_type (new_type);
+          GList *saved_props, *prop_cmds;
+	  GladeWidget *gnew_parent;
+
+          /* Dont add non-scrollable widgets to scrolled windows... */
+          if (gparent &&
+              glade_util_check_and_warn_scrollable (gparent, adaptor,
+                                                    glade_app_get_window ()))
+            return;
+
+          glade_command_push_group (_("Adding parent %s for %s"),
+                                    glade_widget_adaptor_get_title (adaptor), 
+				    glade_widget_get_name (gwidget));
+
+          /* Record packing properties */
+          saved_props =
+	    glade_widget_dup_properties (gwidget, glade_widget_get_packing_properties (gwidget),
+					 FALSE, FALSE, FALSE);
+
+
+	  property = glade_widget_get_parentless_widget_ref (gwidget);
+
+	  /* Remove "this" widget, If the parent we're removing is a parentless 
+	   * widget reference, the reference will be implicitly broken by the 'cut' command */
+          this_widget.data = gwidget;
+          glade_command_delete (&this_widget);
+
+          /* Create new widget and put it where the placeholder was */
+          if ((gnew_parent =
+               glade_command_create (adaptor, gparent, NULL, project)) != NULL)
+            {
+	      /* Now we created the new parent, if gwidget had a parentless widget reference...
+	       * set that reference to the new parent instead */
+	      if (property)
+		glade_command_set_property (property, glade_widget_get_object (gnew_parent));
+
+              /* Remove the alignment that we added in the frame's post_create... */
+              if (new_type == GTK_TYPE_FRAME)
+                {
+                  GObject *frame = glade_widget_get_object (gnew_parent);
+                  GladeWidget *galign =
+                      glade_widget_get_from_gobject (gtk_bin_get_child (GTK_BIN (frame)));
+                  GList to_delete = { 0, };
+
+                  to_delete.data = galign;
+                  glade_command_delete (&to_delete);
+                }
+
+              /* Create heavy-duty glade-command properties stuff */
+              prop_cmds =
+                  create_command_property_list (gnew_parent, saved_props);
+              g_list_foreach (saved_props, (GFunc) g_object_unref, NULL);
+              g_list_free (saved_props);
+
+              /* Apply the properties in an undoable way */
+              if (prop_cmds)
+                glade_command_set_properties_list 
+		  (glade_widget_get_project (gparent), prop_cmds);
+
+              /* Add "this" widget to the new parent */
+              glade_command_add (&this_widget, gnew_parent, NULL, project, FALSE);
+            }
+          else
+	    {
+	      /* Create parent was cancelled, paste back to parent */
+	      glade_command_add (&this_widget, gparent, NULL, project, FALSE);
+
+	      /* Restore any parentless widget reference if there was one */
+	      if (property)
+		glade_command_set_property (property, glade_widget_get_object (gwidget));
+	    }
+
+          glade_command_pop_group ();
+        }
+    }
+  else if (strcmp (action_path, "sizegroup_add") == 0)
+    {
+      /* Ignore dummy */
+    }
+  else
+    GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
+                                                    object, action_path);
 }
 
-static GList *list_sizegroups (GladeWidget *gwidget)
+static GList *
+list_sizegroups (GladeWidget *gwidget)
 {
 	GladeProject *project = glade_widget_get_project (gwidget);
 	GList *groups = NULL;



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