Commit a10762dc authored by Tristan Van Berkom's avatar Tristan Van Berkom

Now add/remove parentless widget props from the project in


	* 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.


svn path=/trunk/; revision=2045
parent 82c2cad3
2008-11-23 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-widget.c: glade_widget_build_object() now calls glade_widget_set_object()
internally and then uses glade_widget_adaptor_set_property() for non construct properties.
* gladeui/glade-widget.c:
- glade_widget_build_object() now calls glade_widget_set_object() internally and then
uses glade_widget_adaptor_set_property() for non construct properties.
- 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.
* gladeui/glade-command.c: Now add/remove parentless widget props from the project in
command_add/remove.
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in:
- Made GtkTreeView:model property query user at create time.
- Fixed to never sync properties when in attribute mode, to sync attributes
......
......@@ -1302,7 +1302,7 @@ glade_base_editor_change_type (GladeBaseEditor *editor,
}
/* Copy properties */
glade_widget_copy_properties (gchild_new, gchild);
glade_widget_copy_properties (gchild_new, gchild, TRUE, TRUE);
/* Delete old widget */
list.data = gchild;
......
......@@ -61,6 +61,7 @@ typedef struct {
GladeWidget *widget;
GladeWidget *parent;
GladeProject *project;
GList *reffed;
GladePlaceholder *placeholder;
gboolean props_recorded;
GList *pack_props;
......@@ -986,7 +987,11 @@ glade_command_add (GList *widgets,
/* 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 @@ glade_command_remove (GList *widgets)
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 @@ glade_command_transfer_props (GladeWidget *gnew, GList *saved_props)
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 @@ glade_command_add_execute (GladeCommandAddRemove *me)
* 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 @@ glade_command_add_execute (GladeCommandAddRemove *me)
}
/* 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 @@ glade_command_add_execute (GladeCommandAddRemove *me)
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_command_remove_execute (GladeCommandAddRemove *me)
}
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 @@ glade_command_add_remove_finalize (GObject *obj)
{
GladeCommandAddRemove *cmd;
CommandData *cdata;
GList *list;
GList *list, *l;
g_return_if_fail (GLADE_IS_COMMAND_ADD_REMOVE (obj));
......@@ -1437,6 +1454,9 @@ glade_command_add_remove_finalize (GObject *obj)
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);
......
......@@ -99,6 +99,7 @@ glade_property_dup_impl (GladeProperty *template_prop, GladeWidget *widget)
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)
{
......
......@@ -90,6 +90,7 @@ enum
PROP_PARENT,
PROP_INTERNAL_NAME,
PROP_TEMPLATE,
PROP_TEMPLATE_EXACT,
PROP_REASON,
PROP_TOPLEVEL_WIDTH,
PROP_TOPLEVEL_HEIGHT,
......@@ -519,7 +520,7 @@ glade_widget_build_object (GladeWidget *widget,
}
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_build_object (GladeWidget *widget,
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_build_object (GladeWidget *widget,
* 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 @@ glade_widget_build_object (GladeWidget *widget,
* 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 @@ glade_widget_dup_properties (GList *template_props, gboolean as_load)
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 @@ glade_widget_constructor (GType type,
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 @@ glade_widget_constructor (GType type,
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 @@ glade_widget_set_real_property (GObject *object,
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;
......@@ -1067,6 +1109,12 @@ glade_widget_class_init (GladeWidgetClass *klass)
GLADE_TYPE_WIDGET,
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"),
......@@ -1348,6 +1396,7 @@ glade_widget_dup_internal (GladeWidget *parent,
"parent", parent,
"project", template_widget->project,
"template", template_widget,
"template-exact", exact,
"reason", GLADE_CREATE_COPY, NULL);
g_free (name);
}
......@@ -1419,10 +1468,11 @@ glade_widget_dup_internal (GladeWidget *parent,
}
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 @@ glade_widget_extract_children (GladeWidget *gwidget)
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 @@ glade_widget_extract_children (GladeWidget *gwidget)
*/
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 @@ glade_widget_get_parentless_widget_ref (GladeWidget *widget)
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_signals (GladeWidget *widget,
* 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_copy_properties (GladeWidget *widget,
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 @@ glade_widget_rebuild (GladeWidget *gwidget)
g_return_if_fail (GLADE_IS_WIDGET (gwidget));
adaptor = gwidget->adaptor;
/* Here we take care removing the widget from the project and
......
......@@ -112,6 +112,7 @@ struct _GladeWidget
GladeWidget *construct_template;
GladeCreateReason construct_reason;
gchar *construct_internal;
gboolean construct_exact;
};
struct _GladeWidgetClass
......@@ -162,7 +163,9 @@ GList *glade_widget_get_signal_list (GladeWidget *w
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 @@ GladeProperty *glade_widget_get_pack_property (GladeWidget *w
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 @@ void glade_widget_remove_prop_ref (GladeWidget *w
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
*******************************************************************************/
......
......@@ -1272,7 +1272,7 @@ glade_gtk_widget_action_activate (GladeWidgetAdaptor *adaptor,
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;
......
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