[Gnucash-changes] r14285 - gnucash/trunk/src/gnome-utils - Restore two behaviors removed by r14283, and add a third.

Chris Shoemaker chris at cvs.gnucash.org
Wed May 31 21:44:56 EDT 2006


Author: chris
Date: 2006-05-31 21:44:53 -0400 (Wed, 31 May 2006)
New Revision: 14285
Trac: http://svn.gnucash.org/trac/changeset/14285

Modified:
   gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
Log:
   Restore two behaviors removed by r14283, and add a third.
   1) Invalidate outstanding iterators when a row is inserted or deleted.
   2) Emit row_changed for ancestors of inserted or deleted row.
   New) Emit row_changed for ancestors of a changed account, too.



Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2006-05-31 21:42:21 UTC (rev 14284)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2006-06-01 01:44:53 UTC (rev 14285)
@@ -1426,6 +1426,33 @@
 /*   Account Tree Model - Engine Event Handling Functions   */
 /************************************************************/
 
+static void
+increment_stamp(GncTreeModelAccount *model)
+{
+    do model->stamp++; 
+    while (!model->stamp);
+}
+
+static void
+propagate_change(GtkTreeModel *model, GtkTreePath *path, gint toggle_if_num)
+{
+    GtkTreeIter iter;
+
+    /* Immediate parent */
+    if (gtk_tree_path_up(path) && 
+        gtk_tree_model_get_iter(model, &iter, path)) {
+        gtk_tree_model_row_changed(model, path, &iter);
+        if (gtk_tree_model_iter_n_children(model, &iter) == toggle_if_num)
+            gtk_tree_model_row_has_child_toggled(model, path, &iter);
+    }
+
+    /* All other ancestors */
+    while (gtk_tree_path_up(path) && gtk_tree_path_get_depth(path) > 0 &&
+           gtk_tree_model_get_iter(model, &iter, path)) {
+        gtk_tree_model_row_changed(model, path, &iter);
+    }
+}
+
 /** This function is the handler for all event messages from the
  *  engine.  Its purpose is to update the account tree model any time
  *  an account is added to the engine or deleted from the engine.
@@ -1493,15 +1520,13 @@
 	DEBUG("can't generate path");
 	break;
       }
+      increment_stamp(model);
       if (!gnc_tree_model_account_get_iter(GTK_TREE_MODEL(model), &iter, path)) {
 	DEBUG("can't generate iter");
 	break;
       }
       gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), path, &iter);
-      if (gtk_tree_path_up (path) &&
-	  gtk_tree_model_get_iter (GTK_TREE_MODEL(model), &iter, path) &&
-	  gtk_tree_model_iter_n_children (GTK_TREE_MODEL(model), &iter) == 1)
-	gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL(model), path, &iter);
+      propagate_change(GTK_TREE_MODEL(model), path, 1);
       break;
 
     case QOF_EVENT_REMOVE:
@@ -1515,12 +1540,10 @@
 	DEBUG("can't generate path");
 	break;
       }
+      increment_stamp(model);
       gtk_tree_path_append_index (path, ed->idx);
       gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), path);
-      if (gtk_tree_path_up (path) &&
-	  gtk_tree_model_get_iter (GTK_TREE_MODEL(model), &iter, path) &&
-	  gtk_tree_model_iter_n_children (GTK_TREE_MODEL(model), &iter) == 0)
-	gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL(model), path, &iter);
+      propagate_change(GTK_TREE_MODEL(model), path, 0);
       break;
 
     case QOF_EVENT_MODIFY:
@@ -1535,6 +1558,7 @@
 	break;
       }
       gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
+      propagate_change(GTK_TREE_MODEL(model), path, -1);
       break;
 
     default:



More information about the gnucash-changes mailing list