From ff514e3b377dee71def545318b4e8d7fed458a8a Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 17 Feb 2020 12:07:01 +0000 Subject: [PATCH] Bug797486 - Add dialog to cascade placeholder and hidden Make changes to the existing cascade colour dialog to allow the selection of cascading colour, placeholder and hidden account properties --- gnucash/gnome-utils/dialog-account.c | 124 +++++-- gnucash/gnome-utils/dialog-account.h | 2 +- gnucash/gnome/gnc-plugin-page-account-tree.c | 16 +- gnucash/gtkbuilder/dialog-account.glade | 323 +++++++++++++++--- .../ui/gnc-plugin-page-account-tree-ui.xml | 4 +- 5 files changed, 391 insertions(+), 78 deletions(-) diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c index 5383f3032d..0144d1f968 100644 --- a/gnucash/gnome-utils/dialog-account.c +++ b/gnucash/gnome-utils/dialog-account.c @@ -2122,12 +2122,28 @@ update_account_color (Account *acc, const gchar *old_color, const gchar *new_col } } +static void +enable_box_cb (GtkToggleButton *toggle_button, gpointer user_data) +{ + gboolean sensitive = FALSE; + + if (gtk_toggle_button_get_active (toggle_button)) + sensitive = TRUE; + + gtk_widget_set_sensitive (GTK_WIDGET(user_data), sensitive); +} + void -gnc_account_cascade_color_dialog (GtkWidget *window, Account *account) +gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account) { GtkWidget *dialog; GtkBuilder *builder; - GtkWidget *color_label, *color_button, *over_write, *color_button_default; + GtkWidget *label; + GtkWidget *color_button, *over_write, *color_button_default; + GtkWidget *enable_color, *enable_placeholder, *enable_hidden; + GtkWidget *color_box, *placeholder_box, *hidden_box; + GtkWidget *placeholder_button, *hidden_button; + gchar *string; const char *color_string; gchar *old_color_string = NULL; @@ -2138,24 +2154,31 @@ gnc_account_cascade_color_dialog (GtkWidget *window, Account *account) g_return_if_fail (gnc_account_n_children (account) > 0); builder = gtk_builder_new(); - gnc_builder_add_from_file (builder, "dialog-account.glade", "account_cascade_color_dialog"); - dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_cascade_color_dialog")); + gnc_builder_add_from_file (builder, "dialog-account.glade", "account_cascade_dialog"); + dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_cascade_dialog")); gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window)); - color_label = GTK_WIDGET(gtk_builder_get_object (builder, "color_label")); + // Color section + enable_color = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_color")); + color_box = GTK_WIDGET(gtk_builder_get_object (builder, "color_box")); + + label = GTK_WIDGET(gtk_builder_get_object (builder, "color_label")); over_write = GTK_WIDGET(gtk_builder_get_object (builder, "replace_check")); color_button = GTK_WIDGET(gtk_builder_get_object (builder, "color_button")); color_button_default = GTK_WIDGET(gtk_builder_get_object (builder, "color_button_default")); gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(color_button), FALSE); + g_signal_connect (G_OBJECT(enable_color), "toggled", + G_CALLBACK(enable_box_cb), (gpointer)color_box); + g_signal_connect (G_OBJECT(color_button_default), "clicked", G_CALLBACK(default_color_button_cb), (gpointer)color_button); - string = g_strdup_printf(_( "Set the account color for account '%s' " - "including all sub-accounts to the selected color"), - gnc_account_get_full_name(account)); - gtk_label_set_text (GTK_LABEL(color_label), string); + string = g_strdup_printf (_( "Set the account color for account '%s' " + "including all sub-accounts to the selected color"), + gnc_account_get_full_name (account)); + gtk_label_set_text (GTK_LABEL(label), string); g_free (string); color_string = xaccAccountGetColor (account); // get existing account color @@ -2171,6 +2194,34 @@ gnc_account_cascade_color_dialog (GtkWidget *window, Account *account) // set the color chooser to account color gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_button), &color); + // Placeholder section + enable_placeholder = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_placeholder")); + placeholder_box = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_box")); + label = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_label")); + placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_check_button")); + g_signal_connect (G_OBJECT(enable_placeholder), "toggled", + G_CALLBACK(enable_box_cb), (gpointer)placeholder_box); + + string = g_strdup_printf (_( "Set the account placeholder value for account '%s' " + "including all sub-accounts"), + gnc_account_get_full_name (account)); + gtk_label_set_text (GTK_LABEL(label), string); + g_free (string); + + // Hidden section + enable_hidden = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_hidden")); + hidden_box = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_box")); + label = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_label")); + hidden_button = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_check_button")); + g_signal_connect (G_OBJECT(enable_hidden), "toggled", + G_CALLBACK(enable_box_cb), (gpointer)hidden_box); + + string = g_strdup_printf (_( "Set the account hidden value for account '%s' " + "including all sub-accounts"), + gnc_account_get_full_name (account)); + gtk_label_set_text (GTK_LABEL(label), string); + g_free (string); + /* default to cancel */ gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL); @@ -2184,31 +2235,56 @@ gnc_account_cascade_color_dialog (GtkWidget *window, Account *account) if (response == GTK_RESPONSE_OK) { GList *accounts = gnc_account_get_descendants (account); - gboolean replace = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(over_write)); - GList *acct; GdkRGBA new_color; - const gchar *new_color_string; + const gchar *new_color_string = NULL; + gboolean color_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_color)); + gboolean placeholder_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_placeholder)); + gboolean hidden_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_hidden)); + gboolean replace = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(over_write)); + gboolean placeholder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(placeholder_button)); + gboolean hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(hidden_button)); - gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_button), &new_color); - new_color_string = gdk_rgba_to_string (&new_color); + // Update Account Colors + if (color_active) + { + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_button), &new_color); + new_color_string = gdk_rgba_to_string (&new_color); - if (g_strcmp0 (new_color_string, DEFAULT_COLOR) == 0) - new_color_string = NULL; + if (g_strcmp0 (new_color_string, DEFAULT_COLOR) == 0) + new_color_string = NULL; - // check/update selected account - update_account_color (account, old_color_string, new_color_string, replace); + // check/update selected account + update_account_color (account, old_color_string, new_color_string, replace); + } + // Update Account Placeholder value + if (placeholder_active) + xaccAccountSetPlaceholder (account, placeholder); + + // Update Account Hidden value + if (hidden_active) + xaccAccountSetHidden (account, hidden); + + // Update SubAccounts if (accounts) { - for (acct = accounts; acct; acct = g_list_next(acct)) + for (GList *acct = accounts; acct; acct = g_list_next(acct)) { - const char *string = xaccAccountGetColor (acct->data); - - // check/update sub-accounts - update_account_color (acct->data, string, new_color_string, replace); + // Update SubAccount Colors + if (color_active) + { + const char *string = xaccAccountGetColor (acct->data); + update_account_color (acct->data, string, new_color_string, replace); + } + // Update SubAccount PlaceHolder + if (placeholder_active) + xaccAccountSetPlaceholder (acct->data, placeholder); + // Update SubAccount Hidden + if (hidden_active) + xaccAccountSetHidden (acct->data, hidden); } - g_list_free (accounts); } + g_list_free (accounts); } if (old_color_string) g_free (old_color_string); diff --git a/gnucash/gnome-utils/dialog-account.h b/gnucash/gnome-utils/dialog-account.h index 92281ae83c..916f03e3f7 100644 --- a/gnucash/gnome-utils/dialog-account.h +++ b/gnucash/gnome-utils/dialog-account.h @@ -161,7 +161,7 @@ void gnc_ui_register_account_destroy_callback (void (*cb)(Account *)); void gnc_account_renumber_create_dialog (GtkWidget *window, Account *account); -void gnc_account_cascade_color_dialog (GtkWidget *window, Account *account); +void gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account); /** @} */ /** @} */ diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c index 745efc8aab..eac023359b 100644 --- a/gnucash/gnome/gnc-plugin-page-account-tree.c +++ b/gnucash/gnome/gnc-plugin-page-account-tree.c @@ -155,7 +155,7 @@ static void gnc_plugin_page_account_tree_cmd_lots (GtkAction *action, GncPluginP static void gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page); static void gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page); static void gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page); -static void gnc_plugin_page_account_tree_cmd_cascade_color_account (GtkAction *action, GncPluginPageAccountTree *page); +static void gnc_plugin_page_account_tree_cmd_cascade_account_properties (GtkAction *action, GncPluginPageAccountTree *page); /* Command callback for new Register Test */ static void gnc_plugin_page_account_tree_cmd_open2_account (GtkAction *action, GncPluginPageAccountTree *page); @@ -230,9 +230,9 @@ static GtkActionEntry gnc_plugin_page_account_tree_actions [] = G_CALLBACK (gnc_plugin_page_account_tree_cmd_delete_account) }, { - "EditColorCascadeAccountAction", NULL, N_("_Cascade Account Color..."), NULL, - N_("Cascade selected account color"), - G_CALLBACK (gnc_plugin_page_account_tree_cmd_cascade_color_account) + "EditCascadeAccountAction", NULL, N_("_Cascade Account Properties..."), NULL, + N_("Cascade selected properties for account"), + G_CALLBACK (gnc_plugin_page_account_tree_cmd_cascade_account_properties) }, { "EditFindAccountAction", "edit-find", N_("F_ind Account"), "i", @@ -1072,7 +1072,7 @@ gnc_plugin_page_account_tree_selection_changed_cb (GtkTreeSelection *selection, g_object_set (G_OBJECT(action), "sensitive", is_readwrite && sensitive && subaccounts, NULL); - action = gtk_action_group_get_action (action_group, "EditColorCascadeAccountAction"); + action = gtk_action_group_get_action (action_group, "EditCascadeAccountAction"); g_object_set (G_OBJECT(action), "sensitive", subaccounts, NULL); gnc_plugin_update_actions (action_group, actions_requiring_account_rw, @@ -1190,7 +1190,7 @@ gnc_plugin_page_account_tree_cmd_find_account_popup (GtkAction *action, GncPlugi } static void -gnc_plugin_page_account_tree_cmd_cascade_color_account (GtkAction *action, GncPluginPageAccountTree *page) +gnc_plugin_page_account_tree_cmd_cascade_account_properties (GtkAction *action, GncPluginPageAccountTree *page) { Account *account = NULL; GtkWidget *window; @@ -1199,10 +1199,10 @@ gnc_plugin_page_account_tree_cmd_cascade_color_account (GtkAction *action, GncPl account = gnc_plugin_page_account_tree_get_current_account (page); - window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page)); + window = gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(page)); if (account != NULL) - gnc_account_cascade_color_dialog (window, account); + gnc_account_cascade_properties_dialog (window, account); LEAVE(" "); } diff --git a/gnucash/gtkbuilder/dialog-account.glade b/gnucash/gtkbuilder/dialog-account.glade index ccead50e05..29b05bff2a 100644 --- a/gnucash/gtkbuilder/dialog-account.glade +++ b/gnucash/gtkbuilder/dialog-account.glade @@ -2,9 +2,9 @@ - + False - Cascade Account Color + Cascade Account Values dialog @@ -56,33 +56,23 @@ - + True False - vertical - 12 - - - True - False - True - - - False - True - 0 - - + 6 + 6 True False - center + start + 3 - + True - True - True + False + end + Enable Cascading Account Color False @@ -91,11 +81,11 @@ - - Default + True True - True + False + True False @@ -105,44 +95,291 @@ - False - False - 1 + 0 + 1 - + True False - If any account has an existing color it will not be replaced unless the following is ticked. - True - False - True - 2 + 0 + 3 - - Replace any existing account colors + True - True - False - center - True + False + 3 + + + True + False + Enable Cascading Account Placeholder + + + False + True + 0 + + + + + True + True + False + True + + + False + True + 1 + + - False - True - 3 + 0 + 4 + + + + + True + False + + + 0 + 6 + + + + + True + False + 3 + + + True + False + Enable Cascading Account Hidden + + + False + True + 0 + + + + + True + True + False + True + + + False + True + 1 + + + + + 0 + 7 + + + + + True + False + Enable the sections to Cascade + + + + + + 0 + 0 + + + + + True + False + False + vertical + 3 + + + True + False + True + + + False + True + 0 + + + + + True + False + center + + + True + True + True + + + False + True + 0 + + + + + Default + True + True + True + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + If any account has an existing color it will not be replaced unless the following is ticked. + True + + + False + True + 2 + + + + + Replace any existing account colors + True + True + False + center + True + + + False + True + 3 + + + + + 0 + 2 + + + + + True + False + False + vertical + 3 + + + True + False + True + + + False + True + 0 + + + + + Placeholder + True + True + False + center + True + + + False + True + 1 + + + + + 0 + 5 + + + + + True + False + False + vertical + 3 + + + True + False + True + + + False + True + 0 + + + + + Hidden + True + True + False + center + True + + + False + True + 1 + + + + + 0 + 8 False True - 1 + 0 diff --git a/gnucash/ui/gnc-plugin-page-account-tree-ui.xml b/gnucash/ui/gnc-plugin-page-account-tree-ui.xml index 2584cceed8..a6c16c74ea 100644 --- a/gnucash/ui/gnc-plugin-page-account-tree-ui.xml +++ b/gnucash/ui/gnc-plugin-page-account-tree-ui.xml @@ -5,7 +5,7 @@ - + @@ -46,7 +46,7 @@ - +