diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c index c98e10fde5..0bd2e8566f 100644 --- a/gnucash/gnome-utils/dialog-account.c +++ b/gnucash/gnome-utils/dialog-account.c @@ -1985,15 +1985,6 @@ gnc_ui_new_accounts_from_name_window (GtkWindow *parent, const char *name) NULL, NULL); } -Account * -gnc_ui_new_accounts_from_name_window_with_types (GtkWindow *parent, - const char *name, - GList *valid_types) -{ - return gnc_ui_new_accounts_from_name_with_defaults (parent, name, - valid_types, NULL, NULL); -} - Account * gnc_ui_new_accounts_from_name_with_defaults (GtkWindow *parent, const char *name, @@ -2143,6 +2134,14 @@ gnc_ui_edit_account_window (GtkWindow *parent, Account *account) gtk_window_present (GTK_WINDOW(aw->dialog)); } +void +gnc_ui_new_account_with_types_and_commodity (GtkWindow *parent, QofBook *book, GList *valid_types, + gnc_commodity *default_commodity) +{ + gnc_ui_new_account_window_internal (parent, book, NULL, NULL, + valid_types, default_commodity, FALSE); +} + /* * opens up a window to create a new account * @@ -2161,14 +2160,6 @@ gnc_ui_new_account_window (GtkWindow *parent, QofBook *book, NULL, FALSE); } -void -gnc_ui_new_account_with_types (GtkWindow *parent, QofBook *book, - GList *valid_types) -{ - gnc_ui_new_account_window_internal (parent, book, NULL, NULL, - valid_types, NULL, FALSE); -} - /************************************************************ * Callbacks for a non-Modal Dialog * ************************************************************/ diff --git a/gnucash/gnome-utils/dialog-account.h b/gnucash/gnome-utils/dialog-account.h index 9d59b9c9c0..2d51039a3f 100644 --- a/gnucash/gnome-utils/dialog-account.h +++ b/gnucash/gnome-utils/dialog-account.h @@ -74,6 +74,25 @@ account_type_has_auto_interest_payment(type) ) void gnc_ui_edit_account_window (GtkWindow *parent, Account *account); +/** Display a window for creating a new account. This function will + * restrict the available account type values to the list specified + * by the caller. + * + * @param parent The widget on which to parent the dialog. + * + * @param book The book in which the new account should be created. + * This is a required argument. + * + * @param valid_types A GList of GNCAccountType gints [as pointers] + * which are allowed to be created. The calling function is + * responsible for freeing this list. + * + * @param default_commodity A gnc_commodity* to specify the default + * commodity to create. May be NULL. + */ +void gnc_ui_new_account_with_types_and_commodity (GtkWindow *parent, QofBook *book, + GList *valid_types, gnc_commodity*); + /** Display a window for creating a new account. This function will * also initially set the parent account of the new account to what * the caller specified. The user is free, however, to choose any @@ -124,26 +143,6 @@ void gnc_ui_new_account_with_types (GtkWindow *parent, QofBook *book, Account * gnc_ui_new_accounts_from_name_window (GtkWindow *parent, const char *name); -/** Display a modal window for creating a new account. This function - * will restrict the available account type values to the list - * specified by the caller. - * - * @param parent The widget on which to parent the dialog. - * - * @param name The account name/path to be created. This parameter - * is not used for determining the initially selected parent account. - * - * @param valid_types A GList of GNCAccountType gints [as pointers] - * which are allowed to be created. The calling function is - * responsible for freeing this list. - * - * @return A pointer to the newly created account. - */ -/* Note that the caller owns the valid_types list */ -Account * gnc_ui_new_accounts_from_name_window_with_types (GtkWindow *parent, - const char *name, - GList *valid_types); - /** Display a modal window for creating a new account. This function * will restrict the available account type values to the list diff --git a/gnucash/gnome-utils/gnc-account-sel.c b/gnucash/gnome-utils/gnc-account-sel.c index c1cafa3fa2..bdd87e6a81 100644 --- a/gnucash/gnome-utils/gnc-account-sel.c +++ b/gnucash/gnome-utils/gnc-account-sel.c @@ -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 diff --git a/gnucash/gnome-utils/gnc-account-sel.h b/gnucash/gnome-utils/gnc-account-sel.h index c21973c2e0..8965deaec3 100644 --- a/gnucash/gnome-utils/gnc-account-sel.h +++ b/gnucash/gnome-utils/gnc-account-sel.h @@ -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. diff --git a/gnucash/register/ledger-core/gncEntryLedger.c b/gnucash/register/ledger-core/gncEntryLedger.c index 11266c2e41..a799183fde 100644 --- a/gnucash/register/ledger-core/gncEntryLedger.c +++ b/gnucash/register/ledger-core/gncEntryLedger.c @@ -113,7 +113,8 @@ gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell, else account_types = g_list_prepend (account_types, (gpointer)ACCT_TYPE_EXPENSE); - account = gnc_ui_new_accounts_from_name_window_with_types (GTK_WINDOW (ledger->parent), name, account_types); + account = gnc_ui_new_accounts_from_name_with_defaults (GTK_WINDOW (ledger->parent), name, account_types, + NULL, NULL); g_list_free ( account_types ); if (!account) return NULL;