Commit 1d28bf2c authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

Added 'exact' argument to glade_widget_dup() and added


	* gladeui/glade-widget.[ch]: Added 'exact' argument to glade_widget_dup() and
	  added glade_widget_copy_signals()

	* gladeui/glade-command.c: dup the widget "exactly" when pasting widgets that
	  were cut (not copied), fixing bug 432519


svn path=/trunk/; revision=1287
parent 60605d63
2007-05-01 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-widget.[ch]: Added 'exact' argument to glade_widget_dup() and
added glade_widget_copy_signals()
* gladeui/glade-command.c: dup the widget "exactly" when pasting widgets that
were cut (not copied), fixing bug 432519
2007-04-26 Jeff Westerinen <jeff.westerinen@access-company.com>
* plugins/gtk+/glade-gtk.c:
......
......@@ -1576,10 +1576,14 @@ void
glade_command_cut(GList *widgets)
{
GladeWidget *widget;
GList *l;
gchar *description;
g_return_if_fail (widgets != NULL);
for (l = widgets; l; l = l->next)
g_object_set_data (G_OBJECT (l->data), "glade-command-was-cut", GINT_TO_POINTER (TRUE));
widget = widgets->data;
description = g_strdup_printf (_("Cut %s"), g_list_length (widgets) == 1 ? widget->name : _("multiple"));
glade_command_push_group(description);
......@@ -1597,24 +1601,24 @@ glade_command_cut(GList *widgets)
void
glade_command_copy(GList *widgets)
{
GList *list, *copiedWidgets = NULL;
GladeWidget *copiedWidget = NULL;
GList *list, *copied_widgets = NULL;
GladeWidget *copied_widget = NULL;
gchar *description;
g_return_if_fail (widgets != NULL);
for (list = widgets; list && list->data; list = list->next)
{
copiedWidget = glade_widget_dup(list->data);
copiedWidgets = g_list_prepend(copiedWidgets, copiedWidget);
copied_widget = glade_widget_dup(list->data, FALSE);
copied_widgets = g_list_prepend(copied_widgets, copied_widget);
}
description = g_strdup_printf (_("Copy %s"), g_list_length (widgets) == 1 ? copiedWidget->name : _("multiple"));
description = g_strdup_printf (_("Copy %s"), g_list_length (widgets) == 1 ? copied_widget->name : _("multiple"));
glade_command_push_group(description);
glade_command_clipboard_add(copiedWidgets);
glade_command_clipboard_add(copied_widgets);
glade_command_pop_group();
if (copiedWidgets)
g_list_free(copiedWidgets);
if (copied_widgets)
g_list_free(copied_widgets);
}
/**
......@@ -1630,24 +1634,27 @@ glade_command_copy(GList *widgets)
void
glade_command_paste(GList *widgets, GladeWidget *parent, GladePlaceholder *placeholder)
{
GList *list, *copiedWidgets = NULL;
GladeWidget *copiedWidget = NULL;
GList *list, *copied_widgets = NULL;
GladeWidget *copied_widget = NULL;
gchar *description;
gboolean exact;
g_return_if_fail (widgets != NULL);
for (list = widgets; list && list->data; list = list->next)
{
copiedWidget = glade_widget_dup(list->data);
copiedWidgets = g_list_prepend(copiedWidgets, copiedWidget);
exact = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (list->data), "glade-command-was-cut"));
copied_widget = glade_widget_dup(list->data, exact);
copied_widgets = g_list_prepend(copied_widgets, copied_widget);
}
description = g_strdup_printf (_("Paste %s"), g_list_length (widgets) == 1 ? copiedWidget->name : _("multiple"));
description = g_strdup_printf (_("Paste %s"), g_list_length (widgets) == 1 ? copied_widget->name : _("multiple"));
glade_command_push_group(description);
glade_command_add(copiedWidgets, parent, placeholder, TRUE);
glade_command_add(copied_widgets, parent, placeholder, TRUE);
glade_command_pop_group();
if (copiedWidgets)
g_list_free(copiedWidgets);
if (copied_widgets)
g_list_free(copied_widgets);
}
/**
......
......@@ -1301,7 +1301,9 @@ glade_widget_get_internal_func (GladeWidget *parent, GladeWidget **parent_ret)
static GladeWidget *
glade_widget_dup_internal (GladeWidget *parent, GladeWidget *template_widget)
glade_widget_dup_internal (GladeWidget *parent,
GladeWidget *template_widget,
gboolean exact)
{
GladeGetInternalFunc get_internal;
GladeWidget *gwidget = NULL, *internal_parent;
......@@ -1336,7 +1338,14 @@ glade_widget_dup_internal (GladeWidget *parent, GladeWidget *template_widget)
}
else
{
gchar *name = glade_project_new_widget_name (template_widget->project, template_widget->name);
gchar *name;
if (exact)
name = g_strdup (template_widget->name);
else
name = glade_project_new_widget_name (template_widget->project,
template_widget->name);
gwidget = glade_widget_adaptor_create_widget
(template_widget->adaptor, FALSE,
"name", name,
......@@ -1346,7 +1355,11 @@ glade_widget_dup_internal (GladeWidget *parent, GladeWidget *template_widget)
"reason", GLADE_CREATE_COPY, NULL);
g_free (name);
}
/* Copy signals over here regardless of internal or not... */
if (exact)
glade_widget_copy_signals (gwidget, template_widget);
if ((children =
glade_widget_adaptor_get_children (template_widget->adaptor,
template_widget->object)) != NULL)
......@@ -1379,7 +1392,7 @@ glade_widget_dup_internal (GladeWidget *parent, GladeWidget *template_widget)
else
{
/* Recurse through every GladeWidget (internal or not) */
child_dup = glade_widget_dup_internal (gwidget, child_gwidget);
child_dup = glade_widget_dup_internal (gwidget, child_gwidget, exact);
if (child_gwidget->internal == NULL)
{
......@@ -2223,6 +2236,41 @@ glade_widget_project_notify (GladeWidget *widget, GladeProject *project)
widget->prop_refs_readonly = FALSE;
}
static void
glade_widget_copy_signal_foreach (const gchar *key,
GPtrArray *signals,
GladeWidget *dest)
{
GladeSignal *signal;
gint i;
for (i = 0; i < signals->len; i++)
{
signal = (GladeSignal *)signals->pdata[i];
glade_widget_add_signal_handler (dest, signal);
}
}
/**
* glade_widget_copy_signals:
* @widget: a 'dest' #GladeWidget
* @template_widget: a 'src' #GladeWidget
*
* Sets signals in @widget based on the values of
* matching signals in @template_widget
*/
void
glade_widget_copy_signals (GladeWidget *widget,
GladeWidget *template_widget)
{
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET (template_widget));
g_hash_table_foreach (template_widget->signals,
(GHFunc)glade_widget_copy_signal_foreach,
widget);
}
/**
* glade_widget_copy_properties:
* @widget: a 'dest' #GladeWidget
......@@ -2236,6 +2284,10 @@ glade_widget_copy_properties (GladeWidget *widget,
GladeWidget *template_widget)
{
GList *l;
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET (template_widget));
for (l = widget->properties; l && l->data; l = l->next)
{
GladeProperty *widget_prop = GLADE_PROPERTY(l->data);
......@@ -2294,20 +2346,25 @@ glade_widget_remove_child (GladeWidget *parent,
/**
* glade_widget_dup:
* @template_widget: a #GladeWidget
* @exact: whether or not to creat an exact duplicate
*
* Creates a deep copy of #GladeWidget.
* Creates a deep copy of #GladeWidget. if @exact is specified,
* the widget name is preserved and signals are carried over
* (this is used to maintain names & signals in Cut/Paste context
* as opposed to Copy/Paste contexts).
*
* Returns: The newly created #GladeWidget
*/
GladeWidget *
glade_widget_dup (GladeWidget *template_widget)
glade_widget_dup (GladeWidget *template_widget,
gboolean exact)
{
GladeWidget *widget;
g_return_val_if_fail (GLADE_IS_WIDGET (template_widget), NULL);
glade_widget_push_superuser ();
widget = glade_widget_dup_internal (NULL, template_widget);
widget = glade_widget_dup_internal (NULL, template_widget, exact);
glade_widget_pop_superuser ();
return widget;
......
......@@ -142,8 +142,10 @@ void glade_widget_replace (GladeWidget *p
void glade_widget_rebuild (GladeWidget *gwidget);
GladeWidget *glade_widget_dup (GladeWidget *template_widget);
GladeWidget *glade_widget_dup (GladeWidget *template_widget,
gboolean exact);
void glade_widget_copy_signals (GladeWidget *widget,
GladeWidget *template_widget);
void glade_widget_copy_properties (GladeWidget *widget,
GladeWidget *template_widget);
......
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