summaryrefslogtreecommitdiff
path: root/gladeui
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <juanpablougarte@gmail.com>2020-09-21 19:37:44 -0300
committerJuan Pablo Ugarte <juanpablougarte@gmail.com>2020-09-25 16:31:27 -0300
commitccd09e9d86a52af5f720b2e79bd4f2ca7a1f1ddd (patch)
tree258a63f4c5dad2b3edc89d610d8b5235de7d7f9f /gladeui
parentfe428062ac9713202a563f055709ff98dd55ac6f (diff)
downloadglade-ccd09e9d86a52af5f720b2e79bd4f2ca7a1f1ddd.tar.gz
GladeCommand: adjust Box and Grid size automatically
Adjust container size in create and paste command. Properly fix issue #470 "Widgets of type need placeholders to add children"
Diffstat (limited to 'gladeui')
-rw-r--r--gladeui/glade-command.c45
-rw-r--r--gladeui/glade-popup.c53
-rw-r--r--gladeui/glade-project.c30
3 files changed, 41 insertions, 87 deletions
diff --git a/gladeui/glade-command.c b/gladeui/glade-command.c
index ef87e99b..c5f31398 100644
--- a/gladeui/glade-command.c
+++ b/gladeui/glade-command.c
@@ -1758,6 +1758,42 @@ glade_command_add_remove_collapse (GladeCommand *this_cmd,
g_return_if_reached ();
}
+static void
+adjust_container_size (GladeWidget *parent, gint children)
+{
+ gint placeholders;
+ GObject *gparent;
+
+ if (!parent)
+ return;
+
+ placeholders = glade_util_count_placeholders (parent);
+ gparent = glade_widget_get_object (parent);
+
+ if ((GTK_IS_BOX (gparent) || GTK_IS_GRID (gparent)) && placeholders < children)
+ {
+ children -= placeholders;
+
+ if (GTK_IS_BOX (gparent))
+ {
+ GladeProperty *prop = glade_widget_get_property (parent, "size");
+ gint size;
+
+ glade_property_get (prop, &size);
+ glade_command_set_property (prop, size + children);
+ }
+ else
+ {
+ GladeProperty *row = glade_widget_get_property (parent, "n-rows");
+ gint ncol, nrow;
+
+ glade_widget_property_get (parent, "n-columns", &ncol);
+ glade_property_get (row, &nrow);
+ glade_command_set_property (row, nrow + (children / ncol) + ((children % ncol) ? 1 : 0));
+ }
+ }
+}
+
/******************************************************************************
*
* The following are command aliases. Their implementations are the actual
@@ -1807,6 +1843,7 @@ glade_command_create (GladeWidgetAdaptor *adaptor,
widgets.data = widget;
glade_command_push_group (_("Create %s"), glade_widget_get_display_name (widget));
+ adjust_container_size (parent, 1);
glade_command_add (&widgets, parent, placeholder, project, FALSE);
glade_command_pop_group ();
@@ -1946,6 +1983,7 @@ glade_command_paste (GList *widgets,
GList *list, *copied_widgets = NULL;
GladeWidget *copied_widget = NULL;
gboolean exact;
+ gint len;
g_return_if_fail (widgets != NULL);
@@ -1959,10 +1997,9 @@ glade_command_paste (GList *widgets,
copied_widgets = g_list_prepend (copied_widgets, copied_widget);
}
- glade_command_push_group (_("Paste %s"),
- g_list_length (widgets) == 1 ?
- glade_widget_get_display_name (copied_widget) : _("multiple"));
-
+ len = g_list_length (widgets);
+ glade_command_push_group (_("Paste %s"), len == 1 ? glade_widget_get_display_name (copied_widget) : _("multiple"));
+ adjust_container_size (parent, len);
glade_command_add (copied_widgets, parent, placeholder, project, TRUE);
glade_command_pop_group ();
diff --git a/gladeui/glade-popup.c b/gladeui/glade-popup.c
index 997eafba..1a74d70f 100644
--- a/gladeui/glade-popup.c
+++ b/gladeui/glade-popup.c
@@ -63,59 +63,16 @@ typedef struct {
GladePlaceholder *placeholder;
} RootAddData;
-static gboolean
-special_case_box_and_grid_size (GladeWidget *parent, gint children)
-{
- gint placeholders = glade_util_count_placeholders (parent);
- GObject *gparent = glade_widget_get_object (parent);
-
- if ((GTK_IS_BOX (gparent) || GTK_IS_GRID (gparent)) && placeholders < children)
- {
- glade_command_push_group (_("Create %s"), G_OBJECT_TYPE_NAME (gparent));
-
- children -= placeholders;
-
- if (GTK_IS_BOX (gparent))
- {
- GladeProperty *prop = glade_widget_get_property (parent, "size");
- gint size;
-
- glade_property_get (prop, &size);
- glade_command_set_property (prop, size + children);
- }
- else
- {
- GladeProperty *row = glade_widget_get_property (parent, "n-rows");
- gint ncol, nrow;
-
- glade_widget_property_get (parent, "n-columns", &ncol);
- glade_property_get (row, &nrow);
- glade_command_set_property (row, nrow + (children / ncol) + ((children % ncol) ? 1 : 0));
- }
-
- return TRUE;
- }
-
- return FALSE;
-}
-
static void
glade_popup_widget_add_cb (GtkMenuItem *item, RootAddData *data)
{
- gboolean modified;
-
g_return_if_fail (data->adaptor != NULL);
- modified = special_case_box_and_grid_size (data->parent, 1);
-
if (glade_command_create (data->adaptor,
data->parent,
data->placeholder,
data->project))
glade_project_set_add_item (data->project, NULL);
-
- if (modified)
- glade_command_pop_group();
}
static void
@@ -154,19 +111,12 @@ static void
glade_popup_paste_cb (GtkMenuItem *item, gpointer data)
{
GladeWidget *widget = NULL;
- gboolean modified = FALSE;
GladeProject *project;
if (GLADE_IS_WIDGET (data))
{
- GladeClipboard *clipboard = glade_app_get_clipboard ();
- gint clipboard_size;
-
widget = GLADE_WIDGET (data);
project = glade_widget_get_project (widget);
-
- clipboard_size = g_list_length (glade_clipboard_widgets (clipboard));
- modified = special_case_box_and_grid_size (widget, clipboard_size);
}
else if (GLADE_IS_PROJECT (data))
project = GLADE_PROJECT (data);
@@ -180,9 +130,6 @@ glade_popup_paste_cb (GtkMenuItem *item, gpointer data)
glade_project_selection_clear (project, FALSE);
glade_project_command_paste (project, NULL);
-
- if (modified)
- glade_command_pop_group();
}
static void
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 829b45a6..aa48aee9 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -5408,36 +5408,6 @@ glade_project_command_paste (GladeProject *project,
}
}
- g_assert (widget);
-
- /* A GladeWidget that doesnt use placeholders can only paste one
- * at a time
- *
- * XXX: Not sure if this has to be true.
- */
- if (GTK_IS_WIDGET (glade_widget_get_object (widget)) &&
- parent && !GLADE_WIDGET_ADAPTOR_USE_PLACEHOLDERS (glade_widget_get_adaptor (parent)) &&
- g_list_length (glade_clipboard_widgets (clipboard)) != 1)
- {
- glade_util_ui_message (glade_app_get_window (),
- GLADE_UI_INFO, NULL,
- _("Only one widget can be pasted at a "
- "time to this container"));
- return;
- }
-
- /* Check that enough placeholders are available */
- if (parent &&
- GLADE_WIDGET_ADAPTOR_USE_PLACEHOLDERS (glade_widget_get_adaptor (parent)) &&
- glade_util_count_placeholders (parent) < placeholder_relations)
- {
- glade_util_ui_message (glade_app_get_window (),
- GLADE_UI_INFO, NULL,
- _("Insufficient amount of placeholders in "
- "target container"));
- return;
- }
-
glade_command_paste (glade_clipboard_widgets (clipboard), parent, placeholder, project);
}