Commit 060ed587 authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

GladePopup: improve paste and add here actions

Support adding widgets to GtkBox and GtkGrid even if there are no placeholders

Fix issue #470 "Widgets of type need placeholders to add children"
parent a72c4fca
......@@ -63,43 +63,58 @@ typedef struct {
GladePlaceholder *placeholder;
} RootAddData;
static void
glade_popup_widget_add_cb (GtkMenuItem *item, RootAddData *data)
static gboolean
special_case_box_and_grid_size (GladeWidget *parent, gint children)
{
gboolean use_group = FALSE;
GObject *parent;
g_return_if_fail (data->adaptor != NULL);
parent = glade_widget_get_object (data->parent);
gint placeholders = glade_util_count_placeholders (parent);
GObject *gparent = glade_widget_get_object (parent);
if ((GTK_IS_BOX (parent) || GTK_IS_GRID (parent)) &&
glade_util_count_placeholders (data->parent) == 0)
if ((GTK_IS_BOX (gparent) || GTK_IS_GRID (gparent)) && placeholders < children)
{
GladeProperty *prop;
gint value;
glade_command_push_group (_("Create %s"), G_OBJECT_TYPE_NAME (gparent));
children -= placeholders;
glade_command_push_group (_("Create %s"),
glade_widget_adaptor_get_name (data->adaptor));
if (GTK_IS_BOX (gparent))
{
GladeProperty *prop = glade_widget_get_property (parent, "size");
gint size;
if (GTK_IS_BOX (parent))
prop = glade_widget_get_property (data->parent, "size");
glade_property_get (prop, &size);
glade_command_set_property (prop, size + children);
}
else
prop = glade_widget_get_property (data->parent, "n-columns");
{
GladeProperty *row = glade_widget_get_property (parent, "n-rows");
gint ncol, nrow;
glade_property_get (prop, &value);
glade_command_set_property (prop, ++value);
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));
}
use_group = TRUE;
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 (use_group)
if (modified)
glade_command_pop_group();
}
......@@ -139,12 +154,19 @@ 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);
......@@ -158,6 +180,9 @@ 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment