Add function to add the color background data function to account column

Some tree views based on GncTreeViewAccount specify there own columns
and when displayed you can end up with the Account column background
color set and the new ones uncolored which can look odd. Added a
function to add the color data function to the new columns.
This commit is contained in:
Robert Fewell 2017-07-15 11:32:00 +01:00 committed by John Ralls
parent fc0e25e7b2
commit 5a7a8d8d9b
4 changed files with 37 additions and 0 deletions

View File

@ -680,6 +680,10 @@ gnc_set_default_gain_loss_account_widget(gnc_commodity *commodity)
g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE,
GINT_TO_POINTER(1));
// add the color background data function to the column
gnc_tree_view_account_column_add_color (GNC_TREE_VIEW_ACCOUNT(
book_currency_data->default_gain_loss_account_widget), col);
col =
gnc_tree_view_add_toggle_column(GNC_TREE_VIEW(
book_currency_data->default_gain_loss_account_widget),
@ -696,6 +700,10 @@ gnc_set_default_gain_loss_account_widget(gnc_commodity *commodity)
g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE,
GINT_TO_POINTER(1));
// add the color background data function to the column
gnc_tree_view_account_column_add_color (GNC_TREE_VIEW_ACCOUNT(
book_currency_data->default_gain_loss_account_widget), col);
gnc_tree_view_configure_columns (GNC_TREE_VIEW(
book_currency_data->default_gain_loss_account_widget));
gnc_tree_view_set_show_column_menu(GNC_TREE_VIEW(

View File

@ -659,6 +659,18 @@ gnc_tree_view_account_color_update (gpointer gsettings, gchar *key, gpointer use
priv->show_account_color = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, key);
}
/** Add the account color background data function to the GncTreeViewAccount column to
* show or not the column background in the account color.
*/
void
gnc_tree_view_account_column_add_color (GncTreeViewAccount *view, GtkTreeViewColumn *col)
{
GtkCellRenderer *renderer = gnc_tree_view_column_get_renderer(col);
gtk_tree_view_column_set_cell_data_func (col, renderer, acc_color_data_func,
GTK_TREE_VIEW(view), NULL);
}
/************************************************************/
/* New View Creation */
/************************************************************/
@ -1743,6 +1755,7 @@ account_cell_property_data_func (GtkTreeViewColumn *tree_column,
GtkTreeIter *s_iter,
gpointer key)
{
GncTreeViewAccount *view;
Account *account;
gchar *string = NULL;
@ -1755,6 +1768,11 @@ account_cell_property_data_func (GtkTreeViewColumn *tree_column,
string = "";
g_object_set (G_OBJECT (cell), "text", string, "xalign", 0.0, NULL);
view = g_object_get_data(G_OBJECT(tree_column), "tree-view");
if (GNC_IS_TREE_VIEW_ACCOUNT (view))
acc_color_data_func (tree_column, cell, s_model, s_iter, view);
}
@ -1778,6 +1796,9 @@ gnc_tree_view_account_add_property_column (GncTreeViewAccount *view,
renderer = gnc_tree_view_column_get_renderer(column);
g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
// add a pointer to the view to make it easier to access in data_func
g_object_set_data(G_OBJECT(column), "tree-view", (gpointer)view);
gtk_tree_view_column_set_cell_data_func (column, renderer,
account_cell_property_data_func,
g_strdup(propname), g_free);

View File

@ -471,6 +471,11 @@ void gnc_tree_view_account_select_subaccounts (GncTreeViewAccount *view,
*/
void gnc_tree_view_account_expand_to_account (GncTreeViewAccount *view, Account *account);
/** Add the account color background data function to the GncTreeViewAccount column to
* show or not the column background in the account color.
*/
void gnc_tree_view_account_column_add_color (GncTreeViewAccount *view, GtkTreeViewColumn *col);
/** @} */
/** @} */

View File

@ -118,6 +118,9 @@ build_acct_tree(AccountPickerDialog *picker)
_("Account ID"), "online-id");
g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
// the color background data function is part of the add_property_column
// function which will color the background based on preference setting
gtk_container_add(GTK_CONTAINER(picker->account_tree_sw),
GTK_WIDGET(picker->account_tree));