gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Mar 21 10:35:46 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/7e65496a (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ad34bf0f (commit)
	from  https://github.com/Gnucash/gnucash/commit/e9a27f0e (commit)



commit 7e65496a5f081a4292c2a4994f2f64f9dbc413f4
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Mar 18 10:20:54 2017 +0000

    Bug 603379 - Prevent changing some Account Options if it has transactions
    
    There are some account options that it does not make sense to change
    once it contains transactions so prevent them from changing.

diff --git a/src/gnome-utils/dialog-account.c b/src/gnome-utils/dialog-account.c
index 66a1317..20c5231 100644
--- a/src/gnome-utils/dialog-account.c
+++ b/src/gnome-utils/dialog-account.c
@@ -1308,6 +1308,7 @@ gnc_account_window_create(AccountWindow *aw)
     GtkWidget *label;
     GtkBuilder  *builder;
     GtkTreeSelection *selection;
+    const gchar *tt = _("This Account contains Transactions.\nChanging this option is not possible.");
 
     ENTER("aw %p, modal %d", aw, aw->modal);
     builder = gtk_builder_new();
@@ -1338,8 +1339,21 @@ gnc_account_window_create(AccountWindow *aw)
                          gnc_commodity_edit_get_string,
                          gnc_commodity_edit_new_select,
                          &aw->commodity_mode);
-    gtk_box_pack_start(GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
-    gtk_widget_show (aw->commodity_edit);
+
+    // If the account has transactions, prevent changes by displaying a label and tooltip
+    if (xaccAccountCountSplits (aw_get_account (aw), FALSE) > 0)
+    {
+        const gchar *sec_name = gnc_commodity_get_printname (xaccAccountGetCommodity(aw_get_account (aw)));
+        GtkWidget *label = gtk_label_new (sec_name);
+        gtk_widget_set_tooltip_text (label, tt);
+        gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
+        gtk_widget_show (label);
+    }
+    else
+    {
+        gtk_box_pack_start(GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
+        gtk_widget_show (aw->commodity_edit);
+    }
 
     label = GTK_WIDGET(gtk_builder_get_object (builder, "security_label"));
     gnc_general_select_make_mnemonic_target (GNC_GENERAL_SELECT(aw->commodity_edit), label);
@@ -1401,6 +1415,22 @@ gnc_account_window_create(AccountWindow *aw)
     aw->type_view = GTK_WIDGET(gtk_builder_get_object (builder, "type_view"));
     gnc_account_type_view_create (aw);
 
+    // If the account has transactions, prevent changes by displaying a label and tooltip
+    if (xaccAccountCountSplits (aw_get_account (aw), FALSE) > 0)
+    {
+        GNCAccountType atype = xaccAccountGetType (aw_get_account (aw));
+        GtkWidget *label = gtk_label_new (xaccAccountGetTypeStr (atype));
+        GtkWidget *vbox = GTK_WIDGET(gtk_builder_get_object (builder, "type_vbox"));
+        GtkWidget *parent_widget = gtk_widget_get_parent (GTK_WIDGET(aw->type_view));
+
+        g_object_ref (G_OBJECT(aw->type_view));
+        gtk_container_remove (GTK_CONTAINER(vbox), parent_widget);
+        gtk_widget_set_tooltip_text (label, tt);
+        gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_widget_show (label);
+    }
+
     gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
 
     gtk_widget_grab_focus(GTK_WIDGET(aw->name_entry));
diff --git a/src/gnome-utils/gtkbuilder/dialog-account.glade b/src/gnome-utils/gtkbuilder/dialog-account.glade
index d77ea9e..4c56d5a 100644
--- a/src/gnome-utils/gtkbuilder/dialog-account.glade
+++ b/src/gnome-utils/gtkbuilder/dialog-account.glade
@@ -496,18 +496,29 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkScrolledWindow" id="scrolledwindow32">
+                      <object class="GtkVBox" id="type_vbox">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="hscrollbar_policy">never</property>
-                        <property name="vscrollbar_policy">automatic</property>
-                        <property name="shadow_type">in</property>
+                        <property name="can_focus">False</property>
                         <child>
-                          <object class="GtkTreeView" id="type_view">
+                          <object class="GtkScrolledWindow" id="scrolledwindow32">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="headers_visible">False</property>
+                            <property name="hscrollbar_policy">never</property>
+                            <property name="vscrollbar_policy">automatic</property>
+                            <property name="shadow_type">in</property>
+                            <child>
+                              <object class="GtkTreeView" id="type_view">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="headers_visible">False</property>
+                              </object>
+                            </child>
                           </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
                         </child>
                       </object>
                       <packing>

commit ad34bf0faafaef9e384d0f34c288e9ac84325abb
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Mar 18 12:25:52 2017 +0000

    Bug 603379 - Count the splits in an Account.
    
    This procedure is all ready in master and is used to count the number of
     splits in an account or the account and descendants.

diff --git a/src/engine/Account.c b/src/engine/Account.c
index 922ce0f..9099978 100644
--- a/src/engine/Account.c
+++ b/src/engine/Account.c
@@ -3607,6 +3607,25 @@ xaccAccountGetSplitList (const Account *acc)
     return GET_PRIVATE(acc)->splits;
 }
 
+gint64
+xaccAccountCountSplits (const Account *acc, gboolean include_children)
+{
+    gint64 nr, i;
+
+    nr = 0;
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
+
+    nr = g_list_length(xaccAccountGetSplitList(acc));
+    if (include_children && (gnc_account_n_children(acc) != 0))
+    {
+        for (i=0; i < gnc_account_n_children(acc); i++)
+        {
+            nr += xaccAccountCountSplits(gnc_account_nth_child(acc, i), TRUE);
+        }
+    }
+    return nr;
+}
+
 LotList *
 xaccAccountGetLotList (const Account *acc)
 {
diff --git a/src/engine/Account.h b/src/engine/Account.h
index 48cde10..e776110 100644
--- a/src/engine/Account.h
+++ b/src/engine/Account.h
@@ -979,6 +979,15 @@ gboolean xaccAccountIsEquityType(GNCAccountType t);
  */
 SplitList* xaccAccountGetSplitList (const Account *account);
 
+/** The xaccAccountCountSplits() routine returns the number of all
+ *    the splits in the account.
+ * @param acc the account for which to count the splits
+ *
+ * @param include_children also count splits in descendants (TRUE) or
+ *        for this account only (FALSE).
+ */
+gint64 xaccAccountCountSplits (const Account *acc, gboolean include_children);
+
 /** The xaccAccountMoveAllSplits() routine reassigns each of the splits
  *  in accfrom to accto. */
 void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);



Summary of changes:
 src/engine/Account.c                            | 19 ++++++++++++++
 src/engine/Account.h                            |  9 +++++++
 src/gnome-utils/dialog-account.c                | 34 +++++++++++++++++++++++--
 src/gnome-utils/gtkbuilder/dialog-account.glade | 25 +++++++++++++-----
 4 files changed, 78 insertions(+), 9 deletions(-)



More information about the gnucash-changes mailing list