static void _object_remove(DiagramData *dia, Layer *layer, DiaObject *obj, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter; GtkTreeIter *iter = &_iter; gboolean last_child = layer_object_count (layer) == 0; g_return_if_fail (DIA_DIAGRAM(dia) != NULL); NODE_DIAGRAM(iter) = dia; NODE_LAYER(iter) = layer; NODE_OBJECT(iter) = obj; path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path); gtk_tree_path_free (path); /* enforce update - but the arrow on layer does not vanish */ if (last_child) { NODE_OBJECT(iter) = NULL; path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, iter); gtk_tree_path_free (path); } }
static void _diagram_change (DiaApplication *app, Diagram *dia, guint flags, gpointer object, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter = {0,}; GtkTreeIter *iter = &_iter; NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia); if (flags & DIAGRAM_CHANGE_NAME) /* nothing special */; if (flags & DIAGRAM_CHANGE_LAYER) NODE_LAYER(iter) = object; if (flags & DIAGRAM_CHANGE_OBJECT) { NODE_OBJECT(iter) = object; NODE_LAYER(iter) = dia_object_get_parent_layer (object); } path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); gtk_tree_model_row_changed (GTK_TREE_MODEL (dtm), path, iter); gtk_tree_path_free (path); }
/* listen on the diagram for object add/remove */ static void _object_add (DiagramData *dia, Layer *layer, DiaObject *obj, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter; GtkTreeIter *iter = &_iter; /* a bit backward: the first child is in the diagram, but not the tree yet */ gboolean had_child = layer_object_count (layer) > 1; g_return_if_fail (DIA_DIAGRAM(dia) != NULL); NODE_DIAGRAM(iter) = dia; NODE_LAYER(iter) = layer; NODE_OBJECT(iter) = obj; /* FIXME: this may get called before the layer is added to the tree */ path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); if (path) { gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter); /* enforce update */ if (!had_child && gtk_tree_path_up (path)) gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, &_iter); gtk_tree_path_free (path); } }
/* * MODELCHANGES * * No matter if we are wrapped in the SortModel change signals are always * sent to this model. In the sortable case the GtkTreeModelSort translates * them to the right coordinates for the tree view. */ static gboolean _recurse_row_inserted (GtkTreeModel *model, GtkTreeIter *parent) { GtkTreeIter iter; int n = 0; while (_dtm_iter_nth_child (model, &iter, parent, n)) { GtkTreePath *path = _dtm_get_path (model, &iter); gtk_tree_model_row_inserted (model, path, &iter); /* gtk_tree_model_row_has_child_toggled * ... emitted when a row has gotten the first child row ... * So no need to do it here. Or maybe not for the sorted model? */ if (_recurse_row_inserted (model, &iter)) gtk_tree_model_row_has_child_toggled (model, path, &iter); gtk_tree_path_free (path); ++n; } return (n > 0); }
static void _object_remove(DiagramData *dia, Layer *layer, DiaObject *obj, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter; GtkTreeIter *iter = &_iter; g_return_if_fail (DIA_DIAGRAM(dia) != NULL); NODE_DIAGRAM(iter) = dia; NODE_LAYER(iter) = layer; NODE_OBJECT(iter) = obj; path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path); gtk_tree_path_free (path); }
static void _diagram_remove (DiaApplication *app, Diagram *dia, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter = {0,}; GtkTreeIter *iter = &_iter; NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia); NODE_LAYER(iter) = NULL; NODE_OBJECT(iter) = NULL; path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path); gtk_tree_path_free (path); /* stop listening on this diagram */ g_signal_handlers_disconnect_by_func (dia, _object_add, dtm); g_signal_handlers_disconnect_by_func (dia, _object_remove, dtm); }
/* listen to diagram creation */ static void _diagram_add (DiaApplication *app, Diagram *dia, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter = {0,}; /* all null is our root */ GtkTreeIter *iter = &_iter; NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA (dia); path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); /* we always get a path, but it may not be a valid one */ if (path) { /* gtk_tree_model_row_changed is not 'strong' enough, lets try to re-add the root */ gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter); /* looks like the GtkTreeView is somewhat out of service */ if (_recurse_row_inserted (GTK_TREE_MODEL (dtm), iter)) gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, iter); gtk_tree_path_free (path); } _dtm_listen_on_diagram (dtm, dia); }
/* listen on the diagram for object add/remove */ static void _object_add (DiagramData *dia, Layer *layer, DiaObject *obj, DiagramTreeModel *dtm) { GtkTreePath *path; GtkTreeIter _iter; GtkTreeIter *iter = &_iter; g_return_if_fail (DIA_DIAGRAM(dia) != NULL); NODE_DIAGRAM(iter) = dia; NODE_LAYER(iter) = layer; NODE_OBJECT(iter) = obj; /* FIXME: this may get called before the layer is added to the tree */ path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter); if (path) { gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter); gtk_tree_path_free (path); } }