glade3 r2045 - in trunk: . gladeui plugins/gtk+
- From: tvb svn gnome org
- To: svn-commits-list gnome org
- Subject: glade3 r2045 - in trunk: . gladeui plugins/gtk+
- Date: Sun, 23 Nov 2008 23:49:54 +0000 (UTC)
Author: tvb
Date: Sun Nov 23 23:49:53 2008
New Revision: 2045
URL: http://svn.gnome.org/viewvc/glade3?rev=2045&view=rev
Log:
* gladeui/glade-command.c: Now add/remove parentless widget props from the project in
command_add/remove.
* gladeui/glade-widget.c:
- glade_widget_dup_properties/glade_widget_copy_properties take 2 new args, whether copy
parentless widget properties or not, and whether to copy them exactly or not.
- added glade_widget_get_parentless_reffed_widgets() to return a list of reffed parentless
widgets.
Modified:
trunk/ChangeLog
trunk/gladeui/glade-base-editor.c
trunk/gladeui/glade-command.c
trunk/gladeui/glade-property.c
trunk/gladeui/glade-widget.c
trunk/gladeui/glade-widget.h
trunk/plugins/gtk+/glade-gtk.c
Modified: trunk/gladeui/glade-base-editor.c
==============================================================================
--- trunk/gladeui/glade-base-editor.c (original)
+++ trunk/gladeui/glade-base-editor.c Sun Nov 23 23:49:53 2008
@@ -1302,7 +1302,7 @@
}
/* Copy properties */
- glade_widget_copy_properties (gchild_new, gchild);
+ glade_widget_copy_properties (gchild_new, gchild, TRUE, TRUE);
/* Delete old widget */
list.data = gchild;
Modified: trunk/gladeui/glade-command.c
==============================================================================
--- trunk/gladeui/glade-command.c (original)
+++ trunk/gladeui/glade-command.c Sun Nov 23 23:49:53 2008
@@ -61,6 +61,7 @@
GladeWidget *widget;
GladeWidget *parent;
GladeProject *project;
+ GList *reffed;
GladePlaceholder *placeholder;
gboolean props_recorded;
GList *pack_props;
@@ -986,7 +987,11 @@
/* Widget */
cdata->widget = g_object_ref (G_OBJECT (widget));
-
+
+ /* Parentless ref */
+ if ((cdata->reffed = glade_widget_get_parentless_reffed_widgets (widget)) != NULL)
+ g_list_foreach (cdata->reffed, (GFunc)g_object_ref, NULL);
+
/* Parent */
if (parent == NULL)
cdata->parent = glade_widget_get_parent (widget);
@@ -1150,7 +1155,9 @@
cdata->widget = g_object_ref (G_OBJECT (widget));
cdata->parent = glade_widget_get_parent (widget);
cdata->project = glade_widget_get_project (widget);
-
+ if ((cdata->reffed = glade_widget_get_parentless_reffed_widgets (widget)) != NULL)
+ g_list_foreach (cdata->reffed, (GFunc)g_object_ref, NULL);
+
/* Undoably unset any object properties that may point to the removed object */
glade_command_delete_prop_refs (widget);
@@ -1221,7 +1228,7 @@
static gboolean
glade_command_add_execute (GladeCommandAddRemove *me)
{
- GladeProject *active_project = glade_app_get_project ();
+ GladeProject *active_project = glade_app_get_project (), *add_project;
CommandData *cdata;
GList *list, *l, *saved_props;
gchar *special_child_type;
@@ -1261,7 +1268,8 @@
* otherwise prioritize packing defaults.
*/
saved_props =
- glade_widget_dup_properties (cdata->widget->packing_properties, FALSE);
+ glade_widget_dup_properties (cdata->widget->packing_properties,
+ FALSE, FALSE, FALSE);
glade_widget_set_packing_properties (cdata->widget, cdata->parent);
}
@@ -1341,13 +1349,15 @@
}
/* Toplevels get pasted to the active project */
- if (me->from_clipboard &&
- cdata->widget->parent == NULL)
- glade_project_add_object
- (active_project, cdata->project,
- cdata->widget->object);
- else
- glade_project_add_object(me->project, cdata->project, cdata->widget->object);
+ add_project = (me->from_clipboard && cdata->widget->parent == NULL) ?
+ active_project : me->project;
+ glade_project_add_object (add_project, cdata->project, cdata->widget->object);
+
+ for (l = cdata->reffed; l; l = l->next)
+ {
+ GladeWidget *reffed = l->data;
+ glade_project_add_object (add_project, cdata->project, reffed->object);
+ }
glade_app_selection_add(cdata->widget->object, FALSE);
@@ -1362,8 +1372,9 @@
static gboolean
glade_command_remove_execute (GladeCommandAddRemove *me)
{
- CommandData *cdata;
- GList *list;
+ CommandData *cdata;
+ GladeWidget *reffed;
+ GList *list, *l;
for (list = me->widgets; list && list->data; list = list->next)
{
@@ -1378,6 +1389,12 @@
}
glade_project_remove_object(GLADE_PROJECT (cdata->widget->project), cdata->widget->object);
+
+ for (l = cdata->reffed; l; l = l->next)
+ {
+ reffed = l->data;
+ glade_project_remove_object(GLADE_PROJECT (cdata->widget->project), reffed->object);
+ }
glade_widget_hide (cdata->widget);
}
@@ -1416,7 +1433,7 @@
{
GladeCommandAddRemove *cmd;
CommandData *cdata;
- GList *list;
+ GList *list, *l;
g_return_if_fail (GLADE_IS_COMMAND_ADD_REMOVE (obj));
@@ -1437,6 +1454,9 @@
if (cdata->widget)
g_object_unref (G_OBJECT (cdata->widget));
+
+ g_list_foreach (cdata->reffed, (GFunc)g_object_unref, NULL);
+ g_list_free (cdata->reffed);
}
g_list_free (cmd->widgets);
Modified: trunk/gladeui/glade-property.c
==============================================================================
--- trunk/gladeui/glade-property.c (original)
+++ trunk/gladeui/glade-property.c Sun Nov 23 23:49:53 2008
@@ -99,6 +99,7 @@
property->value = g_new0 (GValue, 1);
g_value_init (property->value, template_prop->value->g_type);
+
/* Cannot duplicate parentless_widget property */
if (template_prop->klass->parentless_widget)
{
Modified: trunk/gladeui/glade-widget.c
==============================================================================
--- trunk/gladeui/glade-widget.c (original)
+++ trunk/gladeui/glade-widget.c Sun Nov 23 23:49:53 2008
@@ -90,6 +90,7 @@
PROP_PARENT,
PROP_INTERNAL_NAME,
PROP_TEMPLATE,
+ PROP_TEMPLATE_EXACT,
PROP_REASON,
PROP_TOPLEVEL_WIDTH,
PROP_TOPLEVEL_HEIGHT,
@@ -519,7 +520,7 @@
}
if (template)
- params = glade_widget_template_params (template, TRUE, &n_params);
+ params = glade_widget_template_params (widget, TRUE, &n_params);
else
params = glade_widget_adaptor_default_params (widget->adaptor, TRUE, &n_params);
@@ -532,7 +533,7 @@
glade_widget_set_object (widget, object);
if (template)
- params = glade_widget_template_params (template, FALSE, &n_params);
+ params = glade_widget_template_params (widget, FALSE, &n_params);
else
params = glade_widget_adaptor_default_params (widget->adaptor, FALSE, &n_params);
@@ -548,6 +549,8 @@
* glade_widget_dup_properties:
* @template_props: the #GladeProperty list to copy
* @as_load: whether to behave as if loading the project
+ * @copy_parentless: whether to copy reffed widgets at all
+ * @exact: whether to copy reffed widgets exactly
*
* Copies a list of properties, if @as_load is specified, then
* properties that are not saved to the glade file are ignored.
@@ -555,7 +558,8 @@
* Returns: A newly allocated #GList of new #GladeProperty objects.
*/
GList *
-glade_widget_dup_properties (GList *template_props, gboolean as_load)
+glade_widget_dup_properties (GList *template_props, gboolean as_load,
+ gboolean copy_parentless, gboolean exact)
{
GList *list, *properties = NULL;
@@ -566,7 +570,30 @@
if (prop->klass->save == FALSE && as_load)
continue;
- properties = g_list_prepend (properties, glade_property_dup (prop, NULL));
+
+ if (prop->klass->parentless_widget && copy_parentless)
+ {
+ GObject *object = NULL;
+ GladeWidget *parentless;
+
+ glade_property_get (prop, &object);
+ if (object)
+ {
+ parentless = glade_widget_get_from_gobject (object);
+
+ parentless = glade_widget_dup (parentless, exact);
+
+ prop = glade_property_dup (prop, NULL);
+ glade_property_set (prop, parentless->object);
+ }
+ else
+ prop = glade_property_dup (prop, NULL);
+ }
+ else
+ prop = glade_property_dup (prop, NULL);
+
+
+ properties = g_list_prepend (properties, prop);
}
return g_list_reverse (properties);
}
@@ -688,7 +715,7 @@
if (gwidget->construct_template)
{
properties = glade_widget_dup_properties
- (gwidget->construct_template->properties, FALSE);
+ (gwidget->construct_template->properties, FALSE, TRUE, gwidget->construct_exact);
glade_widget_set_properties (gwidget, properties);
}
@@ -700,6 +727,18 @@
gwidget->construct_reason);
}
+ /* Copy sync parentless widget props here after a dup
+ */
+ if (gwidget->construct_reason == GLADE_CREATE_COPY)
+ {
+ for (list = gwidget->properties; list; list = list->next)
+ {
+ GladeProperty *property = list->data;
+ if (property->klass->parentless_widget)
+ glade_property_sync (property);
+ }
+ }
+
/* Setup width/height */
gwidget->width = GWA_DEFAULT_WIDTH (gwidget->adaptor);
gwidget->height = GWA_DEFAULT_HEIGHT (gwidget->adaptor);
@@ -855,6 +894,9 @@
case PROP_TEMPLATE:
widget->construct_template = g_value_get_object (value);
break;
+ case PROP_TEMPLATE_EXACT:
+ widget->construct_exact = g_value_get_boolean (value);
+ break;
case PROP_REASON:
widget->construct_reason = g_value_get_int (value);
break;
@@ -1068,6 +1110,12 @@
G_PARAM_CONSTRUCT_ONLY|G_PARAM_WRITABLE));
g_object_class_install_property
+ (object_class, PROP_TEMPLATE_EXACT,
+ g_param_spec_boolean ("template-exact", _("Exact Template"),
+ _("Whether we are creating an exact duplicate when using a template"),
+ FALSE, G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property
(object_class, PROP_REASON,
g_param_spec_int ("reason", _("Reason"),
_("A GladeCreateReason for this creation"),
@@ -1348,6 +1396,7 @@
"parent", parent,
"project", template_widget->project,
"template", template_widget,
+ "template-exact", exact,
"reason", GLADE_CREATE_COPY, NULL);
g_free (name);
}
@@ -1419,10 +1468,11 @@
}
if (gwidget->internal)
- glade_widget_copy_properties (gwidget, template_widget);
+ glade_widget_copy_properties (gwidget, template_widget, TRUE, exact);
if (gwidget->packing_properties == NULL)
- gwidget->packing_properties = glade_widget_dup_properties (template_widget->packing_properties , FALSE);
+ gwidget->packing_properties =
+ glade_widget_dup_properties (template_widget->packing_properties, FALSE, FALSE, FALSE);
/* If custom properties are still at thier
* default value, they need to be synced.
@@ -1489,7 +1539,7 @@
extract->internal_name = g_strdup (gchild->internal);
extract->internal_list = glade_widget_extract_children (gchild);
extract->properties =
- glade_widget_dup_properties (gchild->properties, TRUE);
+ glade_widget_dup_properties (gchild->properties, TRUE, FALSE, FALSE);
extract_list = g_list_prepend (extract_list, extract);
@@ -1506,7 +1556,7 @@
*/
extract->properties =
glade_widget_dup_properties
- (gchild->packing_properties, TRUE);
+ (gchild->packing_properties, TRUE, FALSE, FALSE);
glade_widget_remove_child (gwidget, gchild);
}
@@ -2011,6 +2061,31 @@
return NULL;
}
+
+GList *
+glade_widget_get_parentless_reffed_widgets (GladeWidget *widget)
+{
+ GladeWidget *reffed = NULL;
+ GladeProperty *property = NULL;
+ GList *l, *widgets = NULL;
+
+ g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
+
+ for (l = widget->properties; l && l->data; l = l->next)
+ {
+ property = GLADE_PROPERTY (l->data);
+ reffed = NULL;
+
+ if (property->klass->parentless_widget)
+ {
+ glade_property_get (property, &reffed);
+ if (reffed)
+ widgets = g_list_prepend (widgets, reffed);
+ }
+ }
+ return g_list_reverse (widgets);
+}
+
static void
glade_widget_accum_signal_foreach (const gchar *key,
GPtrArray *signals,
@@ -2088,13 +2163,17 @@
* glade_widget_copy_properties:
* @widget: a 'dest' #GladeWidget
* @template_widget: a 'src' #GladeWidget
+ * @copy_parentless: whether to copy reffed widgets at all
+ * @exact: whether to copy reffed widgets exactly
*
* Sets properties in @widget based on the values of
* matching properties in @template_widget
*/
void
glade_widget_copy_properties (GladeWidget *widget,
- GladeWidget *template_widget)
+ GladeWidget *template_widget,
+ gboolean copy_parentless,
+ gboolean exact)
{
GList *l;
@@ -2115,7 +2194,23 @@
glade_widget_get_property (template_widget,
widget_prop->klass->id)) != NULL &&
glade_property_class_match (template_prop->klass, widget_prop->klass))
- glade_property_set_value (widget_prop, template_prop->value);
+ {
+ if (template_prop->klass->parentless_widget && copy_parentless)
+ {
+ GObject *object = NULL;
+ GladeWidget *parentless;
+
+ glade_property_get (template_prop, &object);
+ g_assert (object);
+
+ parentless = glade_widget_get_from_gobject (object);
+ parentless = glade_widget_dup (parentless, exact);
+
+ glade_property_set (widget_prop, parentless->object);
+ }
+ else
+ glade_property_set_value (widget_prop, template_prop->value);
+ }
}
}
@@ -2210,7 +2305,6 @@
g_return_if_fail (GLADE_IS_WIDGET (gwidget));
-
adaptor = gwidget->adaptor;
/* Here we take care removing the widget from the project and
Modified: trunk/gladeui/glade-widget.h
==============================================================================
--- trunk/gladeui/glade-widget.h (original)
+++ trunk/gladeui/glade-widget.h Sun Nov 23 23:49:53 2008
@@ -112,6 +112,7 @@
GladeWidget *construct_template;
GladeCreateReason construct_reason;
gchar *construct_internal;
+ gboolean construct_exact;
};
struct _GladeWidgetClass
@@ -162,7 +163,9 @@
void glade_widget_copy_signals (GladeWidget *widget,
GladeWidget *template_widget);
void glade_widget_copy_properties (GladeWidget *widget,
- GladeWidget *template_widget);
+ GladeWidget *template_widget,
+ gboolean copy_parentless,
+ gboolean exact);
void glade_widget_set_packing_properties (GladeWidget *widget,
GladeWidget *container);
@@ -174,7 +177,9 @@
const gchar *id_property);
GList *glade_widget_dup_properties (GList *template_props,
- gboolean as_load);
+ gboolean as_load,
+ gboolean copy_parentless,
+ gboolean exact);
void glade_widget_remove_property (GladeWidget *widget,
const gchar *id_property);
@@ -275,6 +280,9 @@
GladeProperty *glade_widget_get_parentless_widget_ref (GladeWidget *widget);
+
+GList *glade_widget_get_parentless_reffed_widgets (GladeWidget *widget);
+
/*******************************************************************************
Functions that deal with properties on the runtime object
*******************************************************************************/
Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c (original)
+++ trunk/plugins/gtk+/glade-gtk.c Sun Nov 23 23:49:53 2008
@@ -1272,7 +1272,7 @@
adaptor->title, gwidget->name);
/* Record packing properties */
- saved_props = glade_widget_dup_properties (gwidget->packing_properties, FALSE);
+ saved_props = glade_widget_dup_properties (gwidget->packing_properties, FALSE, FALSE, FALSE);
/* Remove "this" widget */
this_widget.data = gwidget;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]