r17324 - gnucash/trunk - Bug #129099: Add option to toggle between full account path and leaf name in registers.

Andreas Köhler andi5 at cvs.gnucash.org
Sun Jul 13 17:28:45 EDT 2008


Author: andi5
Date: 2008-07-13 17:28:45 -0400 (Sun, 13 Jul 2008)
New Revision: 17324
Trac: http://svn.gnucash.org/trac/changeset/17324

Modified:
   gnucash/trunk/AUTHORS
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/app-utils/gnc-ui-util.h
   gnucash/trunk/src/business/business-ledger/gncEntryLedger.c
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerModel.c
   gnucash/trunk/src/core-utils/gnc-gconf-utils.h
   gnucash/trunk/src/gnome-utils/account-quickfill.c
   gnucash/trunk/src/gnome-utils/glade/preferences.glade
   gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
   gnucash/trunk/src/register/ledger-core/split-register-control.c
   gnucash/trunk/src/register/ledger-core/split-register-model.c
   gnucash/trunk/src/register/ledger-core/split-register.c
Log:
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.


Modified: gnucash/trunk/AUTHORS
===================================================================
--- gnucash/trunk/AUTHORS	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/AUTHORS	2008-07-13 21:28:45 UTC (rev 17324)
@@ -137,6 +137,7 @@
 Koen D'Hondt <ripley at xs4all.nl> for Solaris patches to XmHTML
 Bob Drzyzgula <bob at mostly.com> for budgeting design notes
 Volker Englisch <Volker at englisch.us> QA and testing
+Christoph Ernst <C.Ernst72 at googlemail.com> Small bugfixes and minor enhancements
 Jonathan Ernst <jonathan at ernstfamily.ch> Translations
 Stephen Evanchik <evanchsa at clarkson.edu> Logging improvements; gtk2 conversions
 Joshua Facemyer / Impressus Art <faceman at impressusart.com>: New artwork.

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -212,6 +212,33 @@
   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.

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h	2008-07-13 21:28:45 UTC (rev 17324)
@@ -57,6 +57,29 @@
 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.

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedger.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedger.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedger.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -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;
+  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 @@
     *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. */

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerModel.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerModel.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerModel.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -155,7 +155,7 @@
   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 @@
   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;
 }
 

Modified: gnucash/trunk/src/core-utils/gnc-gconf-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2008-07-13 21:28:45 UTC (rev 17324)
@@ -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);

Modified: gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
===================================================================
--- gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in	2008-07-13 21:28:45 UTC (rev 17324)
@@ -452,6 +452,23 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnucash/general/register/show_leaf_account_names</key>
+      <applyto>/apps/gnucash/general/register/show_leaf_account_names</applyto>
+      <owner>gnucash</owner>
+      <type>bool</type>
+      <default>FALSE</default>
+      <locale name="C">
+        <short>Only display leaf account names.</short>
+        <long>
+          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.
+        </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnucash/general/register/number_of_rows</key>
       <applyto>/apps/gnucash/general/register/number_of_rows</applyto>
       <owner>gnucash</owner>

Modified: gnucash/trunk/src/gnome-utils/account-quickfill.c
===================================================================
--- gnucash/trunk/src/gnome-utils/account-quickfill.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/gnome-utils/account-quickfill.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -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_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 @@
      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 @@
 				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 @@
     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 @@
 	    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);
 	}
       }
 

Modified: gnucash/trunk/src/gnome-utils/glade/preferences.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/glade/preferences.glade	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/gnome-utils/glade/preferences.glade	2008-07-13 21:28:45 UTC (rev 17324)
@@ -3116,8 +3116,8 @@
 		<packing>
 		  <property name="left_attach">0</property>
 		  <property name="right_attach">1</property>
-		  <property name="top_attach">9</property>
-		  <property name="bottom_attach">10</property>
+		  <property name="top_attach">10</property>
+		  <property name="bottom_attach">11</property>
 		  <property name="x_padding">12</property>
 		  <property name="x_options">fill</property>
 		  <property name="y_options"></property>
@@ -3146,8 +3146,8 @@
 		<packing>
 		  <property name="left_attach">0</property>
 		  <property name="right_attach">1</property>
-		  <property name="top_attach">8</property>
-		  <property name="bottom_attach">9</property>
+		  <property name="top_attach">9</property>
+		  <property name="bottom_attach">10</property>
 		  <property name="x_padding">12</property>
 		  <property name="x_options">fill</property>
 		  <property name="y_options"></property>
@@ -3170,8 +3170,8 @@
 		<packing>
 		  <property name="left_attach">1</property>
 		  <property name="right_attach">2</property>
-		  <property name="top_attach">8</property>
-		  <property name="bottom_attach">9</property>
+		  <property name="top_attach">9</property>
+		  <property name="bottom_attach">10</property>
 		  <property name="x_options"></property>
 		  <property name="y_options"></property>
 		</packing>
@@ -3226,6 +3226,30 @@
 	      </child>
 
 	      <child>
+		<widget class="GtkCheckButton" id="gconf/general/register/show_leaf_account_names">
+		  <property name="visible">True</property>
+		  <property name="tooltip" translatable="yes">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.</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">_Only display leaf account names</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		  <property name="focus_on_click">True</property>
+		  <property name="active">False</property>
+		  <property name="inconsistent">False</property>
+		  <property name="draw_indicator">True</property>
+		</widget>
+		<packing>
+		  <property name="left_attach">0</property>
+		  <property name="right_attach">4</property>
+		  <property name="top_attach">8</property>
+		  <property name="bottom_attach">9</property>
+		  <property name="x_padding">12</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options"></property>
+		</packing>
+	      </child>
+
+	      <child>
 		<widget class="GtkSpinButton" id="gconf/general/register/number_of_rows">
 		  <property name="visible">True</property>
 		  <property name="tooltip" translatable="yes">Display this many rows when a register is created.</property>
@@ -3241,8 +3265,8 @@
 		<packing>
 		  <property name="left_attach">1</property>
 		  <property name="right_attach">2</property>
-		  <property name="top_attach">9</property>
-		  <property name="bottom_attach">10</property>
+		  <property name="top_attach">10</property>
+		  <property name="bottom_attach">11</property>
 		  <property name="x_options">fill</property>
 		  <property name="y_options"></property>
 		</packing>

Modified: gnucash/trunk/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-control.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/register/ledger-core/split-register-control.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -750,7 +750,7 @@
 
     case CURSOR_CLASS_SPLIT:
       {
-        char *fullname;
+        char *account_name;
         const char *memo;
         gboolean unit_price;
         Split *auto_split;
@@ -820,9 +820,9 @@
         /* 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);
 

Modified: gnucash/trunk/src/register/ledger-core/split-register-model.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/register/ledger-core/split-register-model.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -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)
@@ -1205,7 +1205,7 @@
 
   g_free (name);
 
-  name = xaccAccountGetFullName (xaccSplitGetAccount (split));
+  name = gnc_get_account_name_for_register (xaccSplitGetAccount (split));
 
   return name;
 }
@@ -1246,7 +1246,7 @@
   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 @@
 
     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;

Modified: gnucash/trunk/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.c	2008-07-13 19:58:11 UTC (rev 17323)
+++ gnucash/trunk/src/register/ledger-core/split-register.c	2008-07-13 21:28:45 UTC (rev 17324)
@@ -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;
+  char *account_name;
   ComboCell *cell = (ComboCell *) bcell;
   Account *account;
 
@@ -1506,7 +1506,7 @@
     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 @@
 
   /* 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)) {



More information about the gnucash-changes mailing list