Add the ability to cascade account colours in account tree

Add the ability to select an account that has sub-accounts and use that
accounts colour on all sub accounts. By default only sub accounts that
do not have a colour set are updated but there is an option to over ride
 this.
pull/384/head
Robert Fewell 8 years ago
parent 43af50bd8a
commit 0e4898fe0a

@ -2080,3 +2080,119 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
gtk_widget_show_all(data->dialog);
}
static void
default_color_button_cb (GtkButton *button, gpointer user_data)
{
GdkRGBA color;
if (gdk_rgba_parse (&color, DEFAULT_COLOR))
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(user_data), &color);
}
static void
update_account_color (Account *acc, const gchar *old_color, const gchar *new_color, gboolean replace)
{
// check to see if the color has been changed
if (g_strcmp0 (new_color, old_color) != 0)
{
if ((old_color == NULL) || (g_strcmp0 (old_color, "Not Set") == 0) || (replace == TRUE))
{
xaccAccountBeginEdit (acc);
xaccAccountSetColor (acc, new_color);
xaccAccountCommitEdit (acc);
}
}
}
void
gnc_account_cascade_color_dialog (GtkWidget *window, Account *account)
{
GtkWidget *dialog;
GtkBuilder *builder;
GtkWidget *color_label, *color_button, *over_write, *color_button_default;
gchar *string;
const char *color_string;
gchar *old_color_string;
GdkRGBA color;
gint response;
// check if we actualy do have sub accounts
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"));
gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window));
color_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(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);
g_free (string);
color_string = xaccAccountGetColor (account); // get existing account color
old_color_string = g_strdup (color_string); // save the old color string
if ((color_string == NULL) || (g_strcmp0 (color_string, "Not Set") == 0))
color_string = DEFAULT_COLOR;
// set the color chooser to account color
if (gdk_rgba_parse (&color, color_string))
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_button), &color);
/* default to cancel */
gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
gtk_builder_connect_signals (builder, dialog);
g_object_unref (G_OBJECT(builder));
gtk_widget_show_all (dialog);
response = gtk_dialog_run (GTK_DIALOG(dialog));
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;
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 = "Not Set";
// check/update selected account
update_account_color (account, old_color_string, new_color_string, replace);
if (accounts != NULL)
{
for (acct = accounts; acct; acct = g_list_next(acct))
{
const char *string = xaccAccountGetColor (acct->data);
// check/update sub-account
update_account_color (acct->data, string, new_color_string, replace);
}
g_list_free (accounts);
}
}
if (old_color_string)
g_free (old_color_string);
gtk_widget_destroy (dialog);
}

@ -161,6 +161,8 @@ 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);
/** @} */
/** @} */

@ -153,6 +153,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);
/* Command callback for new Register Test */
static void gnc_plugin_page_account_tree_cmd_open2_account (GtkAction *action, GncPluginPageAccountTree *page);
@ -226,6 +227,11 @@ static GtkActionEntry gnc_plugin_page_account_tree_actions [] =
N_("Delete selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_delete_account)
},
{
"ColorCascadeAccountAction", NULL, N_("_Cascade Account Color..."), NULL,
N_("Cascade selected account color"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_cascade_color_account)
},
{
"EditFindAccountAction", "edit-find", N_("F_ind Account"), "<primary>i",
N_("Find an account"),
@ -1179,6 +1185,24 @@ gnc_plugin_page_account_tree_cmd_find_account_popup (GtkAction *action, GncPlugi
LEAVE(" ");
}
static void
gnc_plugin_page_account_tree_cmd_cascade_color_account (GtkAction *action, GncPluginPageAccountTree *page)
{
Account *account = NULL;
GtkWidget *window;
ENTER("action %p, page %p", action, page);
account = gnc_plugin_page_account_tree_get_current_account (page);
window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
if (account != NULL)
gnc_account_cascade_color_dialog (window, account);
LEAVE(" ");
}
/********************************************************************
* delete_account_helper
* See if this account has any splits present. Set the user data

@ -2,6 +2,156 @@
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkDialog" id="account_cascade_color_dialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Cascade Account Color</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancelbutton3">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="okbutton3">
<property name="label">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="color_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkColorButton" id="color_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="color_button_default">
<property name="label" translatable="yes">Default</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="sub_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">If any account has an existing color it will not be replaced unless the following is ticked.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="replace_check">
<property name="label" translatable="yes">Replace any existing account colors</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">center</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancelbutton3</action-widget>
<action-widget response="-5">okbutton3</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
<object class="GtkDialog" id="account_delete_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>

@ -6,6 +6,7 @@
<menuitem name="EditDeleteAccount" action="EditDeleteAccountAction"/>
<menuitem name="EditAccountFindAccount" action="EditFindAccountAction"/>
<menuitem name="EditRenumberSubaccounts" action="EditRenumberSubaccountsAction"/>
<menuitem name="AccountColorCascade" action="ColorCascadeAccountAction"/>
<separator name="EditSep2"/>
<menuitem name="FileOpenAccount" action="FileOpenAccountAction"/>
<menuitem name="FileOpenSubaccounts" action="FileOpenSubaccountsAction"/>
@ -45,6 +46,7 @@
<menuitem name="AccountOpenAccount" action="FileOpenAccountAction"/>
<menuitem name="AccountOpenSubaccounts" action="FileOpenSubaccountsAction"/>
<menuitem name="AccountEditAccount" action="EditEditAccountAction"/>
<menuitem name="AccountColorCascade" action="ColorCascadeAccountAction"/>
<menuitem name="AccountFindAccountPopup" action="EditFindAccountPopupAction"/>
<separator name="AccountSep1"/>
<menuitem name="AccountReconcile" action="ActionsReconcileAction"/>

Loading…
Cancel
Save