Connect to the "data-changed" signal in LdDiagram.
Also rewrite some of the functions.
This commit is contained in:
parent
400568ed7d
commit
c07d5f552d
|
@ -49,6 +49,9 @@ static void ld_diagram_set_property (GObject *object, guint property_id,
|
|||
static void ld_diagram_dispose (GObject *gobject);
|
||||
static void ld_diagram_finalize (GObject *gobject);
|
||||
|
||||
static void on_object_data_changed (LdDiagramObject *self,
|
||||
gchar **path, GValue *old_value, GValue *new_value, gpointer user_data);
|
||||
|
||||
static gboolean write_signature (GOutputStream *stream, GError **error);
|
||||
|
||||
static gboolean check_node (JsonNode *node, JsonNodeType type,
|
||||
|
@ -61,8 +64,9 @@ static JsonNode *serialize_diagram (LdDiagram *self);
|
|||
static JsonNode *serialize_object (LdDiagramObject *object);
|
||||
static const gchar *get_object_class_string (GType type);
|
||||
|
||||
static void install_object (LdDiagramObject *object, LdDiagram *self);
|
||||
static void uninstall_object (LdDiagramObject *object, LdDiagram *self);
|
||||
static void ld_diagram_real_changed (LdDiagram *self);
|
||||
static void ld_diagram_clear_internal (LdDiagram *self);
|
||||
static void ld_diagram_unselect_all_internal (LdDiagram *self);
|
||||
|
||||
|
||||
|
@ -166,7 +170,7 @@ ld_diagram_dispose (GObject *gobject)
|
|||
LdDiagram *self;
|
||||
|
||||
self = LD_DIAGRAM (gobject);
|
||||
ld_diagram_clear_internal (self);
|
||||
ld_diagram_clear (self);
|
||||
|
||||
/* Chain up to the parent class. */
|
||||
G_OBJECT_CLASS (ld_diagram_parent_class)->dispose (gobject);
|
||||
|
@ -221,33 +225,37 @@ ld_diagram_new (void)
|
|||
void
|
||||
ld_diagram_clear (LdDiagram *self)
|
||||
{
|
||||
gboolean changed = FALSE;
|
||||
gboolean selection_changed = FALSE;
|
||||
|
||||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
|
||||
ld_diagram_clear_internal (self);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->selection_changed_signal, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* ld_diagram_clear_internal:
|
||||
* @self: an #LdDiagram object.
|
||||
*
|
||||
* Do the same as ld_diagram_clear() does but don't emit signals.
|
||||
*/
|
||||
static void
|
||||
ld_diagram_clear_internal (LdDiagram *self)
|
||||
if (self->priv->selection)
|
||||
{
|
||||
ld_diagram_unselect_all_internal (self);
|
||||
selection_changed = TRUE;
|
||||
}
|
||||
|
||||
if (self->priv->connections)
|
||||
{
|
||||
g_list_free (self->priv->connections);
|
||||
self->priv->connections = NULL;
|
||||
|
||||
g_list_foreach (self->priv->objects, (GFunc) g_object_unref, NULL);
|
||||
changed = TRUE;
|
||||
}
|
||||
if (self->priv->objects)
|
||||
{
|
||||
g_list_foreach (self->priv->objects, (GFunc) uninstall_object, self);
|
||||
g_list_free (self->priv->objects);
|
||||
self->priv->objects = NULL;
|
||||
changed = TRUE;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
|
||||
if (selection_changed)
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->selection_changed_signal, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -530,6 +538,27 @@ ld_diagram_set_modified (LdDiagram *self, gboolean value)
|
|||
g_object_notify (G_OBJECT (self), "modified");
|
||||
}
|
||||
|
||||
static void
|
||||
on_object_data_changed (LdDiagramObject *self, gchar **path,
|
||||
GValue *old_value, GValue *new_value, gpointer user_data)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
install_object (LdDiagramObject *object, LdDiagram *self)
|
||||
{
|
||||
g_signal_connect (object, "data-changed",
|
||||
G_CALLBACK (on_object_data_changed), self);
|
||||
g_object_ref (object);
|
||||
}
|
||||
|
||||
static void
|
||||
uninstall_object (LdDiagramObject *object, LdDiagram *self)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (object, on_object_data_changed, self);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_diagram_get_objects:
|
||||
* @self: an #LdDiagram object.
|
||||
|
@ -558,16 +587,15 @@ ld_diagram_insert_object (LdDiagram *self, LdDiagramObject *object, gint pos)
|
|||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
|
||||
|
||||
if (!g_list_find (self->priv->objects, object))
|
||||
{
|
||||
self->priv->objects =
|
||||
g_list_insert (self->priv->objects, object, pos);
|
||||
g_object_ref (object);
|
||||
if (g_list_find (self->priv->objects, object))
|
||||
return;
|
||||
|
||||
self->priv->objects = g_list_insert (self->priv->objects, object, pos);
|
||||
install_object (object, self);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_diagram_remove_object:
|
||||
|
@ -582,17 +610,17 @@ ld_diagram_remove_object (LdDiagram *self, LdDiagramObject *object)
|
|||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
|
||||
|
||||
if (g_list_find (self->priv->objects, object))
|
||||
{
|
||||
if (!g_list_find (self->priv->objects, object))
|
||||
return;
|
||||
|
||||
ld_diagram_unselect (self, object);
|
||||
|
||||
self->priv->objects = g_list_remove (self->priv->objects, object);
|
||||
g_object_unref (object);
|
||||
uninstall_object (object, self);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_diagram_get_selection:
|
||||
|
@ -617,22 +645,22 @@ ld_diagram_get_selection (LdDiagram *self)
|
|||
void
|
||||
ld_diagram_remove_selection (LdDiagram *self)
|
||||
{
|
||||
gboolean changed = FALSE;
|
||||
LdDiagramObject *object;
|
||||
gboolean changed;
|
||||
GList *iter;
|
||||
|
||||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
|
||||
for (iter = self->priv->selection; iter; iter = g_list_next (iter))
|
||||
{
|
||||
LdDiagramObject *object;
|
||||
|
||||
changed = TRUE;
|
||||
object = LD_DIAGRAM_OBJECT (iter->data);
|
||||
g_object_unref (object);
|
||||
|
||||
self->priv->objects = g_list_remove (self->priv->objects, object);
|
||||
g_object_unref (object);
|
||||
g_object_unref (object);
|
||||
uninstall_object (object, self);
|
||||
}
|
||||
|
||||
changed = self->priv->selection != NULL;
|
||||
g_list_free (self->priv->selection);
|
||||
self->priv->selection = NULL;
|
||||
|
||||
|
@ -657,19 +685,17 @@ ld_diagram_select (LdDiagram *self, LdDiagramObject *object)
|
|||
{
|
||||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
|
||||
|
||||
g_return_if_fail (g_list_find (self->priv->objects, object) != NULL);
|
||||
|
||||
if (!g_list_find (self->priv->selection, object))
|
||||
{
|
||||
self->priv->selection =
|
||||
g_list_insert (self->priv->selection, object, 0);
|
||||
if (g_list_find (self->priv->selection, object))
|
||||
return;
|
||||
|
||||
self->priv->selection = g_list_insert (self->priv->selection, object, 0);
|
||||
g_object_ref (object);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->selection_changed_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_diagram_unselect:
|
||||
|
@ -684,15 +710,15 @@ ld_diagram_unselect (LdDiagram *self, LdDiagramObject *object)
|
|||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
|
||||
|
||||
if (g_list_find (self->priv->selection, object))
|
||||
{
|
||||
if (!g_list_find (self->priv->selection, object))
|
||||
return;
|
||||
|
||||
self->priv->selection = g_list_remove (self->priv->selection, object);
|
||||
g_object_unref (object);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->selection_changed_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_diagram_select_all:
|
||||
|
@ -706,7 +732,6 @@ ld_diagram_select_all (LdDiagram *self)
|
|||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
|
||||
ld_diagram_unselect_all_internal (self);
|
||||
|
||||
self->priv->selection = g_list_copy (self->priv->objects);
|
||||
g_list_foreach (self->priv->selection, (GFunc) g_object_ref, NULL);
|
||||
|
||||
|
@ -725,13 +750,14 @@ ld_diagram_unselect_all (LdDiagram *self)
|
|||
{
|
||||
g_return_if_fail (LD_IS_DIAGRAM (self));
|
||||
|
||||
if (self->priv->selection)
|
||||
{
|
||||
if (!self->priv->selection)
|
||||
return;
|
||||
|
||||
ld_diagram_unselect_all_internal (self);
|
||||
|
||||
g_signal_emit (self,
|
||||
LD_DIAGRAM_GET_CLASS (self)->selection_changed_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ld_diagram_unselect_all_internal (LdDiagram *self)
|
||||
|
|
Loading…
Reference in New Issue