[assistant-stock-transaction] avoid resetting txn_types unnecessarily.

UX improvement.

Previously the txn_types dropdown list would be regenerated whenever
the GtkAssistant reaches the page PAGE_TRANSACTION_TYPE. This means
selecting "Sell", pressing "Next", then "Previous" would reset the
type to "Buy".

This commit will store the date at which the txn_types was set; it
will avoid resetting txn_types unless the date is changed.
This commit is contained in:
Christopher Lam 2022-05-05 22:41:00 +08:00
parent 19803ba9d0
commit 2b198dbce4

View File

@ -430,6 +430,10 @@ typedef struct
GtkWidget * assistant;
std::optional<TxnTypeVec> txn_types;
// the following stores date at which the txn_types were set. If
// the GNCDateEdit date is modified, it will trigger recreation of
// the txn_types above.
std::optional<time64> txn_types_date;
Account * acct;
gnc_commodity * currency;
@ -830,6 +834,9 @@ stock_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
gnc_numeric balance;
time64 date;
date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
if (info->txn_types_date && (info->txn_types_date == date))
break;
info->txn_types_date = date;
balance = xaccAccountGetBalanceAsOfDate (info->acct, date);
info->txn_types = gnc_numeric_zero_p (balance) ? starting_types
: gnc_numeric_positive_p (balance) ? long_types