From 35a8b15f41c916efc2f1145cd043de1326d3fd85 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sun, 5 Mar 2006 01:29:43 +0000 Subject: [PATCH] Move/fix the callbacks function that kills any open registers for an account that has had "extreme" changes made to it in the "edit account" dialog. Fixes 331415. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13486 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 +++ src/gnome/gnc-plugin-page-register.c | 47 ++++++++++++++++ src/register/ledger-core/gnc-ledger-display.c | 54 ------------------- src/register/ledger-core/gnc-ledger-display.h | 3 -- src/register/ledger-core/split-register.c | 1 - 5 files changed, 54 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef634e45f8..16b227da51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2006-03-04 David Hampton + * src/register/ledger-core/gnc-ledger-display.[ch]: + * src/register/ledger-core/split-register.c: + * src/gnome/gnc-plugin-page-register.c: Move/fix the callbacks + function that kills any open registers for an account that has had + "extreme" changes made to it in the "edit account" dialog. Fixes + 331415. + * src/pixmaps/* * src/gnome-utils/Makefile.am: * src/gnome-utils/gnc-icons.[ch]: diff --git a/src/gnome/gnc-plugin-page-register.c b/src/gnome/gnc-plugin-page-register.c index 3a38f17ba1..39f0752ce1 100644 --- a/src/gnome/gnc-plugin-page-register.c +++ b/src/gnome/gnc-plugin-page-register.c @@ -149,6 +149,7 @@ static void gnc_plugin_page_help_changed_cb( GNCSplitReg *gsr, GncPluginPageRegi static void gnc_plugin_page_register_refresh_cb (GHashTable *changes, gpointer user_data); static void gnc_plugin_page_register_update_split_button (SplitRegister *reg, GncPluginPageRegister *page); +static void gppr_account_destroy_cb (Account *account); /************************************************************/ /* Actions */ @@ -506,6 +507,8 @@ gnc_plugin_page_register_class_init (GncPluginPageRegisterClass *klass) gnc_plugin_class->update_edit_menu_actions = gnc_plugin_page_register_update_edit_menu; g_type_class_add_private(klass, sizeof(GncPluginPageRegisterPrivate)); + + gnc_ui_register_account_destroy_callback (gppr_account_destroy_cb); } static void @@ -2717,5 +2720,49 @@ gnc_plugin_page_register_refresh_cb (GHashTable *changes, gpointer user_data) } } +/** This function is called when an account has been edited and an + * "extreme" change has been made to it. (E.G. Changing from a + * credit card account to an expense account. This rouine is + * responsible for finding all open registers containing the account + * and closing them. + * + * @param accoung A pointer to the account that was changed. + */ +static void +gppr_account_destroy_cb (Account *account) +{ + GncPluginPageRegister *page; + GncPluginPageRegisterPrivate *priv; + GNCLedgerDisplayType ledger_type; + const GUID *acct_guid; + const GList *citem; + GList *item, *kill = NULL; + + acct_guid = xaccAccountGetGUID(account); + + /* Find all windows that need to be killed. Don't kill them yet, as + * that would affect the list being walked.*/ + citem = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_REGISTER_NAME); + for ( ; citem; citem = g_list_next(citem)) { + page = (GncPluginPageRegister *)citem->data; + priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page); + ledger_type = gnc_ledger_display_type (priv->ledger); + if (ledger_type == LD_GL) { + kill = g_list_append(kill, page); + /* kill it */ + } else if ((ledger_type == LD_SINGLE) || (ledger_type == LD_SUBACCOUNT)) { + if (guid_compare(acct_guid, &priv->key) == 0) { + kill = g_list_append(kill, page); + } + } + } + + /* Now kill them. */ + for (item = kill; item; item = g_list_next(item)) { + page = (GncPluginPageRegister *)item->data; + gnc_main_window_close_page(GNC_PLUGIN_PAGE(page)); + } +} + /** @} */ /** @} */ diff --git a/src/register/ledger-core/gnc-ledger-display.c b/src/register/ledger-core/gnc-ledger-display.c index 52112812ea..42aa530bae 100644 --- a/src/register/ledger-core/gnc-ledger-display.c +++ b/src/register/ledger-core/gnc-ledger-display.c @@ -167,25 +167,6 @@ find_by_leader (gpointer find_data, gpointer user_data) return (account == gnc_ledger_display_leader (ld)); } -static gboolean -find_by_account (gpointer find_data, gpointer user_data) -{ - Account *account = find_data; - GNCLedgerDisplay *ld = user_data; - - if (!account || !ld) - return FALSE; - - if (account == gnc_ledger_display_leader (ld)) - return TRUE; - - if (ld->ld_type == LD_SINGLE) - return FALSE; - - /* Hack. */ - return TRUE; -} - static gboolean find_by_query (gpointer find_data, gpointer user_data) { @@ -891,41 +872,6 @@ gnc_ledger_display_refresh_by_split_register (SplitRegister *reg) } } -/********************************************************************\ - * xaccDestroyLedgerDisplay() -\********************************************************************/ - -static void -gnc_destroy_ledger_display_class (Account *account, - const char *component_class) -{ - GList *list; - GList *node; - - list = gnc_find_gui_components (component_class, find_by_account, account); - - for (node = list; node; node = node->next) - { - GNCLedgerDisplay *ld = node->data; - - gnc_close_gui_component (ld->component_id); - } - - g_list_free (list); -} - -void -gnc_ledger_display_destroy_by_account (Account *account) -{ - if (!account) - return; - - gnc_destroy_ledger_display_class (account, REGISTER_SINGLE_CM_CLASS); - gnc_destroy_ledger_display_class (account, REGISTER_SUBACCOUNT_CM_CLASS); - gnc_destroy_ledger_display_class (account, REGISTER_GL_CM_CLASS); - /* no TEMPLATE_CM_CLASS, because it doesn't correspond to any account */ -} - void gnc_ledger_display_close (GNCLedgerDisplay *ld) { diff --git a/src/register/ledger-core/gnc-ledger-display.h b/src/register/ledger-core/gnc-ledger-display.h index e1f0610eba..8d9b99bad6 100644 --- a/src/register/ledger-core/gnc-ledger-display.h +++ b/src/register/ledger-core/gnc-ledger-display.h @@ -119,9 +119,6 @@ void gnc_ledger_display_refresh_by_split_register (SplitRegister *reg); /* close the window */ void gnc_ledger_display_close (GNCLedgerDisplay * ledger_display); -/* close all ledger windows containing this account. */ -void gnc_ledger_display_destroy_by_account (Account *account); - /* Returns a boolean of whether this display should be single or double lined * mode by default */ gboolean gnc_ledger_display_default_double_line (GNCLedgerDisplay *gld); diff --git a/src/register/ledger-core/split-register.c b/src/register/ledger-core/split-register.c index 5dbc4e3427..c05634c881 100644 --- a/src/register/ledger-core/split-register.c +++ b/src/register/ledger-core/split-register.c @@ -2229,7 +2229,6 @@ gnc_split_register_init (SplitRegister *reg, TableControl *control; /* Register 'destroy' callback */ - gnc_ui_register_account_destroy_callback (gnc_ledger_display_destroy_by_account); gnc_gconf_general_register_cb(KEY_ACCOUNTING_LABELS, split_register_gconf_changed, reg);