gnucash master: Bug 797472 - Add option to choose account templates

Robert Fewell bobit at code.gnucash.org
Sat Jan 25 08:08:26 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/b4e67782 (commit)
	from  https://github.com/Gnucash/gnucash/commit/c77e1975 (commit)



commit b4e677826c9e99573160bf91b3799b486dc5722e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri Dec 6 15:44:47 2019 +0000

    Bug 797472 - Add option to choose account templates
    
    In the account hierarchy assistant the choice of account template was
    decided by the your locale and so could be limited. Add two combos so
    you can select account templates by language and region.

diff --git a/gnucash/gnome/assistant-hierarchy.c b/gnucash/gnome/assistant-hierarchy.c
index 96449d6fc..a67c42272 100644
--- a/gnucash/gnome/assistant-hierarchy.c
+++ b/gnucash/gnome/assistant-hierarchy.c
@@ -94,6 +94,8 @@ typedef struct
 
     GtkWidget   *language_combo;
     GtkWidget   *region_combo;
+    GtkWidget   *region_label;
+
     const gchar *gnc_accounts_dir;
 
     GtkTreeView *categories_tree;
@@ -315,6 +317,7 @@ region_combo_changed_cb (GtkComboBox *widget, hierarchy_data  *data)
     if (gtk_combo_box_get_active_iter (widget, &filter_iter))
     {
         GtkListStore *cat_list = GTK_LIST_STORE(gtk_tree_view_get_model (data->categories_tree));
+        GtkTreeModel *cat_model = gtk_tree_view_get_model (data->categories_tree);
         GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(data->categories_tree));
         GSList *list;
         GtkTreePath *path;
@@ -325,13 +328,22 @@ region_combo_changed_cb (GtkComboBox *widget, hierarchy_data  *data)
 
         gtk_tree_model_get (region_model, &region_iter, LANG_REG_STRING, &lang_reg, -1);
 
+        gnc_suspend_gui_refresh ();
+
+        /* Remove the old account tree */
+        if (data->category_accounts_tree)
+            gtk_widget_destroy(GTK_WIDGET(data->category_accounts_tree));
+        data->category_accounts_tree = NULL;
+
         // clear the categories list store in prep for new load
         if (cat_list)
             gtk_list_store_clear (cat_list);
 
         account_path = g_build_filename (data->gnc_accounts_dir, lang_reg, NULL);
 
+        qof_event_suspend ();
         list = gnc_load_example_account_list (account_path);
+        qof_event_resume ();
 
         if (data->initial_category)
         {
@@ -356,6 +368,10 @@ region_combo_changed_cb (GtkComboBox *widget, hierarchy_data  *data)
 
         // now load the account tree
         categories_tree_selection_changed (selection, data);
+
+        gnc_resume_gui_refresh ();
+
+        g_slist_free (list);
     }
     g_free (account_path);
     g_free (lang_reg);
@@ -368,6 +384,7 @@ region_combo_change_filter_cb (GtkComboBox *widget, hierarchy_data  *data)
     GtkTreeModel *filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX(data->region_combo));
     GtkTreeModel *region_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter_model));
     GtkTreeIter language_iter, region_iter, sorted_iter;
+    gboolean have_one_region = FALSE;
 
     if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX(data->language_combo), &sorted_iter))
     {
@@ -411,20 +428,41 @@ region_combo_change_filter_cb (GtkComboBox *widget, hierarchy_data  *data)
             valid = gtk_tree_model_iter_next (region_model, &region_iter);
         }
 
-        // clear the categories list store in prep for new load
-        if (cat_list)
-            gtk_list_store_clear (cat_list);
-
         // if we only have a language or just one region activate it
         if (count == 1)
         {
+            gchar *region_label = NULL;
             GtkTreeIter filter_iter;
             gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER(filter_model),
                                                               &filter_iter,
                                                               iter);
 
             gtk_combo_box_set_active_iter (GTK_COMBO_BOX(data->region_combo), &filter_iter);
+
+            have_one_region = TRUE;
+
+            gtk_tree_model_get (region_model, iter, REGION_STRING, &region_label, -1);
+
+            gtk_label_set_text (GTK_LABEL(data->region_label), region_label);
+            g_free (region_label);
+        }
+        else
+        {
+            // if the combo is not already active, set it to first on in filtered list
+            if (gtk_combo_box_get_active (GTK_COMBO_BOX(data->region_combo)) == -1)
+            {
+                GtkTreeIter filter_iter;
+
+                gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER(filter_model),
+                                                                  &filter_iter,
+                                                                  iter);
+
+                gtk_combo_box_set_active_iter (GTK_COMBO_BOX(data->region_combo), &filter_iter);
+            }
         }
+        gtk_widget_set_visible (GTK_WIDGET(data->region_label), have_one_region);
+        gtk_widget_set_visible (GTK_WIDGET(data->region_combo), !have_one_region);
+
         gtk_tree_iter_free (iter);
         g_free (language);
     }
@@ -687,7 +725,9 @@ account_categories_tree_view_prepare (hierarchy_data  *data)
     data->gnc_accounts_dir = gnc_path_get_accountsdir ();
     locale_dir = gnc_get_ea_locale_dir (data->gnc_accounts_dir);
 
+    qof_event_suspend ();
     list = gnc_load_example_account_list (locale_dir);
+    qof_event_resume ();
 
     update_language_region_combos (data, locale_dir);
 
@@ -740,14 +780,20 @@ account_categories_tree_view_prepare (hierarchy_data  *data)
                                           COL_TITLE,
                                           GTK_SORT_ASCENDING);
 
+    selection = gtk_tree_view_get_selection (tree_view);
+
     if (data->initial_category)
     {
-        path = gtk_tree_row_reference_get_path(data->initial_category);
-        selection = gtk_tree_view_get_selection(tree_view);
-        gtk_tree_view_scroll_to_cell(tree_view, path, NULL, TRUE, 0.5, 0.5);
-        gtk_tree_selection_select_path(selection, path);
-        gtk_tree_path_free(path);
+        path = gtk_tree_row_reference_get_path (data->initial_category);
+        gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.5, 0.5);
     }
+    else
+        path = gtk_tree_path_new_first ();
+
+    gtk_tree_selection_select_path (selection, path);
+    gtk_tree_path_free (path);
+
+    g_slist_free (list);
 }
 
 void on_prepare (GtkAssistant  *assistant, GtkWidget *page,
@@ -1566,6 +1612,7 @@ gnc_create_hierarchy_assistant (gboolean use_defaults, GncHierarchyAssistantFini
 
     data->language_combo = GTK_WIDGET(gtk_builder_get_object (builder, "language_combo"));
     data->region_combo = GTK_WIDGET(gtk_builder_get_object (builder, "region_combo"));
+    data->region_label = GTK_WIDGET(gtk_builder_get_object (builder, "region_label"));
 
     data->category_accounts_label = GTK_LABEL(gtk_builder_get_object (builder, "accounts_in_category_label"));
     data->category_accounts_container = GTK_WIDGET(gtk_builder_get_object (builder, "accounts_in_category"));
diff --git a/gnucash/gtkbuilder/assistant-hierarchy.glade b/gnucash/gtkbuilder/assistant-hierarchy.glade
index 66b5ed442..426ab8b0a 100644
--- a/gnucash/gtkbuilder/assistant-hierarchy.glade
+++ b/gnucash/gtkbuilder/assistant-hierarchy.glade
@@ -108,131 +108,13 @@ Please choose the currency to use for new accounts.</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Selecting a different Language/Region will show the categories that are available for that selection.</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">center</property>
-            <property name="margin_top">12</property>
-            <property name="spacing">6</property>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Language</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="language_combo">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkCellRendererText" id="cellrenderertext1"/>
-                  <attributes>
-                    <attribute name="text">0</attribute>
-                  </attributes>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Region</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="region_combo">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkCellRendererText" id="cellrenderertext2"/>
-                  <attributes>
-                    <attribute name="text">1</attribute>
-                  </attributes>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_left">6</property>
-            <property name="margin_right">6</property>
-            <property name="margin_top">12</property>
-            <property name="label" translatable="yes">If not satisfied with the available templates, please read the wiki page linked below and share your new or improved template.</property>
-            <property name="use_markup">True</property>
-            <property name="wrap">True</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLinkButton">
-            <property name="label" translatable="yes">GnuCash Account Template Wiki</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="relief">none</property>
-            <property name="uri">https://wiki.gnucash.org/wiki/Account_Hierarchy_Template</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">3</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkLabel" id="pickAccountsDescriptionLabel">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="margin_left">6</property>
             <property name="margin_right">6</property>
-            <property name="label" translatable="yes">Select categories that correspond to the ways that you foresee you will use GnuCash. Each category you select will cause several accounts to be created.
-
-<b>Note:</b> the selection you make here is only the starting point for your personalized account hierarchy. Accounts can be added, renamed, moved, or deleted by hand later at any time.</property>
+            <property name="label" translatable="yes">Select language and region specific categories that correspond to the ways that you foresee you will use GnuCash. Each category you select will cause several accounts to be created.</property>
             <property name="use_markup">True</property>
             <property name="wrap">True</property>
             <property name="width_chars">75</property>
@@ -240,13 +122,14 @@ Please choose the currency to use for new accounts.</property>
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="position">4</property>
+            <property name="position">0</property>
           </packing>
         </child>
         <child>
           <object class="GtkPaned" id="hpaned100">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="margin_top">12</property>
             <property name="position">300</property>
             <property name="position_set">True</property>
             <child>
@@ -270,11 +153,68 @@ Please choose the currency to use for new accounts.</property>
                         <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
-                          <object class="GtkLabel" id="label101">
+                          <object class="GtkBox">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="label" translatable="yes"><b>Categories</b></property>
-                            <property name="use_markup">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkLabel" id="label101">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes"><b>Categories</b></property>
+                                <property name="use_markup">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkComboBox" id="language_combo">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="cellrenderertext3"/>
+                                  <attributes>
+                                    <attribute name="text">0</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkComboBox" id="region_combo">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="cellrenderertext4"/>
+                                  <attributes>
+                                    <attribute name="text">1</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="region_label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">3</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -468,7 +408,104 @@ Please choose the currency to use for new accounts.</property>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">5</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="margin_left">6</property>
+            <property name="margin_right">6</property>
+            <property name="label" translatable="yes"><b>Notes</b></property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">6</property>
+            <property name="margin_right">6</property>
+            <property name="row_spacing">3</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="label" translatable="yes">•</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="label" translatable="yes">•</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">If not satisfied with the available templates, please read the wiki page linked below and share your new or improved template.</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">The selection you make here is only the starting point for your personalized account hierarchy. Accounts can be added, renamed, moved, or deleted by hand later at any time.</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLinkButton">
+            <property name="label" translatable="yes">GnuCash Account Template Wiki</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="relief">none</property>
+            <property name="uri">https://wiki.gnucash.org/wiki/Account_Hierarchy_Template</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">4</property>
           </packing>
         </child>
       </object>



Summary of changes:
 gnucash/gnome/assistant-hierarchy.c          |  65 +++++-
 gnucash/gtkbuilder/assistant-hierarchy.glade | 285 +++++++++++++++------------
 2 files changed, 217 insertions(+), 133 deletions(-)



More information about the gnucash-changes mailing list