[Gnucash-changes] r13010 - gnucash/trunk/src/gnome - Automatically close registers whose accounts are deleted.

Chris Shoemaker chris at cvs.gnucash.org
Sat Jan 28 15:30:23 EST 2006


Author: chris
Date: 2006-01-28 15:30:23 -0500 (Sat, 28 Jan 2006)
New Revision: 13010
Trac: http://svn.gnucash.org/trac/changeset/13010

Modified:
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
Log:
   Automatically close registers whose accounts are deleted.
   We use the component manager to watch for the destruction of the account.
   Previously, having an account's register open while deleting it would
   just crash.


Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2006-01-28 19:54:59 UTC (rev 13009)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2006-01-28 20:30:23 UTC (rev 13010)
@@ -64,6 +64,8 @@
 #include "gnc-split-reg.h"
 #include "gnc-ui-util.h"
 #include "gnc-window.h"
+#include "gnc-main-window.h"
+#include "gnc-session.h"
 #include "gnucash-sheet.h"
 #include "lot-viewer.h"
 #include "Scrub.h"
@@ -340,6 +342,7 @@
 	GtkWidget *widget;
 
 	gint component_manager_id;
+	GUID key;  /* The guid of the Account we're watching */
 
 	const char *lines_opt_section;
 	const char *lines_opt_name;
@@ -424,6 +427,7 @@
 	register_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_REGISTER, NULL);
 	priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(register_page);
 	priv->ledger = ledger;
+	priv->key = *guid_null();
 
 	plugin_page = GNC_PLUGIN_PAGE(register_page);
 	label = gnc_plugin_page_register_get_tab_name(plugin_page);
@@ -444,13 +448,18 @@
 gnc_plugin_page_register_new (Account *account, gboolean subaccounts)
 {
 	GNCLedgerDisplay *ledger;
+	GncPluginPage *page;
+	GncPluginPageRegisterPrivate *priv;
 
 	if (subaccounts)
 	  ledger = gnc_ledger_display_subaccounts (account);
 	else
 	  ledger = gnc_ledger_display_simple (account);
 
-	return gnc_plugin_page_register_new_common(ledger);
+	page = gnc_plugin_page_register_new_common(ledger);
+	priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+	priv->key = *xaccAccountGetGUID(account);
+	return page;
 }
 
 GncPluginPage *
@@ -620,6 +629,7 @@
 	guint numRows;
 	GtkWidget *gsr;
 	SplitRegister *sr;
+	Account *acct;
 
 	ENTER("page %p", plugin_page);
 	page = GNC_PLUGIN_PAGE_REGISTER (plugin_page);
@@ -669,7 +679,15 @@
 	  gnc_register_gui_component(GNC_PLUGIN_PAGE_REGISTER_NAME,
 				     gnc_plugin_page_register_refresh_cb,
 				     NULL, page);
+	gnc_gui_component_set_session (priv->component_manager_id,
+				       gnc_get_current_session());
+	acct = gnc_plugin_page_register_get_account(page);
+	if (acct)
+	    gnc_gui_component_watch_entity (
+		priv->component_manager_id, xaccAccountGetGUID(acct),
+		GNC_EVENT_DESTROY | GNC_EVENT_MODIFY);
 
+
 	/* DRH - Probably lots of other stuff from regWindowLedger should end up here. */
 	LEAVE(" ");
 	return priv->widget;
@@ -2613,14 +2631,27 @@
   GncPluginPageRegisterPrivate *priv;
 
   g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
+  priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
 
-  /* We're only looking for forced updates here. */
-  if (changes)
-    return;
-
-  priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
-  gnucash_register_refresh_from_gconf(priv->gsr->reg);
-  gtk_widget_queue_draw(priv->widget);
+  if (changes) {
+      const EventInfo* ei;
+      ei = gnc_gui_get_entity_events(changes, &priv->key);
+      if (ei) {
+          if (ei->event_mask & GNC_EVENT_DESTROY) {
+              gnc_main_window_close_page(GNC_PLUGIN_PAGE(page));
+              return;
+          }
+          if (ei->event_mask & GNC_EVENT_MODIFY) {
+              /* CAS: We need to also handle account renames, but at
+                 least we don't crash for those. */
+          }
+      }
+  }
+  else {
+      /* forced updates */
+      gnucash_register_refresh_from_gconf(priv->gsr->reg);
+      gtk_widget_queue_draw(priv->widget);
+  }
 }
 
 /** @} */



More information about the gnucash-changes mailing list