[Gnucash-changes] r13601 - gnucash/trunk/src - Change the account removal event back to using the parent account instead of

Chris Shoemaker chris at cvs.gnucash.org
Sat Mar 11 14:39:16 EST 2006


Author: chris
Date: 2006-03-11 14:39:16 -0500 (Sat, 11 Mar 2006)
New Revision: 13601
Trac: http://svn.gnucash.org/trac/changeset/13601

Modified:
   gnucash/trunk/src/engine/Group.c
   gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
Log:
   Change the account removal event back to using the parent account instead of
   the group, but delay the nulling of the account's group pointer until after
   the generation of the remove event.  That way, the tree model can verify
   that the removed account's root is the same as the root for the model.
   Also, in the model's event handler, check that accounts are in the same book
   as the model is for.


Modified: gnucash/trunk/src/engine/Group.c
===================================================================
--- gnucash/trunk/src/engine/Group.c	2006-03-11 18:10:19 UTC (rev 13600)
+++ gnucash/trunk/src/engine/Group.c	2006-03-11 19:39:16 UTC (rev 13601)
@@ -641,10 +641,8 @@
     return;
   }
 
-  acc->parent = NULL;
-
   /* Gather event data */
-  ed.node = grp;
+  ed.node = grp->parent;
   ed.idx = g_list_index(grp->accounts, acc);
 
   grp->accounts = g_list_remove (grp->accounts, acc);
@@ -652,6 +650,9 @@
   /* Now send the event. */
   qof_event_gen(&acc->inst.entity, QOF_EVENT_REMOVE, &ed);
 
+  /* clear the account's group pointer after REMOVE event generation. */
+  acc->parent = NULL;
+
   grp->saved = 0;
 
   /* if this was the last account in a group, delete

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2006-03-11 18:10:19 UTC (rev 13600)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2006-03-11 19:39:16 UTC (rev 13601)
@@ -1443,7 +1443,6 @@
   GtkTreePath *path = NULL;
   GtkTreeIter iter;
   Account *account, *parent;
-  AccountGroup *group;
 
   g_return_if_fail(model);	/* Required */
   if (!GNC_IS_ACCOUNT(entity))
@@ -1453,16 +1452,20 @@
 	entity, event_type, model, ed);
   priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
 
+  account = GNC_ACCOUNT(entity);
+  if (xaccAccountGetBook(account) != priv->book) {
+      LEAVE("not in this book");
+      return;
+  }
+  if (xaccAccountGetRoot(account) != priv->root) {
+      LEAVE("not in this model");
+      return;
+  }
   /* What to do, that to do. */
   switch (event_type) {
     case QOF_EVENT_ADD:
       /* Tell the filters/views where the new account was added. */
-      account = GNC_ACCOUNT(entity);
       DEBUG("add account %p (%s)", account, xaccAccountGetName(account));
-      if (xaccAccountGetRoot(account) != priv->root) {
-	LEAVE("not in this model");
-	return;
-      }
       path = gnc_tree_model_account_get_path_from_account(model, account);
       if (!path) {
 	DEBUG("can't generate path");
@@ -1480,15 +1483,8 @@
     case QOF_EVENT_REMOVE:
       if (!ed) /* Required for a remove. */
 	break;
-      group = ed->node;
-      if (xaccGroupGetRoot(group) != priv->root) {
-	LEAVE("not in this model");
-	return;
-      }
-      parent = xaccGroupGetParentAccount(ed->node);
-      if (!parent)
-	parent = priv->toplevel;;
-      parent_name = parent ? xaccAccountGetName(parent) : "Root";
+      parent = ed->node ? GNC_ACCOUNT(ed->node) : priv->toplevel;
+      parent_name = ed->node ? xaccAccountGetName(parent) : "Root";
       DEBUG("remove child %d of account %p (%s)", ed->idx, parent, parent_name);
       path = gnc_tree_model_account_get_path_from_account(model, parent);
       if (!path) {
@@ -1501,12 +1497,7 @@
       break;
 
     case QOF_EVENT_MODIFY:
-      account = GNC_ACCOUNT(entity);
       DEBUG("modify  account %p (%s)", account, xaccAccountGetName(account));
-      if (xaccAccountGetRoot(account) != priv->root) {
-	LEAVE("not in this model");
-	return;
-      }
       path = gnc_tree_model_account_get_path_from_account(model, account);
       if (!path) {
 	DEBUG("can't generate path");



More information about the gnucash-changes mailing list