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.
This commit is contained in:
parent
58e3e43c15
commit
b5ff3b5bbb
@ -25,10 +25,12 @@
|
|||||||
/*
|
/*
|
||||||
* LdDiagramObjectPrivate:
|
* LdDiagramObjectPrivate:
|
||||||
* @storage: storage for object parameters.
|
* @storage: storage for object parameters.
|
||||||
|
* @lock_history: lock emitting of changes.
|
||||||
*/
|
*/
|
||||||
struct _LdDiagramObjectPrivate
|
struct _LdDiagramObjectPrivate
|
||||||
{
|
{
|
||||||
JsonObject *storage;
|
JsonObject *storage;
|
||||||
|
gboolean lock_history;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _SetParamActionData SetParamActionData;
|
typedef struct _SetParamActionData SetParamActionData;
|
||||||
@ -309,7 +311,10 @@ ld_diagram_object_get_data_warn:
|
|||||||
|
|
||||||
ld_diagram_object_get_data_default:
|
ld_diagram_object_get_data_default:
|
||||||
g_param_value_set_default (pspec, data);
|
g_param_value_set_default (pspec, data);
|
||||||
|
|
||||||
|
self->priv->lock_history = TRUE;
|
||||||
g_object_set_property (G_OBJECT (self), name, data);
|
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;
|
SetParamActionData *action_data;
|
||||||
JsonObject *storage;
|
JsonObject *storage;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
JsonNode *node;
|
JsonNode *new_node, *old_node;
|
||||||
|
|
||||||
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (self));
|
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (self));
|
||||||
g_return_if_fail (G_IS_VALUE (data));
|
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);
|
storage = ld_diagram_object_get_storage (self);
|
||||||
name = g_param_spec_get_name (pspec);
|
name = g_param_spec_get_name (pspec);
|
||||||
|
|
||||||
|
if (!self->priv->lock_history)
|
||||||
|
{
|
||||||
action_data = g_slice_new (SetParamActionData);
|
action_data = g_slice_new (SetParamActionData);
|
||||||
action_data->self = g_object_ref (self);
|
action_data->self = g_object_ref (self);
|
||||||
action_data->param_name = g_strdup (g_param_spec_get_name (pspec));
|
action_data->param_name = g_strdup (g_param_spec_get_name (pspec));
|
||||||
|
|
||||||
node = json_object_get_member (storage, name);
|
old_node = json_object_get_member (storage, name);
|
||||||
action_data->old_node = node ? json_node_copy (node) : NULL;
|
action_data->old_node = old_node ? json_node_copy (old_node) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
node = json_node_new (JSON_NODE_VALUE);
|
new_node = json_node_new (JSON_NODE_VALUE);
|
||||||
json_node_set_value (node, data);
|
json_node_set_value (new_node, data);
|
||||||
action_data->new_node = json_node_copy (node);
|
|
||||||
|
|
||||||
json_object_set_member (storage, name, node);
|
if (!self->priv->lock_history)
|
||||||
|
action_data->new_node = json_node_copy (new_node);
|
||||||
|
|
||||||
|
json_object_set_member (storage, name, new_node);
|
||||||
|
|
||||||
|
if (!self->priv->lock_history)
|
||||||
|
{
|
||||||
action = ld_undo_action_new (on_set_param_undo, on_set_param_redo,
|
action = ld_undo_action_new (on_set_param_undo, on_set_param_redo,
|
||||||
on_set_param_destroy, action_data);
|
on_set_param_destroy, action_data);
|
||||||
ld_diagram_object_changed (self, action);
|
ld_diagram_object_changed (self, action);
|
||||||
g_object_unref (action);
|
g_object_unref (action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user