From da778e274eb4d3f112ebd9d43f79092d55dfeca2 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Tue, 12 Nov 2002 18:58:45 +0000 Subject: [PATCH] Apply the fixes for #92157 to the business entry ledger. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7474 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 4 ++ src/business/business-ledger/gncEntryLedger.c | 58 +++++++++++++++++-- .../business-ledger/gncEntryLedgerControl.c | 29 +--------- .../business-ledger/gncEntryLedgerP.h | 2 + 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe69996d9c..fa0d2285ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ accounts. (gnc_split_register_get_account): Call the new function to get the addditional checks. This solves #92157. + * src/business/business-ledger/gncEntryLedger.c: + * src/business/business-ledger/gncEntryLedgerControl.c: Implement + the equivalent fixes for the business ledger. + 2002-11-12 Benoit Grégoire * src/import-export/Transaction-matcher.c: Fix previous patch. gcc 3.2 is too forgiving... diff --git a/src/business/business-ledger/gncEntryLedger.c b/src/business/business-ledger/gncEntryLedger.c index 76458dbfc1..dd67522c04 100644 --- a/src/business/business-ledger/gncEntryLedger.c +++ b/src/business/business-ledger/gncEntryLedger.c @@ -11,6 +11,7 @@ #include #include "Account.h" +#include "AccWindow.h" #include "gnc-ui-util.h" #include "combocell.h" #include "pricecell.h" @@ -57,16 +58,63 @@ gnc_entry_ledger_get_blank_entry (GncEntryLedger *ledger) return gncEntryLookup (ledger->book, &(ledger->blank_entry_guid)); } +Account * +gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell, + const char *name, gboolean *new) +{ + const char *placeholder = _("The account %s does not allow transactions.\n"); + const char *missing = _("The account %s does not exist.\n" + "Would you like to create it?"); + char *fullname; + ComboCell *cell = (ComboCell *) bcell; + Account *account; + + /* No changes, as yet. */ + *new = FALSE; + + /* Find the account */ + account = xaccGetAccountFromFullName (gnc_get_current_group (), + name, gnc_get_account_separator ()); + + if (!account) { + /* Ask if they want to create a new one. */ + if (!gnc_verify_dialog_parented (ledger->parent, TRUE, missing, name)) + return NULL; + + /* User said yes, they want to create a new account. */ + account = gnc_ui_new_accounts_from_name_window (name); + if (!account) + return NULL; + *new = TRUE; + + /* Now have a new account. Update the cell with the name as created. */ + fullname = xaccAccountGetFullName (account, gnc_get_account_separator ()); + gnc_combo_cell_set_value (cell, fullname); + gnc_basic_cell_set_changed (&cell->cell, TRUE); + g_free (fullname); + } + + /* See if the account (either old or new) is a placeholder. */ + if (xaccAccountGetPlaceholder (account)) { + gnc_error_dialog_parented (GTK_WINDOW(ledger->parent), placeholder, name); + } + + /* Be seeing you. */ + return account; +} Account * gnc_entry_ledger_get_account (GncEntryLedger *ledger, const char * cell_name) { - const char * name = - gnc_table_layout_get_cell_value (ledger->table->layout, cell_name); + BasicCell *cell; + const char * name; + gboolean dummy; - return xaccGetAccountFromFullName (gnc_book_get_group (ledger->book), - name, - gnc_get_account_separator ()); + cell = gnc_table_layout_get_cell (ledger->table->layout, cell_name); + if (!cell) + return NULL; + name = gnc_basic_cell_get_value (cell); + return gnc_entry_ledger_get_account_by_name (ledger, cell, name, &dummy); } GncTaxTable * gnc_entry_ledger_get_taxtable (GncEntryLedger *ledger, diff --git a/src/business/business-ledger/gncEntryLedgerControl.c b/src/business/business-ledger/gncEntryLedgerControl.c index 59335806f0..546248c0d8 100644 --- a/src/business/business-ledger/gncEntryLedgerControl.c +++ b/src/business/business-ledger/gncEntryLedgerControl.c @@ -279,7 +279,6 @@ static gboolean gnc_entry_ledger_traverse (VirtualLocation *p_new_virt_loc, do { ComboCell *cell; - Account *account; char *name; char *cell_name = NULL; @@ -316,31 +315,9 @@ static gboolean gnc_entry_ledger_traverse (VirtualLocation *p_new_virt_loc, if (!name || *name == '\0') break; - account = xaccGetAccountFromFullName (gnc_book_get_group (ledger->book), - cell->cell.value, - gnc_get_account_separator ()); - if (account) - break; - - { - const char *format = _("The account %s does not exist.\n" - "Would you like to create it?"); - if (!gnc_verify_dialog_parented (ledger->parent, TRUE, format, name)) - break; - } - - ledger->full_refresh = FALSE; - - account = gnc_ui_new_accounts_from_name_window (name); - if (!account) - break; - - ledger->full_refresh = TRUE; - - name = xaccAccountGetFullName (account, gnc_get_account_separator ()); - gnc_combo_cell_set_value (cell, name); - gnc_basic_cell_set_changed (&cell->cell, TRUE); - g_free (name); + /* Create the account if necessary. Also checks for a placeholder */ + (void) gnc_entry_ledger_get_account_by_name (ledger, (BasicCell *)cell, cell->cell.value, + &ledger->full_refresh); } while (FALSE); diff --git a/src/business/business-ledger/gncEntryLedgerP.h b/src/business/business-ledger/gncEntryLedgerP.h index 9fbdc6959d..40e278b40a 100644 --- a/src/business/business-ledger/gncEntryLedgerP.h +++ b/src/business/business-ledger/gncEntryLedgerP.h @@ -39,6 +39,8 @@ struct GncEntryLedger_s { GncEntry * gnc_entry_ledger_get_entry (GncEntryLedger *ledger, VirtualCellLocation vcell_loc); +Account * gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell, + const char *name, gboolean *new); Account * gnc_entry_ledger_get_account (GncEntryLedger *ledger, const char * cell_name); GncTaxTable * gnc_entry_ledger_get_taxtable (GncEntryLedger *ledger,