[dia] Bug 651584 - Signal emissions for layer add/remove/change and update



commit dc34599a668daa932cc41a5aa5f813458a41ef1b
Author: Hans Breuer <hans breuer org>
Date:   Fri Jun 3 13:59:34 2011 +0200

    Bug 651584 - Signal emissions for layer add/remove/change and update
    
    The initial object added to the diagram was not correctly reflected in
    an open diagram tree dialog. Also all signals regarding layer changes
    were missing.

 app/diagram_tree_model.c |   13 +++++++++++++
 app/layer_dialog.c       |    4 ++++
 lib/diagramdata.c        |    3 +++
 lib/layer.c              |   16 +++++-----------
 4 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/app/diagram_tree_model.c b/app/diagram_tree_model.c
index a9d7833..59c1781 100644
--- a/app/diagram_tree_model.c
+++ b/app/diagram_tree_model.c
@@ -413,6 +413,8 @@ _object_add (DiagramData      *dia,
   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);
 
@@ -425,6 +427,9 @@ _object_add (DiagramData      *dia,
   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);
   }
 }
@@ -437,6 +442,7 @@ _object_remove(DiagramData      *dia,
   GtkTreePath *path;
   GtkTreeIter _iter;
   GtkTreeIter *iter = &_iter;
+  gboolean last_child = layer_object_count (layer) == 0;
 
   g_return_if_fail (DIA_DIAGRAM(dia) != NULL);
   
@@ -447,6 +453,13 @@ _object_remove(DiagramData      *dia,
   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);
+  }
 }
 /* start listening for diagram specific object changes */
 static void
diff --git a/app/layer_dialog.c b/app/layer_dialog.c
index 83364cb..84cfcfe 100644
--- a/app/layer_dialog.c
+++ b/app/layer_dialog.c
@@ -39,6 +39,8 @@
 #include "widgets.h"
 #include "interface.h"
 
+#include "dia-application.h" /* dia_diagram_change */
+
 #include "dia-app-icons.h"
 
 /* DiaLayerWidget: */
@@ -1101,6 +1103,8 @@ edit_layer_ok_callback (GtkWidget *w, gpointer client_data)
 
   g_free (layer->name);
   layer->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
+  /* reflect name change on listeners */
+  dia_diagram_change (dialog->layer_widget->dia, DIAGRAM_CHANGE_LAYER, layer);
   
   diagram_add_update_all (dialog->layer_widget->dia);
   diagram_flush (dialog->layer_widget->dia);
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index a49316e..38c21bc 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -332,6 +332,7 @@ data_add_layer(DiagramData *data, Layer *layer)
 {
   g_ptr_array_add(data->layers, layer);
   layer->parent_diagram = data;
+  data_emit (data, layer, NULL, "object_add");
   layer_update_extents(layer);
   data_update_extents(data);
 }
@@ -353,6 +354,7 @@ data_add_layer_at(DiagramData *data, Layer *layer, int pos)
   }
   
   layer->parent_diagram = data;
+  data_emit (data, layer, NULL, "object_add");
   layer_update_extents(layer);
   data_update_extents(data);
 }
@@ -406,6 +408,7 @@ data_delete_layer(DiagramData *data, Layer *layer)
   if (data->active_layer == layer) {
     data_remove_all_selected(data);
   }
+  data_emit (data, layer, NULL, "object_remove");
   layer->parent_diagram = NULL;
   g_ptr_array_remove(data->layers, layer);
 
diff --git a/lib/layer.c b/lib/layer.c
index 8b74463..5747d6d 100644
--- a/lib/layer.c
+++ b/lib/layer.c
@@ -275,18 +275,17 @@ layer_add_objects_first(Layer *layer, GList *obj_list)
 void
 layer_remove_object(Layer *layer, DiaObject *obj)
 {
+  /* send a signal that we'll remove a object from the diagram */
+  data_emit (layer_get_parent_diagram(layer), layer, obj, "object_remove");
+
   layer->objects = g_list_remove(layer->objects, obj);
   dynobj_list_remove_object(obj);
   set_parent_layer(obj, NULL);
-
-  /* send a signal that we have removed a object from the diagram */
-  data_emit (layer_get_parent_diagram(layer), layer, obj, "object_remove");
 }
 
 /** Remove a list of objects from a layer.
  * @param layer The layer to remove the objects from.
  * @param obj The objects to remove.
- * @bug This should call layer_remove_object repeatedly.
  */
 void
 layer_remove_objects(Layer *layer, GList *obj_list)
@@ -294,15 +293,10 @@ layer_remove_objects(Layer *layer, GList *obj_list)
   DiaObject *obj;
   while (obj_list != NULL) {
     obj = (DiaObject *) obj_list->data;
-    
-    /* send a signal that we will remove an object from the diagram */
-    data_emit (layer_get_parent_diagram(layer), layer, obj, "object_remove");
 
-    layer->objects = g_list_remove(layer->objects, obj);
-    
+    layer_remove_object (layer, obj);
+
     obj_list = g_list_next(obj_list);
-    dynobj_list_remove_object(obj);
-    set_parent_layer(obj, NULL);
   }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]