From c76efd656ecdd77571102af57e936fc4ce4be97b Mon Sep 17 00:00:00 2001 From: John Ralls Date: Fri, 23 Feb 2018 15:18:01 -0800 Subject: [PATCH] Transient-for for Edit/New Account dialog. --- gnucash/gnome-utils/dialog-account.c | 64 +++++++++++-------- gnucash/gnome-utils/dialog-account.h | 38 +++++++---- gnucash/gnome-utils/gnc-account-sel.c | 8 ++- .../gnome-utils/gnc-tree-control-split-reg.c | 2 +- gnucash/gnome/gnc-plugin-page-account-tree.c | 9 +-- gnucash/gnome/gnc-plugin-page-invoice.c | 5 +- gnucash/gnome/gnc-plugin-page-register.c | 4 +- gnucash/gnome/gnc-plugin-page-register2.c | 4 +- gnucash/gnome/window-reconcile.c | 2 +- gnucash/gnome/window-reconcile2.c | 2 +- .../import-export/import-account-matcher.c | 11 ++-- gnucash/import-export/ofx/gnc-ofx-import.c | 21 +++--- gnucash/register/ledger-core/gncEntryLedger.c | 2 +- gnucash/register/ledger-core/split-register.c | 6 +- 14 files changed, 108 insertions(+), 70 deletions(-) diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c index 3c2a59d63e..3bd082711c 100644 --- a/gnucash/gnome-utils/dialog-account.c +++ b/gnucash/gnome-utils/dialog-account.c @@ -1568,7 +1568,8 @@ refresh_handler (GHashTable *changes, gpointer user_data) static AccountWindow * -gnc_ui_new_account_window_internal (QofBook *book, +gnc_ui_new_account_window_internal (GtkWindow *parent, + QofBook *book, Account *base_account, gchar **subaccount_names, GList *valid_types, @@ -1616,6 +1617,8 @@ gnc_ui_new_account_window_internal (QofBook *book, } gnc_account_window_create (aw); + gtk_window_set_transient_for (GTK_WINDOW (aw->dialog), parent); + gnc_account_to_ui (aw); gnc_resume_gui_refresh (); @@ -1722,23 +1725,27 @@ gnc_split_account_name (QofBook *book, const char *in_name, Account **base_accou ************************************************************/ Account * -gnc_ui_new_accounts_from_name_window (const char *name) +gnc_ui_new_accounts_from_name_window (GtkWindow *parent, const char *name) { - return gnc_ui_new_accounts_from_name_with_defaults (name, NULL, NULL, NULL); + return gnc_ui_new_accounts_from_name_with_defaults (parent, name, NULL, + NULL, NULL); } Account * -gnc_ui_new_accounts_from_name_window_with_types (const char *name, - GList *valid_types) +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(name, valid_types, NULL, NULL); + return gnc_ui_new_accounts_from_name_with_defaults(parent, name, + valid_types, NULL, NULL); } Account * -gnc_ui_new_accounts_from_name_with_defaults (const char *name, - GList *valid_types, - const gnc_commodity * default_commodity, - Account * parent) +gnc_ui_new_accounts_from_name_with_defaults (GtkWindow *parent, + const char *name, + GList *valid_types, + const gnc_commodity * default_commodity, + Account * parent_acct) { QofBook *book; AccountWindow *aw; @@ -1749,7 +1756,7 @@ gnc_ui_new_accounts_from_name_with_defaults (const char *name, gboolean done = FALSE; ENTER("name %s, valid %p, commodity %p, account %p", - name, valid_types, default_commodity, parent); + name, valid_types, default_commodity, parent_acct); book = gnc_get_current_book(); if (!name || *name == '\0') { @@ -1759,11 +1766,12 @@ gnc_ui_new_accounts_from_name_with_defaults (const char *name, else subaccount_names = gnc_split_account_name (book, name, &base_account); - if (parent != NULL) + if (parent_acct != NULL) { - base_account = parent; + base_account = parent_acct; } - aw = gnc_ui_new_account_window_internal (book, base_account, subaccount_names, + aw = gnc_ui_new_account_window_internal (parent, book, base_account, + subaccount_names, valid_types, default_commodity, TRUE); @@ -1819,10 +1827,10 @@ find_by_account (gpointer find_data, gpointer user_data) * Return: EditAccountWindow object */ void -gnc_ui_edit_account_window(Account *account) +gnc_ui_edit_account_window(GtkWindow *parent, Account *account) { AccountWindow * aw; - Account *parent; + Account *parent_acct; if (account == NULL) return; @@ -1847,6 +1855,7 @@ gnc_ui_edit_account_window(Account *account) gnc_suspend_gui_refresh (); gnc_account_window_create (aw); + gtk_window_set_transient_for (GTK_WINDOW (aw->dialog), parent); gnc_account_to_ui (aw); gnc_resume_gui_refresh (); @@ -1854,13 +1863,13 @@ gnc_ui_edit_account_window(Account *account) gtk_widget_show_all (aw->dialog); gtk_widget_hide (aw->opening_balance_page); - parent = gnc_account_get_parent (account); - if (parent == NULL) - parent = account; /* must be at the root */ + parent_acct = gnc_account_get_parent (account); + if (parent_acct == NULL) + parent_acct = account; /* must be at the root */ gtk_tree_view_collapse_all (aw->parent_tree); gnc_tree_view_account_set_selected_account ( - GNC_TREE_VIEW_ACCOUNT(aw->parent_tree), parent); + GNC_TREE_VIEW_ACCOUNT(aw->parent_tree), parent_acct); gnc_account_window_set_name (aw); @@ -1886,20 +1895,23 @@ gnc_ui_edit_account_window(Account *account) * parent - The initial parent for the new account (optional) */ void -gnc_ui_new_account_window(QofBook *book, Account *parent) +gnc_ui_new_account_window (GtkWindow *parent, QofBook *book, + Account *parent_acct) { g_return_if_fail(book != NULL); if (parent && book) - g_return_if_fail(gnc_account_get_book(parent) == book); + g_return_if_fail(gnc_account_get_book(parent_acct) == book); - gnc_ui_new_account_window_internal (book, parent, NULL, NULL, NULL, FALSE); + gnc_ui_new_account_window_internal (parent, book, parent_acct, NULL, NULL, + NULL, FALSE); } void -gnc_ui_new_account_with_types( QofBook *book, - GList *valid_types ) +gnc_ui_new_account_with_types (GtkWindow *parent, QofBook *book, + GList *valid_types) { - gnc_ui_new_account_window_internal( book, NULL, NULL, valid_types, NULL, FALSE ); + gnc_ui_new_account_window_internal (parent, book, NULL, NULL, + valid_types, NULL, FALSE); } /************************************************************ diff --git a/gnucash/gnome-utils/dialog-account.h b/gnucash/gnome-utils/dialog-account.h index 5003dc5deb..ffdb44b201 100644 --- a/gnucash/gnome-utils/dialog-account.h +++ b/gnucash/gnome-utils/dialog-account.h @@ -44,11 +44,13 @@ @{ */ /** Disply a window for editing the attributes of an existing account. + * + * @param parent The widget on which to parent the dialog. * * @param account This parameter specifies the account whose data * will be edited. */ -void gnc_ui_edit_account_window (Account *account); +void gnc_ui_edit_account_window (GtkWindow *parent, Account *account); /** Disply a window for creating a new account. This function will @@ -56,20 +58,25 @@ void gnc_ui_edit_account_window (Account *account); * the caller specified. The user is free, however, to choose any * parent account they wish. * + * @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 parent The initially selected parent account. This + * @param parent_acct The initially selected parent account. This * argument is optional, but if supplied must be an account contained * in the specified book. */ -void gnc_ui_new_account_window (QofBook *book, Account *parent); +void gnc_ui_new_account_window (GtkWindow *parent, + QofBook *book, Account *parent_acct); /** Disply 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. * @@ -77,7 +84,7 @@ void gnc_ui_new_account_window (QofBook *book, Account *parent); * which are allowed to be created. The calling function is * responsible for freeing this list. */ -void gnc_ui_new_account_with_types (QofBook *book, +void gnc_ui_new_account_with_types (GtkWindow *parent, QofBook *book, GList *valid_types); /** @} */ @@ -87,16 +94,21 @@ void gnc_ui_new_account_with_types (QofBook *book, @{ */ /** Disply a modal window for creating a new account + * + * @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. */ -Account * gnc_ui_new_accounts_from_name_window (const char *name); +Account * gnc_ui_new_accounts_from_name_window (GtkWindow *parent, + const char *name); /** Disply 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. * @@ -107,7 +119,8 @@ Account * gnc_ui_new_accounts_from_name_window (const char *name); * @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 (const char *name, +Account * gnc_ui_new_accounts_from_name_window_with_types (GtkWindow *parent, + const char *name, GList *valid_types); @@ -115,6 +128,8 @@ Account * gnc_ui_new_accounts_from_name_window_with_types (const char *name, * 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. * @@ -125,14 +140,15 @@ Account * gnc_ui_new_accounts_from_name_window_with_types (const char *name, * @param default_commodity The commodity to initially select when * the dialog is presented. * - * @param parent The initially selected parent account. + * @param parent_acct The initially selected parent account. * * @return A pointer to the newly created account. */ -Account * gnc_ui_new_accounts_from_name_with_defaults (const char *name, - GList *valid_types, - const gnc_commodity * default_commodity, - Account * parent); +Account * gnc_ui_new_accounts_from_name_with_defaults (GtkWindow *parent, + const char *name, + GList *valid_types, + const gnc_commodity * default_commodity, + Account * parent_acct); /* * register a callback that get's called when the account has changed diff --git a/gnucash/gnome-utils/gnc-account-sel.c b/gnucash/gnome-utils/gnc-account-sel.c index d255ce6128..f3a2916428 100644 --- a/gnucash/gnome-utils/gnc-account-sel.c +++ b/gnucash/gnome-utils/gnc-account-sel.c @@ -480,11 +480,13 @@ static void gas_new_account_click( GtkButton *b, gpointer ud ) { GNCAccountSel *gas = (GNCAccountSel*)ud; + GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gas))); if (gas->isModal) - gnc_ui_new_accounts_from_name_window_with_types ( NULL, - gas->acctTypeFilters ); + gnc_ui_new_accounts_from_name_window_with_types (parent, NULL, + gas->acctTypeFilters ); else - gnc_ui_new_account_with_types( gnc_get_current_book(), gas->acctTypeFilters ); + gnc_ui_new_account_with_types (parent, gnc_get_current_book(), + gas->acctTypeFilters ); } gint diff --git a/gnucash/gnome-utils/gnc-tree-control-split-reg.c b/gnucash/gnome-utils/gnc-tree-control-split-reg.c index 1eecf27f65..3c68ddde3d 100644 --- a/gnucash/gnome-utils/gnc-tree-control-split-reg.c +++ b/gnucash/gnome-utils/gnc-tree-control-split-reg.c @@ -1973,7 +1973,7 @@ gnc_tree_control_split_reg_get_account_by_name (GncTreeViewSplitReg *view, const return NULL; /* User said yes, they want to create a new account. */ - account = gnc_ui_new_accounts_from_name_window (name); + account = gnc_ui_new_accounts_from_name_window (window, name); if (!account) return NULL; } diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c index e9a1a53a6b..4269f51c79 100644 --- a/gnucash/gnome/gnc-plugin-page-account-tree.c +++ b/gnucash/gnome/gnc-plugin-page-account-tree.c @@ -1072,8 +1072,9 @@ static void gnc_plugin_page_account_tree_cmd_new_account (GtkAction *action, GncPluginPageAccountTree *page) { Account *account = gnc_plugin_page_account_tree_get_current_account (page); - - gnc_ui_new_account_window (gnc_get_current_book(), account); + GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page))); + gnc_ui_new_account_window (parent, gnc_get_current_book(), + account); } static void @@ -1134,13 +1135,13 @@ static void gnc_plugin_page_account_tree_cmd_edit_account (GtkAction *action, GncPluginPageAccountTree *page) { Account *account; - + GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page))); ENTER("action %p, page %p", action, page); account = gnc_plugin_page_account_tree_get_current_account (page); g_return_if_fail (account != NULL); - gnc_ui_edit_account_window (account); + gnc_ui_edit_account_window (parent, account); LEAVE(" "); } diff --git a/gnucash/gnome/gnc-plugin-page-invoice.c b/gnucash/gnome/gnc-plugin-page-invoice.c index 1b8b869b26..f58b700aea 100644 --- a/gnucash/gnome/gnc-plugin-page-invoice.c +++ b/gnucash/gnome/gnc-plugin-page-invoice.c @@ -726,10 +726,11 @@ static void gnc_plugin_page_invoice_cmd_new_account (GtkAction *action, GncPluginPageInvoice *plugin_page) { + GtkWindow *parent = NULL; g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page)); - + parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (plugin_page))); ENTER("(action %p, plugin_page %p)", action, plugin_page); - gnc_ui_new_account_window (gnc_get_current_book(), NULL); + gnc_ui_new_account_window (parent, gnc_get_current_book(), NULL); LEAVE(" "); } diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index 0ef9fe9c79..57372d42c8 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -2951,13 +2951,13 @@ gnc_plugin_page_register_cmd_edit_account (GtkAction *action, GncPluginPageRegister *page) { Account *account; - + GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page))); g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page)); ENTER("(action %p, page %p)", action, page); account = gnc_plugin_page_register_get_account (page); if (account) - gnc_ui_edit_account_window (account); + gnc_ui_edit_account_window (parent, account); LEAVE(" "); } diff --git a/gnucash/gnome/gnc-plugin-page-register2.c b/gnucash/gnome/gnc-plugin-page-register2.c index 58d9d36073..50216074ed 100644 --- a/gnucash/gnome/gnc-plugin-page-register2.c +++ b/gnucash/gnome/gnc-plugin-page-register2.c @@ -2752,13 +2752,13 @@ gnc_plugin_page_register2_cmd_edit_account (GtkAction *action, GncPluginPageRegister2 *page) //this works { Account *account; - + GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window (GNC_PLUGIN_PAGE (page))); g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER2(page)); ENTER("(action %p, page %p)", action, page); account = gnc_plugin_page_register2_get_account (page); if (account) - gnc_ui_edit_account_window (account); + gnc_ui_edit_account_window (parent, account); LEAVE(" "); } diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c index 78ed182a8a..d080647006 100644 --- a/gnucash/gnome/window-reconcile.c +++ b/gnucash/gnome/window-reconcile.c @@ -1388,7 +1388,7 @@ gnc_recn_edit_account_cb(GtkAction *action, gpointer data) if (account == NULL) return; - gnc_ui_edit_account_window (account); + gnc_ui_edit_account_window (GTK_WINDOW (recnData->window), account); } diff --git a/gnucash/gnome/window-reconcile2.c b/gnucash/gnome/window-reconcile2.c index d8d59beeab..4f7cbc95e5 100644 --- a/gnucash/gnome/window-reconcile2.c +++ b/gnucash/gnome/window-reconcile2.c @@ -1349,7 +1349,7 @@ gnc_recn_edit_account_cb (GtkAction *action, gpointer data) if (account == NULL) return; - gnc_ui_edit_account_window (account); + gnc_ui_edit_account_window (GTK_WINDOW (recnData->window), account); } diff --git a/gnucash/import-export/import-account-matcher.c b/gnucash/import-export/import-account-matcher.c index 4e59b98028..5373ef8c35 100644 --- a/gnucash/import-export/import-account-matcher.c +++ b/gnucash/import-export/import-account-matcher.c @@ -143,6 +143,8 @@ gnc_import_add_account(GtkWidget *button, AccountPickerDialog *picker) { Account *selected_account, *new_account; GList * valid_types = NULL; + GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (button)); + /*DEBUG("Begin"); */ if (picker->new_account_default_type != ACCT_TYPE_NONE) { @@ -150,10 +152,11 @@ gnc_import_add_account(GtkWidget *button, AccountPickerDialog *picker) valid_types = g_list_prepend(valid_types, GINT_TO_POINTER(picker->new_account_default_type)); } selected_account = gnc_tree_view_account_get_selected_account(picker->account_tree); - new_account = gnc_ui_new_accounts_from_name_with_defaults ( picker->account_human_description, - valid_types, - picker->new_account_default_commodity, - selected_account); + new_account = gnc_ui_new_accounts_from_name_with_defaults (parent, + picker->account_human_description, + valid_types, + picker->new_account_default_commodity, + selected_account); g_list_free(valid_types); gnc_tree_view_account_set_selected_account(picker->account_tree, new_account); } diff --git a/gnucash/import-export/ofx/gnc-ofx-import.c b/gnucash/import-export/ofx/gnc-ofx-import.c index 08d950e84f..5a37e15450 100644 --- a/gnucash/import-export/ofx/gnc-ofx-import.c +++ b/gnucash/import-export/ofx/gnc-ofx-import.c @@ -79,7 +79,7 @@ int ofx_proc_status_cb(struct OfxStatusData data) */ int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data); -int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data); +int ofx_proc_transaction_cb (struct OfxTransactionData data, void *user_data); int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data); static double ofx_get_investment_amount(const struct OfxTransactionData* data); @@ -292,7 +292,8 @@ static gnc_numeric gnc_ofx_numeric_from_double_txn(double value, const Transacti /* Opens the dialog to create a new account with given name, commodity, parent, type. * Returns the new account, or NULL if it couldn't be created.. */ -static Account *gnc_ofx_new_account(const char* name, +static Account *gnc_ofx_new_account(GtkWindow* parent, + const char* name, const gnc_commodity * account_commodity, Account *parent_account, GNCAccountType new_account_default_type) @@ -318,10 +319,10 @@ static Account *gnc_ofx_new_account(const char* name, GINT_TO_POINTER(xaccAccountGetType(parent_account))); } } - result = gnc_ui_new_accounts_from_name_with_defaults (name, - valid_types, - account_commodity, - parent_account); + result = gnc_ui_new_accounts_from_name_with_defaults (parent, name, + valid_types, + account_commodity, + parent_account); g_list_free(valid_types); return result; } @@ -343,7 +344,7 @@ fix_ofx_bug_39 (time64 t) return t; } -int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data) +int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data) { char dest_string[255]; time64 current_time = gnc_time (NULL); @@ -358,6 +359,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u Transaction *transaction; Split *split; gchar *notes, *tmp; + GtkWindow *parent = GTK_WINDOW (user_data); g_assert(gnc_ofx_importer_gui); @@ -637,7 +639,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u // commodity. Account *parent_account = investment_account; investment_account = - gnc_ofx_new_account(investment_account_text, + gnc_ofx_new_account(parent, + investment_account_text, investment_commodity, parent_account, ACCT_TYPE_STOCK); @@ -1020,7 +1023,7 @@ void gnc_file_ofx_import (GtkWindow *parent) /*ofx_set_statement_cb(libofx_context, ofx_proc_statement_cb, 0);*/ ofx_set_account_cb(libofx_context, ofx_proc_account_cb, 0); - ofx_set_transaction_cb(libofx_context, ofx_proc_transaction_cb, 0); + ofx_set_transaction_cb(libofx_context, ofx_proc_transaction_cb, parent); ofx_set_security_cb(libofx_context, ofx_proc_security_cb, 0); /*ofx_set_status_cb(libofx_context, ofx_proc_status_cb, 0);*/ diff --git a/gnucash/register/ledger-core/gncEntryLedger.c b/gnucash/register/ledger-core/gncEntryLedger.c index b3ea14816c..91d0736e32 100644 --- a/gnucash/register/ledger-core/gncEntryLedger.c +++ b/gnucash/register/ledger-core/gncEntryLedger.c @@ -111,7 +111,7 @@ 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 (name, account_types); + account = gnc_ui_new_accounts_from_name_window_with_types (GTK_WINDOW (ledger->parent), name, account_types); g_list_free ( account_types ); if (!account) return NULL; diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c index 69c1793205..760b727ffd 100644 --- a/gnucash/register/ledger-core/split-register.c +++ b/gnucash/register/ledger-core/split-register.c @@ -1852,6 +1852,7 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, ComboCell *cell = (ComboCell *) bcell; Account *account; static gboolean creating_account = FALSE; + GtkWindow *parent = GTK_WINDOW (gnc_split_register_get_parent (reg)); if (!name || (strlen(name) == 0)) return NULL; @@ -1864,12 +1865,11 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, if (!account && !creating_account) { /* Ask if they want to create a new one. */ - if (!gnc_verify_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), - TRUE, missing, name)) + if (!gnc_verify_dialog (parent, TRUE, missing, name)) return NULL; creating_account = TRUE; /* User said yes, they want to create a new account. */ - account = gnc_ui_new_accounts_from_name_window (name); + account = gnc_ui_new_accounts_from_name_window (parent, name); creating_account = FALSE; if (!account) return NULL;