gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Sep 17 03:42:22 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/9a8bc8f7 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/596ff269 (commit)
	from  https://github.com/Gnucash/gnucash/commit/8dd063b8 (commit)



commit 9a8bc8f7e5b8f44076297689adfa698929a77f2b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Sep 17 14:17:50 2022 +0800

    [assistant-stock-transaction] disallow selection in summary table
    
    ... because selection hides the red color from last commit. There's no
    action attached to selection in the treeview. It can be disabled.

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 09f283d3a..bca3653d9 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -1236,6 +1236,8 @@ get_treeview (GtkBuilder *builder, const gchar *treeview_label)
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING);
     gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
+    gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view),
+                                 GTK_SELECTION_NONE);
     g_object_unref(store);
 
     auto renderer = gtk_cell_renderer_text_new();

commit 596ff26928b55a3d3eb887affbe087f736359fb0
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Sep 17 13:37:04 2022 +0800

    [assistant-stock-transaction] if negative Units, render in red color
    
    ...in the summary table

diff --git a/gnucash/gnome/assistant-stock-transaction.cpp b/gnucash/gnome/assistant-stock-transaction.cpp
index 03b9105b8..09f283d3a 100644
--- a/gnucash/gnome/assistant-stock-transaction.cpp
+++ b/gnucash/gnome/assistant-stock-transaction.cpp
@@ -38,6 +38,7 @@ extern "C" {
 #include "assistant-stock-transaction.h"
 #include "gnc-account-sel.h"
 #include "gnc-amount-edit.h"
+#include "gnc-prefs.h"
 #include "gnc-component-manager.h"
 #include "gnc-date-edit.h"
 #include "gnc-tree-view-account.h"
@@ -79,6 +80,7 @@ enum split_cols
     SPLIT_COL_DEBIT,
     SPLIT_COL_CREDIT,
     SPLIT_COL_UNITS,
+    SPLIT_COL_UNITS_COLOR,
     NUM_SPLIT_COLS
 };
 
@@ -608,6 +610,7 @@ struct SummaryLineInfo
     std::string memo;
     std::string value;
     std::string units;
+    bool units_in_red;
 };
 
 static void
@@ -623,6 +626,7 @@ add_to_summary_table (GtkListStore *list, SummaryLineInfo line)
                         SPLIT_COL_DEBIT, line.debit_side ? line.value.c_str() : "",
                         SPLIT_COL_CREDIT, !line.debit_side ? line.value.c_str() : "",
                         SPLIT_COL_UNITS, line.units.c_str(),
+                        SPLIT_COL_UNITS_COLOR, line.units_in_red ? "red" : nullptr,
                         -1);
     g_free (tooltip);
 }
@@ -640,6 +644,7 @@ check_page (SummaryLineInfo& line, gnc_numeric& debit, gnc_numeric& credit,
 
     line.memo = gtk_entry_get_text (GTK_ENTRY (memo));
     line.units = "";
+    line.units_in_red = false;
     line.debit_side = (splitfield & FieldMask::ENABLED_DEBIT);
 
     if (gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT (gae), &amount, true, nullptr))
@@ -704,6 +709,8 @@ refresh_page_finish (StockTransactionInfo *info)
     gnc_numeric credit = gnc_numeric_zero ();
     StringVec errors, warnings, infos;
     SummaryLineInfo line;
+    bool negative_in_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL,
+                                               GNC_PREF_NEGATIVE_IN_RED);
 
     // check the stock transaction date. If there are existing stock
     // transactions dated after the date specified, it is very likely
@@ -735,7 +742,7 @@ to ensure proper recording."), new_date_str, last_split_date_str);
     }
 
     if (info->txn_type->stock_value == FieldMask::DISABLED)
-        line = { false, false, xaccAccountGetName (info->acct), "", "", "" };
+        line = { false, false, xaccAccountGetName (info->acct), "", "", "", false };
     else
         check_page (line, debit, credit, info->txn_type->stock_value, info->acct,
                     info->stock_memo_edit, info->stock_value_edit, info->currency,
@@ -756,6 +763,7 @@ to ensure proper recording."), new_date_str, last_split_date_str);
             (xaccAccountGetCommodity (info->acct), true);
         stock_amount = gnc_numeric_sub_fixed (stock_amount, info->balance_at_date);
         line.units = xaccPrintAmount (stock_amount, stock_pinfo);
+        line.units_in_red = negative_in_red && gnc_numeric_negative_p (stock_amount);
         if (gnc_numeric_check (ratio))
             add_error_str (errors, N_("Invalid stock new balance"));
         else if (gnc_numeric_negative_p (ratio))
@@ -776,6 +784,7 @@ to ensure proper recording."), new_date_str, last_split_date_str);
         if (info->txn_type->stock_amount & FieldMask::ENABLED_CREDIT)
             stock_amount = gnc_numeric_neg (stock_amount);
         line.units = xaccPrintAmount (stock_amount, stock_pinfo);
+        line.units_in_red = negative_in_red && gnc_numeric_negative_p (stock_amount);
         auto new_bal = gnc_numeric_add_fixed (info->balance_at_date, stock_amount);
         if (gnc_numeric_positive_p (info->balance_at_date) &&
             gnc_numeric_negative_p (new_bal))
@@ -1225,7 +1234,7 @@ get_treeview (GtkBuilder *builder, const gchar *treeview_label)
 
     auto store = gtk_list_store_new (NUM_SPLIT_COLS, G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
-                                     G_TYPE_STRING);
+                                     G_TYPE_STRING, G_TYPE_STRING);
     gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
     g_object_unref(store);
 
@@ -1259,7 +1268,10 @@ get_treeview (GtkBuilder *builder, const gchar *treeview_label)
     gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
     gtk_cell_renderer_set_padding (renderer, 5, 0);
     column = gtk_tree_view_column_new_with_attributes
-        (_("Units"), renderer, "text", SPLIT_COL_UNITS, nullptr);
+        (_("Units"), renderer,
+         "text", SPLIT_COL_UNITS,
+         "foreground", SPLIT_COL_UNITS_COLOR,
+         nullptr);
     gtk_tree_view_append_column(view, column);
 
     return GTK_WIDGET (view);



Summary of changes:
 gnucash/gnome/assistant-stock-transaction.cpp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list