From b5ff3b5bbb13e7ebb5791bb983975a14ec6f212c Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 19 Feb 2011 21:08:18 +0100 Subject: Don't emit changes when reading. When the value for a property isn't present in it's JsonObject, it can be assigned upon reading. Previously this could generate history events even when just viewing an old diagram with some of newer properties missing. Modify the code, so setting to default doesn't count as a change anymore. --- liblogdiag/ld-diagram-object.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/liblogdiag/ld-diagram-object.c b/liblogdiag/ld-diagram-object.c index b0ae76b..684e93f 100644 --- a/liblogdiag/ld-diagram-object.c +++ b/liblogdiag/ld-diagram-object.c @@ -25,10 +25,12 @@ /* * LdDiagramObjectPrivate: * @storage: storage for object parameters. + * @lock_history: lock emitting of changes. */ struct _LdDiagramObjectPrivate { JsonObject *storage; + gboolean lock_history; }; typedef struct _SetParamActionData SetParamActionData; @@ -309,7 +311,10 @@ ld_diagram_object_get_data_warn: ld_diagram_object_get_data_default: g_param_value_set_default (pspec, data); + + self->priv->lock_history = TRUE; g_object_set_property (G_OBJECT (self), name, data); + self->priv->lock_history = FALSE; } /** @@ -328,7 +333,7 @@ ld_diagram_object_set_data_for_param (LdDiagramObject *self, SetParamActionData *action_data; JsonObject *storage; const gchar *name; - JsonNode *node; + JsonNode *new_node, *old_node; g_return_if_fail (LD_IS_DIAGRAM_OBJECT (self)); g_return_if_fail (G_IS_VALUE (data)); @@ -337,23 +342,31 @@ ld_diagram_object_set_data_for_param (LdDiagramObject *self, storage = ld_diagram_object_get_storage (self); name = g_param_spec_get_name (pspec); - action_data = g_slice_new (SetParamActionData); - action_data->self = g_object_ref (self); - action_data->param_name = g_strdup (g_param_spec_get_name (pspec)); + if (!self->priv->lock_history) + { + action_data = g_slice_new (SetParamActionData); + action_data->self = g_object_ref (self); + action_data->param_name = g_strdup (g_param_spec_get_name (pspec)); - node = json_object_get_member (storage, name); - action_data->old_node = node ? json_node_copy (node) : NULL; + old_node = json_object_get_member (storage, name); + action_data->old_node = old_node ? json_node_copy (old_node) : NULL; + } + + new_node = json_node_new (JSON_NODE_VALUE); + json_node_set_value (new_node, data); - node = json_node_new (JSON_NODE_VALUE); - json_node_set_value (node, data); - action_data->new_node = json_node_copy (node); + if (!self->priv->lock_history) + action_data->new_node = json_node_copy (new_node); - json_object_set_member (storage, name, node); + json_object_set_member (storage, name, new_node); - action = ld_undo_action_new (on_set_param_undo, on_set_param_redo, - on_set_param_destroy, action_data); - ld_diagram_object_changed (self, action); - g_object_unref (action); + if (!self->priv->lock_history) + { + action = ld_undo_action_new (on_set_param_undo, on_set_param_redo, + on_set_param_destroy, action_data); + ld_diagram_object_changed (self, action); + g_object_unref (action); + } } static void -- cgit v1.2.3-70-g09d2