From 1a25b2bc39b0db123bc6bd2f3e344f4f94a180b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Sun, 13 Jul 2008 21:28:45 +0000 Subject: [PATCH] Bug #129099: Add option to toggle between full account path and leaf name in registers. * Introduce new property show_full_account_names to the schema general/register to toggle between full account path and leaf name * Configuration in Preferences dialog ("Register Defaults") * Convenience functions gnc_get_account_name_for_register() and gnc_account_lookup_for_register() return the proper values depending on the configurations. * Ledgers and registers use the new functions for displaying account names (applies also to business-ledger) * account-quickfill uses gnc_get_account_name_for_register() and listens to gconf property Patch from Christoph Ernst. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17324 57a11ea4-9604-0410-9ed3-97b8803252fd --- AUTHORS | 1 + src/app-utils/gnc-ui-util.c | 27 +++++++++++++ src/app-utils/gnc-ui-util.h | 23 +++++++++++ src/business/business-ledger/gncEntryLedger.c | 10 ++--- .../business-ledger/gncEntryLedgerModel.c | 4 +- src/core-utils/gnc-gconf-utils.h | 1 + src/gnome-utils/account-quickfill.c | 17 ++++++-- src/gnome-utils/glade/preferences.glade | 40 +++++++++++++++---- .../schemas/apps_gnucash_general.schemas.in | 17 ++++++++ .../ledger-core/split-register-control.c | 8 ++-- .../ledger-core/split-register-model.c | 8 ++-- src/register/ledger-core/split-register.c | 10 ++--- 12 files changed, 134 insertions(+), 32 deletions(-) diff --git a/AUTHORS b/AUTHORS index a2cb09f0ac..b9e49a638f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -137,6 +137,7 @@ Tyson Dowd for config/make patches & debian maint Koen D'Hondt for Solaris patches to XmHTML Bob Drzyzgula for budgeting design notes Volker Englisch QA and testing +Christoph Ernst Small bugfixes and minor enhancements Jonathan Ernst Translations Stephen Evanchik Logging improvements; gtk2 conversions Joshua Facemyer / Impressus Art : New artwork. diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index e659616f8b..ad3aa49a08 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -212,6 +212,33 @@ gnc_get_current_commodities (void) return gnc_book_get_commodity_table (gnc_get_current_book ()); } +gchar * +gnc_get_account_name_for_register(const Account *account) +{ + gboolean show_leaf_accounts; + show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER, + KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL); + + if (show_leaf_accounts) + return g_strdup (xaccAccountGetName (account)); + else + return xaccAccountGetFullName (account); +} + +Account * +gnc_account_lookup_for_register(const Account *base_account, const char *name) +{ + gboolean show_leaf_accounts; + show_leaf_accounts = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER, + KEY_SHOW_LEAF_ACCOUNT_NAMES, NULL); + + if (show_leaf_accounts) + return gnc_account_lookup_by_name (base_account, name); + else + return gnc_account_lookup_by_full_name (base_account, name); +} + + /* * This is a wrapper routine around an xaccGetBalanceInCurrency * function that handles additional needs of the gui. diff --git a/src/app-utils/gnc-ui-util.h b/src/app-utils/gnc-ui-util.h index 6ff5a0ffd2..e163927ba1 100644 --- a/src/app-utils/gnc-ui-util.h +++ b/src/app-utils/gnc-ui-util.h @@ -57,6 +57,29 @@ QofBook * gnc_get_current_book (void); 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_leaf_account_names. + * + * @param account The account to retrieve the name for. + * @return A newly allocated string. +*/ +gchar *gnc_get_account_name_for_register(const Account *account); + +/** + * Retrieve the account matching the given name starting from the descandants of + * base_account. + * @a name is either considered to be the name of the leaf in the account tree + * or to be the full account path, depending on the configuration parameter + * general/register/show_leaf_account_names. + * + * @param base_account The account to start the search at. + * @param name The name to search for. + * @return A pointer to the account, or NULL if the account was not found. +*/ +Account *gnc_account_lookup_for_register(const Account *base_account, const + gchar *name); + /* * This is a wrapper routine around an xaccGetBalanceInCurrency * function that handles additional needs of the gui. diff --git a/src/business/business-ledger/gncEntryLedger.c b/src/business/business-ledger/gncEntryLedger.c index dfd8f2916f..971ba5271a 100644 --- a/src/business/business-ledger/gncEntryLedger.c +++ b/src/business/business-ledger/gncEntryLedger.c @@ -81,12 +81,12 @@ gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell, 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; + 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,10 @@ gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell, *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); + g_free (account_name); } /* See if the account (either old or new) is a placeholder. */ diff --git a/src/business/business-ledger/gncEntryLedgerModel.c b/src/business/business-ledger/gncEntryLedgerModel.c index abeb84c54c..124ec68b21 100644 --- a/src/business/business-ledger/gncEntryLedgerModel.c +++ b/src/business/business-ledger/gncEntryLedgerModel.c @@ -155,7 +155,7 @@ static const char * get_iacct_entry (VirtualLocation virt_loc, entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); g_free (name); - name = xaccAccountGetFullName (gncEntryGetInvAccount (entry)); + name = gnc_get_account_name_for_register (gncEntryGetInvAccount (entry)); return name; } @@ -172,7 +172,7 @@ static const char * get_bacct_entry (VirtualLocation virt_loc, entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); g_free (name); - name = xaccAccountGetFullName (gncEntryGetBillAccount (entry)); + name = gnc_get_account_name_for_register (gncEntryGetBillAccount (entry)); return name; } diff --git a/src/core-utils/gnc-gconf-utils.h b/src/core-utils/gnc-gconf-utils.h index de544a27e6..c3df965b30 100644 --- a/src/core-utils/gnc-gconf-utils.h +++ b/src/core-utils/gnc-gconf-utils.h @@ -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_LEAF_ACCOUNT_NAMES "show_leaf_account_names" typedef void (*GncGconfGeneralCb) (GConfEntry *entry, gpointer user_data); typedef void (*GncGconfGeneralAnyCb) (gpointer user_data); diff --git a/src/gnome-utils/account-quickfill.c b/src/gnome-utils/account-quickfill.c index 61f7ba08eb..b90a48fe28 100644 --- a/src/gnome-utils/account-quickfill.c +++ b/src/gnome-utils/account-quickfill.c @@ -40,7 +40,7 @@ static void listen_for_account_events (QofInstance *entity, QofEventId event_t #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 @@ shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data) gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR, shared_quickfill_gconf_changed, qfb); + gnc_gconf_general_remove_cb(KEY_SHOW_LEAF_ACCOUNT_NAMES, + shared_quickfill_gconf_changed, + qfb); gnc_quickfill_destroy (qfb->qf); g_object_unref(qfb->list_store); qof_event_unregister_handler (qfb->listener); @@ -118,7 +121,7 @@ load_shared_qf_cb (Account *account, gpointer data) 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) { @@ -169,6 +172,10 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key, shared_quickfill_gconf_changed, qfb); + gnc_gconf_general_register_cb(KEY_SHOW_LEAF_ACCOUNT_NAMES, + shared_quickfill_gconf_changed, + qfb); + gnc_account_foreach_descendant(root, load_shared_qf_cb, qfb); qfb->load_list_store = FALSE; @@ -248,7 +255,7 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type, return; } - name = xaccAccountGetFullName (account); + name = gnc_get_account_name_for_register(account); if (NULL == name) { LEAVE("account has no name"); return; @@ -285,9 +292,11 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type, qfb->dont_add_cb(account, qfb->dont_add_data)) { gtk_list_store_remove(qfb->list_store, &iter); } else { + gchar *aname = gnc_get_account_name_for_register(account); gtk_list_store_set(qfb->list_store, &iter, - ACCOUNT_NAME, xaccAccountGetFullName(account), + ACCOUNT_NAME, aname, -1); + g_free(aname); } } diff --git a/src/gnome-utils/glade/preferences.glade b/src/gnome-utils/glade/preferences.glade index 3f715d534f..bf18783c9d 100644 --- a/src/gnome-utils/glade/preferences.glade +++ b/src/gnome-utils/glade/preferences.glade @@ -3116,8 +3116,8 @@ 0 1 - 9 - 10 + 10 + 11 12 fill @@ -3146,8 +3146,8 @@ 0 1 - 8 - 9 + 9 + 10 12 fill @@ -3170,8 +3170,8 @@ 1 2 - 8 - 9 + 9 + 10 @@ -3225,6 +3225,30 @@ + + + True + If checked, only the names of the leaf accounts are displayed in the register and in the account selection popup. The default behaviour is to display the full name, including the path in the account tree. Cecking this option implies that you use unique leaf names. + True + _Only display leaf account names + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + 4 + 8 + 9 + 12 + fill + + + + True @@ -3241,8 +3265,8 @@ 1 2 - 9 - 10 + 10 + 11 fill diff --git a/src/gnome/schemas/apps_gnucash_general.schemas.in b/src/gnome/schemas/apps_gnucash_general.schemas.in index 4a4e9cf7fc..d3daffab17 100644 --- a/src/gnome/schemas/apps_gnucash_general.schemas.in +++ b/src/gnome/schemas/apps_gnucash_general.schemas.in @@ -451,6 +451,23 @@ + + /schemas/apps/gnucash/general/register/show_leaf_account_names + /apps/gnucash/general/register/show_leaf_account_names + gnucash + bool + FALSE + + Only display leaf account names. + + Show only the names of the leaf accounts in the register and in the + account selection popup. The default behaviour is to display the full + name, including the path in the account tree. Activating this option + implies that you use unique leaf names. + + + + /schemas/apps/gnucash/general/register/number_of_rows /apps/gnucash/general/register/number_of_rows diff --git a/src/register/ledger-core/split-register-control.c b/src/register/ledger-core/split-register-control.c index ee799be76f..eac56da7d0 100644 --- a/src/register/ledger-core/split-register-control.c +++ b/src/register/ledger-core/split-register-control.c @@ -750,7 +750,7 @@ gnc_split_register_auto_completion (SplitRegister *reg, case CURSOR_CLASS_SPLIT: { - char *fullname; + char *account_name; const char *memo; gboolean unit_price; Split *auto_split; @@ -820,9 +820,9 @@ gnc_split_register_auto_completion (SplitRegister *reg, /* 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); + g_free(account_name); gnc_basic_cell_set_changed (cell, TRUE); diff --git a/src/register/ledger-core/split-register-model.c b/src/register/ledger-core/split-register-model.c index 75098cccc6..c2c780378a 100644 --- a/src/register/ledger-core/split-register-model.c +++ b/src/register/ledger-core/split-register-model.c @@ -82,7 +82,7 @@ gnc_split_register_use_security_cells (SplitRegister *reg, 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) @@ -1205,7 +1205,7 @@ gnc_split_register_get_xfrm_entry (VirtualLocation virt_loc, g_free (name); - name = xaccAccountGetFullName (xaccSplitGetAccount (split)); + name = gnc_get_account_name_for_register (xaccSplitGetAccount (split)); return name; } @@ -1246,7 +1246,7 @@ gnc_split_register_get_mxfrm_entry (VirtualLocation virt_loc, 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, @@ -1737,7 +1737,7 @@ gnc_template_register_get_xfrm_entry (VirtualLocation virt_loc, 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; diff --git a/src/register/ledger-core/split-register.c b/src/register/ledger-core/split-register.c index 2c6bbe59c1..6e1dd98f2e 100644 --- a/src/register/ledger-core/split-register.c +++ b/src/register/ledger-core/split-register.c @@ -1498,7 +1498,7 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, 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; + char *account_name; ComboCell *cell = (ComboCell *) bcell; Account *account; @@ -1506,7 +1506,7 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, 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 (!account) account = gnc_account_lookup_by_code (gnc_get_current_root_account (), name); @@ -1525,10 +1525,10 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, /* Now have the account. Update the cell with the name as created. */ *refresh = TRUE; - 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); + g_free (account_name); /* See if the account (either old or new) is a placeholder. */ if (xaccAccountGetPlaceholder (account)) {