[gnc-account-sel] can specify any new account's default commodity

This commit is contained in:
Christopher Lam 2023-09-07 23:39:40 +08:00
parent af371af172
commit 58d5d4bc73
2 changed files with 22 additions and 4 deletions

View File

@ -65,6 +65,7 @@ struct _GNCAccountSel
GList *acctTypeFilters;
GList *acctCommodityFilters;
GList *acctExcludeList;
gnc_commodity *default_new_commodity;
/* The state of this pointer also serves as a flag about what state
* the widget is in WRT the new-account-button ability. */
@ -671,6 +672,7 @@ gnc_account_sel_init (GNCAccountSel *gas)
gtk_orientable_set_orientation (GTK_ORIENTABLE(gas), GTK_ORIENTATION_HORIZONTAL);
gas->default_new_commodity = NULL;
gas->acctTypeFilters = NULL;
gas->acctCommodityFilters = NULL;
gas->acctExcludeList = NULL;
@ -913,6 +915,14 @@ gnc_account_sel_set_acct_exclude_filter (GNCAccountSel *gas,
update_entry_and_refilter (gas);
}
void
gnc_account_sel_set_default_new_commodity (GNCAccountSel *gas, gnc_commodity *new_commodity)
{
g_return_if_fail (gas);
g_return_if_fail (GNC_IS_COMMODITY (new_commodity));
gas->default_new_commodity = new_commodity;
}
static void
gnc_account_sel_finalize (GObject *object)
{
@ -1015,14 +1025,14 @@ gas_new_account_click (GtkButton *b, gpointer user_data)
if (gas->isModal)
{
Account *account = gnc_ui_new_accounts_from_name_window_with_types (parent, NULL,
gas->acctTypeFilters);
Account *account = gnc_ui_new_accounts_from_name_with_defaults (parent, NULL, gas->acctTypeFilters,
gas->default_new_commodity, NULL);
if (account)
gnc_account_sel_set_account (gas, account, FALSE);
}
else
gnc_ui_new_account_with_types (parent, gnc_get_current_book(),
gas->acctTypeFilters);
gnc_ui_new_account_with_types_and_commodity (parent, gnc_get_current_book(),
gas->acctTypeFilters, gas->default_new_commodity);
}
gint

View File

@ -75,6 +75,14 @@ void gnc_account_sel_set_acct_filters (GNCAccountSel *gas,
void gnc_account_sel_set_acct_exclude_filter (GNCAccountSel *gas,
GList *excludeFilter);
/**
* The GNCAccountSel can be setup to provide a New account facility whose commodity
* is defaulted to this commodity.
* @param gas The GNCAccountSel widget.
* @param gnc_commodity* A gnc_commodity*
**/
void gnc_account_sel_set_default_new_commodity (GNCAccountSel*, gnc_commodity*);
/**
* Conditional inclusion of a new-account button to the right of the
* combobox.