Index: src/register/ledger-core/split-register-model.c =================================================================== --- src/register/ledger-core/split-register-model.c (Revision 17148) +++ src/register/ledger-core/split-register-model.c (Arbeitskopie) @@ -82,7 +82,7 @@ const char *name; name = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL); - account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name); + account = gnc_account_lookup_for_register (gnc_get_current_root_account (), name); } if (!account) @@ -1196,17 +1196,15 @@ gboolean *conditionally_changed, gpointer user_data) { - static char *name = NULL; + static const char *name = NULL; SplitRegister *reg = user_data; Split *split; split = gnc_split_register_get_split (reg, virt_loc.vcell_loc); - g_free (name); + name = gnc_get_account_name_for_register (xaccSplitGetAccount (split)); - name = xaccAccountGetFullName (xaccSplitGetAccount (split)); - return name; } @@ -1231,7 +1229,7 @@ gboolean *conditionally_changed, gpointer user_data) { - static char *name = NULL; + static const char *name = NULL; SplitRegister *reg = user_data; Split *split; @@ -1243,10 +1241,8 @@ s = xaccSplitGetOtherSplit (split); - g_free (name); - if (s) - name = xaccAccountGetFullName (xaccSplitGetAccount (s)); + name = gnc_get_account_name_for_register (xaccSplitGetAccount (s)); else { /* For multi-split transactions and stock splits, @@ -1713,7 +1709,7 @@ gboolean *conditionally_changed, gpointer user_data) { - static char *name = NULL; + static const char *name = NULL; SplitRegister *reg = user_data; kvp_frame *kvpf; @@ -1725,8 +1721,6 @@ kvpf = xaccSplitGetSlots (split); - g_free (name); - if (kvpf) { Account *account; @@ -1737,7 +1731,7 @@ account = xaccAccountLookup (guid, gnc_get_current_book ()); - name = account ? xaccAccountGetFullName(account) : NULL; + name = account ? gnc_get_account_name_for_register(account) : NULL; } else name = NULL; Index: src/register/ledger-core/split-register.c =================================================================== --- src/register/ledger-core/split-register.c (Revision 17148) +++ src/register/ledger-core/split-register.c (Arbeitskopie) @@ -1498,7 +1498,7 @@ const char *placeholder = _("The account %s does not allow transactions."); const char *missing = _("The account %s does not exist. " "Would you like to create it?"); - char *fullname; + const char *account_name; ComboCell *cell = (ComboCell *) bcell; Account *account; @@ -1506,7 +1506,10 @@ return NULL; /* Find the account */ - account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name); + account = gnc_account_lookup_for_register(gnc_get_current_root_account (), name); + // If no account was found, try matching by account code. + if (!account) + account = gnc_account_lookup_by_code (gnc_get_current_root_account (), name); if (!account) { /* Ask if they want to create a new one. */ @@ -1519,15 +1522,14 @@ account = gnc_ui_new_accounts_from_name_window (name); if (!account) return NULL; - *refresh = TRUE; - - /* Now have a new account. Update the cell with the name as created. */ - fullname = xaccAccountGetFullName (account); - gnc_combo_cell_set_value (cell, fullname); - gnc_basic_cell_set_changed (&cell->cell, TRUE); - g_free (fullname); } + /* Now we have the account. Update the cell with the name as created. */ + *refresh = TRUE; + account_name = gnc_get_account_name_for_register (account); + gnc_combo_cell_set_value (cell, account_name); + gnc_basic_cell_set_changed (&cell->cell, TRUE); + /* See if the account (either old or new) is a placeholder. */ if (xaccAccountGetPlaceholder (account)) { gnc_error_dialog (gnc_split_register_get_parent (reg), Index: src/register/ledger-core/split-register-control.c =================================================================== --- src/register/ledger-core/split-register-control.c (Revision 17148) +++ src/register/ledger-core/split-register-control.c (Arbeitskopie) @@ -750,7 +750,7 @@ case CURSOR_CLASS_SPLIT: { - char *fullname; + const char *account_name; const char *memo; gboolean unit_price; Split *auto_split; @@ -820,9 +820,8 @@ /* auto-complete the account name */ cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL); - fullname = xaccAccountGetFullName (xaccSplitGetAccount (auto_split)); - gnc_combo_cell_set_value ((ComboCell *) cell, fullname); - g_free(fullname); + account_name = gnc_get_account_name_for_register (xaccSplitGetAccount (auto_split)); + gnc_combo_cell_set_value ((ComboCell *) cell, account_name); gnc_basic_cell_set_changed (cell, TRUE); Index: src/core-utils/gnc-gconf-utils.h =================================================================== --- src/core-utils/gnc-gconf-utils.h (Revision 17148) +++ src/core-utils/gnc-gconf-utils.h (Arbeitskopie) @@ -67,6 +67,7 @@ #define KEY_NUMBER_OF_ROWS "number_of_rows" #define KEY_ENABLE_EURO "enable_euro" #define KEY_DATE_FORMAT "date_format" +#define KEY_SHOW_FULL_ACCOUNT_NAMES "show_full_account_names" typedef void (*GncGconfGeneralCb) (GConfEntry *entry, gpointer user_data); typedef void (*GncGconfGeneralAnyCb) (gpointer user_data); Index: src/business/business-ledger/gncEntryLedger.c =================================================================== --- src/business/business-ledger/gncEntryLedger.c (Revision 17148) +++ src/business/business-ledger/gncEntryLedger.c (Arbeitskopie) @@ -81,12 +81,12 @@ const char *placeholder = _("The account %s does not allow transactions."); const char *missing = _("The account %s does not exist. " "Would you like to create it?"); - char *fullname; + const char *account_name; ComboCell *cell = (ComboCell *) bcell; Account *account; /* Find the account */ - account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name); + account = gnc_account_lookup_for_register (gnc_get_current_root_account (), name); if (!account) { /* Ask if they want to create a new one. */ @@ -103,10 +103,9 @@ *new = TRUE; /* Now have a new account. Update the cell with the name as created. */ - fullname = xaccAccountGetFullName (account); - gnc_combo_cell_set_value (cell, fullname); + account_name = gnc_get_account_name_for_register (account); + gnc_combo_cell_set_value (cell, account_name); gnc_basic_cell_set_changed (&cell->cell, TRUE); - g_free (fullname); } /* See if the account (either old or new) is a placeholder. */ Index: src/business/business-ledger/gncEntryLedgerModel.c =================================================================== --- src/business/business-ledger/gncEntryLedgerModel.c (Revision 17148) +++ src/business/business-ledger/gncEntryLedgerModel.c (Arbeitskopie) @@ -147,16 +147,12 @@ gboolean *conditionally_changed, gpointer user_data) { - static char *name = NULL; - GncEntryLedger *ledger = user_data; GncEntry *entry; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); - g_free (name); - name = xaccAccountGetFullName (gncEntryGetInvAccount (entry)); - return name; + return gnc_get_account_name_for_register (gncEntryGetInvAccount (entry)); } static const char * get_bacct_entry (VirtualLocation virt_loc, @@ -164,16 +160,12 @@ gboolean *conditionally_changed, gpointer user_data) { - static char *name = NULL; - GncEntryLedger *ledger = user_data; GncEntry *entry; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); - g_free (name); - name = xaccAccountGetFullName (gncEntryGetBillAccount (entry)); - return name; + return gnc_get_account_name_for_register (gncEntryGetBillAccount (entry)); } static const char * get_actn_entry (VirtualLocation virt_loc, Index: src/gnome-utils/glade/preferences.glade =================================================================== --- src/gnome-utils/glade/preferences.glade (Revision 17148) +++ src/gnome-utils/glade/preferences.glade (Arbeitskopie) @@ -3095,29 +3095,23 @@ - + True - Number of _rows: + If checked, each register will be opened in its own top level window. If clear, the register will be opened in the current window. + True + Register opens in a new _window True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - gconf/general/register/number_of_rows - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + GTK_RELIEF_NORMAL + True + False + False + True 0 - 1 - 9 - 10 + 4 + 6 + 7 12 fill @@ -3125,6 +3119,54 @@ + + True + Show two lines of information for each transaction instead of one. Does not affect expanded transactions. + True + _Double line mode + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + 4 + 7 + 8 + 12 + fill + + + + + + + True + Show the full account names in register. If deactivated only the simple account name is shown. + True + _Show full account names + True + GTK_RELIEF_NORMAL + True + True + False + True + + + 0 + 4 + 8 + 9 + 12 + fill + + + + + True Number of _transactions: @@ -3146,8 +3188,8 @@ 0 1 - 8 - 9 + 9 + 10 12 fill @@ -3170,31 +3212,37 @@ 1 2 - 8 - 9 + 9 + 10 - + True - Show two lines of information for each transaction instead of one. Does not affect expanded transactions. - True - _Double line mode + Number of _rows: True - GTK_RELIEF_NORMAL - True - False - False - True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + gconf/general/register/number_of_rows + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 - 4 - 7 - 8 + 1 + 10 + 11 12 fill @@ -3202,30 +3250,6 @@ - - True - If checked, each register will be opened in its own top level window. If clear, the register will be opened in the current window. - True - Register opens in a new _window - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - 4 - 6 - 7 - 12 - fill - - - - - True Display this many rows when a register is created. @@ -3241,8 +3265,8 @@ 1 2 - 9 - 10 + 10 + 11 fill Index: src/gnome-utils/account-quickfill.c =================================================================== --- src/gnome-utils/account-quickfill.c (Revision 17148) +++ src/gnome-utils/account-quickfill.c (Arbeitskopie) @@ -40,7 +40,7 @@ #define NUM_ACCOUNT_COLUMNS 2 /* ===================================================================== */ -/* In order to speed up register starts for registers htat have a huge +/* In order to speed up register starts for registers that have a huge * number of accounts in them (where 'huge' is >500) we build a quickfill * cache of account names. This cache is needed because some users on * some machines experience register open times in the tens of seconds @@ -67,6 +67,9 @@ gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR, shared_quickfill_gconf_changed, qfb); + gnc_gconf_general_remove_cb(KEY_SHOW_FULL_ACCOUNT_NAMES, + shared_quickfill_gconf_changed, + qfb); gnc_quickfill_destroy (qfb->qf); g_object_unref(qfb->list_store); qof_event_unregister_handler (qfb->listener); @@ -109,7 +112,7 @@ load_shared_qf_cb (Account *account, gpointer data) { QFB *qfb = data; - char *name; + const char *name; GtkTreeIter iter; if (qfb->dont_add_cb) @@ -118,7 +121,7 @@ if (skip) return; } - name = xaccAccountGetFullName (account); + name = gnc_get_account_name_for_register (account); if (NULL == name) return; gnc_quickfill_insert (qfb->qf, name, QUICKFILL_ALPHA); if (qfb->load_list_store) { @@ -128,7 +131,6 @@ ACCOUNT_POINTER, account, -1); } - g_free(name); } static void @@ -169,6 +171,10 @@ shared_quickfill_gconf_changed, qfb); + gnc_gconf_general_register_cb(KEY_SHOW_FULL_ACCOUNT_NAMES, + shared_quickfill_gconf_changed, + qfb); + gnc_account_foreach_descendant(root, load_shared_qf_cb, qfb); qfb->load_list_store = FALSE; @@ -225,7 +231,7 @@ QFB *qfb = user_data; QuickFill *qf = qfb->qf; QuickFill *match; - char * name; + const char * name; const char *match_str; Account *account; GtkTreeIter iter; @@ -248,7 +254,7 @@ return; } - name = xaccAccountGetFullName (account); + name = gnc_get_account_name_for_register(account); if (NULL == name) { LEAVE("account has no name"); return; @@ -286,7 +292,7 @@ gtk_list_store_remove(qfb->list_store, &iter); } else { gtk_list_store_set(qfb->list_store, &iter, - ACCOUNT_NAME, xaccAccountGetFullName(account), + ACCOUNT_NAME, gnc_get_account_name_for_register(account), -1); } } @@ -365,7 +371,6 @@ g_list_free(data.accounts); if (data.refs) g_list_free(data.refs); - g_free(name); LEAVE(" "); } Index: src/gnome/schemas/apps_gnucash_general.schemas.in =================================================================== --- src/gnome/schemas/apps_gnucash_general.schemas.in (Revision 17148) +++ src/gnome/schemas/apps_gnucash_general.schemas.in (Arbeitskopie) @@ -452,6 +452,22 @@ + /schemas/apps/gnucash/general/register/show_full_account_names + /apps/gnucash/general/register/show_full_account_names + gnucash + bool + TRUE + + Show the full account names. + + Show the full name of the accounts in the register and in the auto + completion popup. If this is deselcted, only the last name of the account + path is shown, which implies that you use unique names. + + + + + /schemas/apps/gnucash/general/register/number_of_rows /apps/gnucash/general/register/number_of_rows gnucash Index: src/engine/Account.c =================================================================== --- src/engine/Account.c (Revision 17148) +++ src/engine/Account.c (Arbeitskopie) @@ -2491,6 +2491,39 @@ return NULL; } +Account * +gnc_account_lookup_by_code (const Account *parent, const char * code) +{ + AccountPrivate *cpriv, *ppriv; + Account *child, *result; + GList *node; + + g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL); + g_return_val_if_fail(code, NULL); + + /* first, look for accounts hanging off the current node */ + ppriv = GET_PRIVATE(parent); + for (node = ppriv->children; node; node = node->next) + { + child = node->data; + cpriv = GET_PRIVATE(child); + if (safe_strcmp(cpriv->accountCode, code) == 0) + return child; + } + + /* if we are still here, then we haven't found the account yet. + * Recursively search each of the child accounts next */ + for (node = ppriv->children; node; node = node->next) + { + child = node->data; + result = gnc_account_lookup_by_code (child, code); + if (result) + return result; + } + + return NULL; +} + /********************************************************************\ * Fetch an account, given its full name * \********************************************************************/ Index: src/engine/Account.h =================================================================== --- src/engine/Account.h (Revision 17148) +++ src/engine/Account.h (Arbeitskopie) @@ -878,7 +878,7 @@ /** @} */ -/** @name Getting Accounts and Subaccounts by Name +/** @name Lookup Accounts and Subaccounts by name or code @{ */ /** The gnc_account_lookup_by_name() subroutine fetches the account by @@ -899,6 +899,12 @@ Account *gnc_account_lookup_by_full_name (const Account *any_account, const gchar *name); +/** The gnc_account_lookup_by_code() subroutine works like + * gnc_account_lookup_by_name, but uses the account code. + */ +Account *gnc_account_lookup_by_code (const Account *parent, + const char *code); + /** @} */ /* ------------------ */ Index: src/app-utils/gnc-ui-util.h =================================================================== --- src/app-utils/gnc-ui-util.h (Revision 17148) +++ src/app-utils/gnc-ui-util.h (Arbeitskopie) @@ -57,6 +57,22 @@ Account * gnc_get_current_root_account (void); gnc_commodity_table * gnc_get_current_commodities (void); +/** + * Get either the full name of the account or the simple name, depending on the + * configuration parameter general/register/show_full_account_names. +*/ +const char* gnc_get_account_name_for_register(const Account *account); + +/** + * Retrieve the account matching the given name starting from the descandants of + * base_account. + * name is either considered to be a simple name or the full account name, + * depending on the configuration parameter + * general/register/show_full_account_names. +*/ +Account* +gnc_account_lookup_for_register(const Account *base_account, const char *name); + /* * This is a wrapper routine around an xaccGetBalanceInCurrency * function that handles additional needs of the gui. Index: src/app-utils/gnc-ui-util.c =================================================================== --- src/app-utils/gnc-ui-util.c (Revision 17148) +++ src/app-utils/gnc-ui-util.c (Arbeitskopie) @@ -212,6 +212,33 @@ return gnc_book_get_commodity_table (gnc_get_current_book ()); } +const char * +gnc_get_account_name_for_register(const Account *account) +{ + gboolean showFullNames; + showFullNames = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER, + KEY_SHOW_FULL_ACCOUNT_NAMES, NULL); + + if (showFullNames) + return xaccAccountGetFullName (account); + else + return xaccAccountGetName (account); +} + +Account * +gnc_account_lookup_for_register(const Account *base_account, const char *name) +{ + gboolean showFullNames; + showFullNames = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER, + KEY_SHOW_FULL_ACCOUNT_NAMES, NULL); + + if (showFullNames) + return gnc_account_lookup_by_full_name (base_account, name); + else + return gnc_account_lookup_by_name (base_account, name); +} + + /* * This is a wrapper routine around an xaccGetBalanceInCurrency * function that handles additional needs of the gui.