From e76ebf4c60cd845e60d07ce596ab57044ae73e73 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 11 May 2019 14:44:37 +0100 Subject: [PATCH] Change the Placeholder warning in the Account picker When an account is selected it is checked for being a placeholder and if it is a warning dialog was created. This was pointed out as being disruptive so this change controls the sensitivity of the OK button and displays a warning in the account picker dialog. --- gnucash/gtkbuilder/dialog-import.glade | 71 +++++++++++++++---- .../import-export/import-account-matcher.c | 71 ++++++++++++++++--- .../import-export/import-account-matcher.h | 3 + 3 files changed, 120 insertions(+), 25 deletions(-) diff --git a/gnucash/gtkbuilder/dialog-import.glade b/gnucash/gtkbuilder/dialog-import.glade index 59ed257be9..84f6c6ac6c 100644 --- a/gnucash/gtkbuilder/dialog-import.glade +++ b/gnucash/gtkbuilder/dialog-import.glade @@ -1,5 +1,5 @@ - + @@ -14,6 +14,9 @@ 600 dialog + + + True @@ -80,16 +83,43 @@ - - - - - - - - - - + + False + 6 + 6 + 6 + 6 + + + False + start + gtk-dialog-warning + + + False + True + 0 + + + + + False + start + True + + + False + True + 2 + + + + + False + True + end + 2 + @@ -165,7 +195,6 @@ 10 - False False Choose a format False @@ -173,6 +202,9 @@ 600 400 dialog + + + True @@ -301,6 +333,9 @@ True False Preferences + + + True @@ -554,6 +589,9 @@ 600 400 dialog + + + True @@ -726,6 +764,9 @@ False dialog + + + True @@ -1119,9 +1160,6 @@ 1 - - - Show the Source Account column @@ -1145,6 +1183,9 @@ 400 dialog + + + True diff --git a/gnucash/import-export/import-account-matcher.c b/gnucash/import-export/import-account-matcher.c index 02546621a6..704cffa841 100644 --- a/gnucash/import-export/import-account-matcher.c +++ b/gnucash/import-export/import-account-matcher.c @@ -171,6 +171,53 @@ gnc_import_add_account(GtkWidget *button, AccountPickerDialog *picker) } +/*********************************************************** + * show_placeholder_warning + * + * show the warning when account is a place holder and disable + * OK button + ************************************************************/ +static void +show_placeholder_warning (AccountPickerDialog *picker, const gchar *name) +{ + gchar *text = g_strdup_printf (_("The account %s is a placeholder account and does not allow " + "transactions. Please choose a different account."), name); + + gtk_label_set_text (GTK_LABEL(picker->pwarning), text); + gnc_label_set_alignment (picker->pwarning, 0.0, 0.5); + gtk_widget_show_all (GTK_WIDGET(picker->pwhbox)); + g_free (text); + + gtk_widget_set_sensitive (picker->ok_button, FALSE); // disable OK button +} + + +/******************************************************* + * account_tree_row_changed_cb + * + * Callback for when user selects a different row + *******************************************************/ +static void +account_tree_row_changed_cb (GtkTreeSelection *selection, + AccountPickerDialog *picker) +{ + + Account *sel_account = gnc_tree_view_account_get_selected_account (picker->account_tree); + + gtk_widget_set_sensitive (picker->ok_button, TRUE); // enable OK button + + /* See if the selected account is a placeholder. */ + if (sel_account && xaccAccountGetPlaceholder (sel_account)) + { + const gchar *retval_name = xaccAccountGetName (sel_account); + + show_placeholder_warning (picker, retval_name); + } + else + gtk_widget_hide (GTK_WIDGET(picker->pwhbox)); // hide the placeholder warning +} + + /******************************************************* * account_tree_row_activated_cb * @@ -201,10 +248,7 @@ account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path, /* See if the selected account is a placeholder. */ if (picker->retAccount && xaccAccountGetPlaceholder (picker->retAccount)) { - gnc_error_dialog (GTK_WINDOW (picker->dialog), - _("The account %s is a placeholder account and does not allow " - "transactions. Please choose a different account."), - retval_name); + show_placeholder_warning (picker, retval_name); } else if ( picker->account_online_id_value != NULL) { @@ -251,6 +295,7 @@ Account * gnc_import_select_account(GtkWidget *parent, Account * retval = NULL; const gchar *retval_name = NULL; GtkBuilder *builder; + GtkTreeSelection *selection; GtkWidget * online_id_label, *box, *pbox; gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE + 1] = ""; gboolean ok_pressed_retval = FALSE; @@ -314,6 +359,10 @@ Account * gnc_import_select_account(GtkWidget *parent, PERR("Error opening the glade builder interface"); } picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_picker_dialog")); + picker->pwhbox = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_warning_hbox")); + picker->pwarning = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_warning_label")); + picker->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "okbutton")); + if (parent) gtk_window_set_transient_for (GTK_WINDOW (picker->dialog), GTK_WINDOW (parent)); @@ -349,11 +398,17 @@ Account * gnc_import_select_account(GtkWidget *parent, } gtk_label_set_text((GtkLabel*)online_id_label, account_description_text); build_acct_tree(picker); - gnc_tree_view_account_set_selected_account(picker->account_tree, default_selection); gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE); g_signal_connect(picker->account_tree, "row-activated", G_CALLBACK(account_tree_row_activated_cb), picker); + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(picker->account_tree)); + g_signal_connect(selection, "changed", + G_CALLBACK(account_tree_row_changed_cb), picker); + + gnc_tree_view_account_set_selected_account(picker->account_tree, default_selection); + do { response = gtk_dialog_run(GTK_DIALOG(picker->dialog)); @@ -380,11 +435,7 @@ Account * gnc_import_select_account(GtkWidget *parent, /* See if the selected account is a placeholder. */ if (retval && xaccAccountGetPlaceholder (retval)) { - gnc_error_dialog - (GTK_WINDOW (picker->dialog), - _("The account %s is a placeholder account and does not allow " - "transactions. Please choose a different account."), - retval_name); + show_placeholder_warning (picker, retval_name); response = GNC_RESPONSE_NEW; break; } diff --git a/gnucash/import-export/import-account-matcher.h b/gnucash/import-export/import-account-matcher.h index 986e75908e..17c99976a2 100644 --- a/gnucash/import-export/import-account-matcher.h +++ b/gnucash/import-export/import-account-matcher.h @@ -40,6 +40,7 @@ typedef struct GtkWidget *dialog; /* Dialog Widget */ GtkWidget *assistant; /* assistant Widget */ GtkWidget *new_button; /* new account button Widget */ + GtkWidget *ok_button; /* ok button Widget */ GncTreeViewAccount *account_tree; /* Account tree */ GtkWidget *account_tree_sw; /* Scroll Window for Account tree */ gboolean auto_create; /* Auto create retAccount, can be used to step over this stage */ @@ -50,6 +51,8 @@ typedef struct GNCAccountType new_account_default_type; /* new account default type, incoming */ Account *default_account; /* default account for selection, incoming */ Account *retAccount; /* Account value returned to caller */ + GtkWidget *pwhbox; /* Placeholder Warning HBox */ + GtkWidget *pwarning; /* Placeholder Warning Label */ } AccountPickerDialog; /** Must be called with a string containing a unique identifier for the