[glade] GladePopup: special case add to box/grid



commit a72c4fca91a5183723bc1558abbc8eed6eef4889
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Thu Sep 17 21:08:28 2020 -0300

    GladePopup: special case add to box/grid
    
    Increase size of grid/box if there is no space to add a widget in the container
    
    Fix issue #470 "Widgets of type need placeholders to add children"

 gladeui/glade-popup.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gladeui/glade-popup.c b/gladeui/glade-popup.c
index 28621634..6e437793 100644
--- a/gladeui/glade-popup.c
+++ b/gladeui/glade-popup.c
@@ -66,12 +66,41 @@ typedef struct {
 static void
 glade_popup_widget_add_cb (GtkMenuItem *item, RootAddData *data)
 {
+  gboolean use_group = FALSE;
+  GObject *parent;
+
   g_return_if_fail (data->adaptor != NULL);
 
-  if (glade_command_create (data->adaptor, data->parent,
-                            data->placeholder, data->project))
+  parent = glade_widget_get_object (data->parent);
+
+  if ((GTK_IS_BOX (parent) || GTK_IS_GRID (parent)) &&
+      glade_util_count_placeholders (data->parent) == 0)
+    {
+      GladeProperty *prop;
+      gint value;
+
+      glade_command_push_group (_("Create %s"),
+                                glade_widget_adaptor_get_name (data->adaptor));
+
+      if (GTK_IS_BOX (parent))
+        prop = glade_widget_get_property (data->parent, "size");
+      else
+        prop = glade_widget_get_property (data->parent, "n-columns");
+
+      glade_property_get (prop, &value);
+      glade_command_set_property (prop, ++value);
 
+      use_group = TRUE;
+    }
+
+  if (glade_command_create (data->adaptor,
+                            data->parent,
+                            data->placeholder,
+                            data->project))
     glade_project_set_add_item (data->project, NULL);
+
+  if (use_group)
+    glade_command_pop_group();
 }
 
 static void


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