Commit ccd09e9d authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

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"
parent fe428062
......@@ -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 ();
......
......@@ -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
......
......@@ -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);
}
......
......@@ -83,6 +83,9 @@ glade_gtk_container_add_verify (GladeWidgetAdaptor *adaptor,
return FALSE;
}
else if (GTK_IS_BOX (container) || GTK_IS_GRID (container))
/* GtkBox and GtkGrid size is adjusted automaticaly in GladeCommand */
return TRUE;
else if (GLADE_WIDGET_ADAPTOR_USE_PLACEHOLDERS (adaptor) &&
/* Special case GtkBin since Windows can hace a placeholder in the titlebar */
((GTK_IS_BIN (container) &&
......
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