GnuCash  5.6-150-g038405b370+
Files | Data Structures | Macros | Enumerations | Functions
GncTreeView

Files

file  gnc-tree-view.c
 Base GncTreeView implementation for gnucash trees.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 

Data Structures

struct  GncTreeViewPrivate
 Private Data Structure. More...
 

Macros

#define STATE_KEY   "state-key"
 
#define STATE_KEY_SORT_COLUMN   "sort_column"
 
#define STATE_KEY_SORT_ORDER   "sort_order"
 
#define STATE_KEY_COLUMN_ORDER   "column_order"
 
#define STATE_KEY_SUFF_VISIBLE   "visible"
 
#define STATE_KEY_SUFF_WIDTH   "width"
 

Enumerations

enum  { PROP_0, PROP_STATE_SECTION, PROP_SHOW_COLUMN_MENU }
 

Functions

void gnc_tree_view_configure_columns (GncTreeView *view)
 Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available. More...
 
GtkTreeViewColumn * gnc_tree_view_add_toggle_column (GncTreeView *view, const gchar *column_title, const gchar *column_short_title, const gchar *pref_name, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn, renderer_toggled toggle_edited_cb)
 This function adds a new toggle column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_view_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text view column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_pix_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new pixbuf view column to a GncTreeView base view. More...
 
GtkCellRenderer * gnc_tree_view_column_get_renderer (GtkTreeViewColumn *column)
 Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines. More...
 
GtkTreeViewColumn * gnc_tree_view_add_numeric_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_color_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new numeric column to a GncTreeView base view. More...
 
gint gnc_tree_view_append_column (GncTreeView *view, GtkTreeViewColumn *column)
 Add a column to a view based upon a GncTreeView. More...
 
gboolean gnc_tree_view_path_is_valid (GncTreeView *view, GtkTreePath *path)
 
void gnc_tree_view_keynav (GncTreeView *view, GtkTreeViewColumn **col, GtkTreePath *path, GdkEventKey *event)
 
void gnc_tree_view_set_editing_started_cb (GncTreeView *view, GFunc editing_started_cb, gpointer editing_cb_data)
 Setup a callback for when the user starts editing so appropriate actions can be taken like disable the actions delete menu option.
 
void gnc_tree_view_set_editing_finished_cb (GncTreeView *view, GFunc editing_finished_cb, gpointer editing_cb_data)
 Setup a callback for when the user finishes editing so appropriate actions can be taken like enable the actions delete menu option.
 
void tree_view_column_set_default_width (GtkTreeView *view, GtkTreeViewColumn *column, const gchar *sizing_text)
 Set default width for a treeview column. More...
 

Gnc Tree View Auxiliary Functions

GtkTreeViewColumn * gnc_tree_view_find_column_by_name (GncTreeView *view, const gchar *wanted)
 Find a tree column given the "pref name" used with saved state. More...
 

Gnc Tree View state Callback / Related Functions

void gnc_tree_view_remove_state_information (GncTreeView *view)
 Completely wipe the treeview's state information (column visibility, width, sorting order,..). More...
 
void gnc_tree_view_set_state_section (GncTreeView *view, const gchar *section)
 Set up or remove an association between a saved state section and the display of a view. More...
 
const gchar * gnc_tree_view_get_state_section (GncTreeView *view)
 Get the name of the state section this tree view is associated with. More...
 
void gnc_tree_view_save_state (GncTreeView *view)
 This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file. More...
 

Gnc Tree View Column Selection Menu Related Functions

void gnc_tree_view_expand_columns (GncTreeView *view, gchar *first_column_name,...)
 This function set the columns that will be allocated the free space in the view. More...
 
void gnc_tree_view_set_control_column_background (GncTreeView *view, gint column, GtkTreeCellDataFunc func)
 This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property. More...
 
void gnc_tree_view_set_sort_user_data (GncTreeView *view, GtkTreeModel *s_model)
 This allows the columns to be setup without the model connected. More...
 
void gnc_tree_view_set_show_column_menu (GncTreeView *view, gboolean visible)
 This function is called to set the "show-column-menu" property on this view. More...
 
gboolean gnc_tree_view_get_show_column_menu (GncTreeView *view)
 This function is called to get the current value of the "show-column-menu" property. More...
 

Detailed Description

Function Documentation

◆ gnc_tree_view_add_numeric_column()

GtkTreeViewColumn* gnc_tree_view_add_numeric_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_color_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new numeric column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered. A numeric column is nothing more then a text column with a few extra attributes.

Parameters are defined in gnc-tree-view.h

Definition at line 2060 of file gnc-tree-view.c.

2068 {
2069  GtkTreeViewColumn *column;
2070  GtkCellRenderer *renderer;
2071  gfloat alignment = 1.0;
2072 
2073  column = gnc_tree_view_add_text_column (view, column_title, pref_name,
2074  NULL, sizing_text, model_data_column,
2075  model_visibility_column,
2076  column_sort_fn);
2077 
2078  renderer = gnc_tree_view_column_get_renderer (column);
2079 
2080  /* Right align the column title and data for both ltr and rtl */
2081  if (gtk_widget_get_direction (GTK_WIDGET(view)) == GTK_TEXT_DIR_RTL)
2082  alignment = 0.0;
2083 
2084  g_object_set (G_OBJECT(column), "alignment", alignment, NULL);
2085  g_object_set (G_OBJECT(renderer), "xalign", alignment, NULL);
2086 
2087  /* Change the text color */
2088  if (model_color_column != GNC_TREE_VIEW_COLUMN_COLOR_NONE)
2089  gtk_tree_view_column_add_attribute (column, renderer,
2090  "foreground", model_color_column);
2091 
2092  return column;
2093 }
GtkCellRenderer * gnc_tree_view_column_get_renderer(GtkTreeViewColumn *column)
Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the conveni...
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
This function adds a new text column to a GncTreeView base view.

◆ gnc_tree_view_add_pix_column()

GtkTreeViewColumn* gnc_tree_view_add_pix_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new pixbuf view column to a GncTreeView base view.

This function adds a pixbuf view column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1984 of file gnc-tree-view.c.

1991 {
1992  GtkTreeViewColumn *column;
1993  PangoLayout* layout;
1994  int default_width, title_width;
1995  GtkCellRenderer *renderer;
1996 
1997  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1998 
1999  renderer = gtk_cell_renderer_pixbuf_new ();
2000 
2001  column = gtk_tree_view_column_new ();
2002  gtk_tree_view_column_set_title (column, column_title);
2003 
2004  /* Set up a text renderer and attributes */
2005  gtk_tree_view_column_pack_start (column, renderer, TRUE);
2006 
2007  /* Set renderer attributes controlled by the model */
2008  if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
2009  gtk_tree_view_column_add_attribute (column, renderer,
2010  "icon-name", model_data_column);
2011  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
2012  gtk_tree_view_column_add_attribute (column, renderer,
2013  "visible", model_visibility_column);
2014 
2015  /* Default size is the larger of the column title and the sizing text */
2016  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
2017  pango_layout_get_pixel_size (layout, &title_width, NULL);
2018  g_object_unref (layout);
2019  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
2020  pango_layout_get_pixel_size (layout, &default_width, NULL);
2021  g_object_unref (layout);
2022  default_width = MAX(default_width, title_width);
2023  if (default_width)
2024  default_width += 10; /* padding on either side */
2025  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
2026  default_width, TRUE, column_sort_fn);
2027 
2028  gnc_tree_view_append_column (view, column);
2029  return column;
2030 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_add_text_column()

GtkTreeViewColumn* gnc_tree_view_add_text_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1920 of file gnc-tree-view.c.

1928 {
1929  GtkCellRenderer *renderer;
1930 
1931  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1932 
1933  renderer = gtk_cell_renderer_text_new ();
1934 
1935  return add_text_column_variant (view, renderer,
1936  column_title, pref_name,
1937  icon_name, sizing_text,
1938  model_data_column,
1939  model_visibility_column,
1940  column_sort_fn);
1941 }

◆ gnc_tree_view_add_text_view_column()

GtkTreeViewColumn* gnc_tree_view_add_text_view_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text view column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1952 of file gnc-tree-view.c.

1960 {
1961  GtkCellRenderer *renderer;
1962 
1963  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1964 
1965  renderer = gnc_cell_renderer_text_view_new ();
1966 
1967  return add_text_column_variant (view, renderer,
1968  column_title, pref_name,
1969  icon_name, sizing_text,
1970  model_data_column,
1971  model_visibility_column,
1972  column_sort_fn);
1973 }

◆ gnc_tree_view_add_toggle_column()

GtkTreeViewColumn* gnc_tree_view_add_toggle_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  column_short_title,
const gchar *  pref_name,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn,
renderer_toggled  toggle_edited_cb 
)

This function adds a new toggle column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. It handles creating a tooltip to show the full title name, and setting the sort and edit callback functions. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1767 of file gnc-tree-view.c.

1775 {
1776  GtkTreeViewColumn *column;
1777  GtkCellRenderer *renderer;
1778 
1779  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1780 
1781  renderer = gtk_cell_renderer_toggle_new ();
1782  if (!toggle_edited_cb)
1783  {
1784  gtk_cell_renderer_toggle_set_activatable (GTK_CELL_RENDERER_TOGGLE(renderer), FALSE);
1785  }
1786  column =
1787  gtk_tree_view_column_new_with_attributes (column_short_title,
1788  renderer,
1789  "active", model_data_column,
1790  NULL);
1791 
1792  /* Add the full title to the object for menu creation */
1793  g_object_set_data_full (G_OBJECT(column), REAL_TITLE,
1794  g_strdup(column_title), g_free);
1795  if (toggle_edited_cb)
1796  g_signal_connect (G_OBJECT(renderer), "toggled",
1797  G_CALLBACK(toggle_edited_cb), view);
1798 
1799  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
1800  gtk_tree_view_column_add_attribute (column, renderer,
1801  "visible", model_visibility_column);
1802 
1803 
1804  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
1805  0, FALSE, column_sort_fn);
1806 
1807  gnc_tree_view_append_column (view, column);
1808 
1809  /* Also add the full title to the object as a tooltip */
1810  gtk_widget_set_tooltip_text (gtk_tree_view_column_get_button (column), column_title);
1811 
1812  return column;
1813 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_append_column()

gint gnc_tree_view_append_column ( GncTreeView *  view,
GtkTreeViewColumn *  column 
)

Add a column to a view based upon a GncTreeView.

This function knows about the two special columns on the right side of this type of view, and adds the new column before these two columns. You could say that it appends to the data columns and ignores the infrastructure columns.

Parameters are defined in gnc-tree-view.h

Definition at line 2104 of file gnc-tree-view.c.

2106 {
2107  int n = gtk_tree_view_get_n_columns (GTK_TREE_VIEW(view));
2108 
2109  /* Ignore the initial column, the selection menu */
2110  if (n >= 1)
2111  n -= 1;
2112  return gtk_tree_view_insert_column (GTK_TREE_VIEW(view), column, n);
2113 }

◆ gnc_tree_view_column_get_renderer()

GtkCellRenderer* gnc_tree_view_column_get_renderer ( GtkTreeViewColumn *  column)

Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines.

Parameters
columnThe tree view column that was added to the GncTreeView
Returns
The cell renderer in use in the column.

Definition at line 2033 of file gnc-tree-view.c.

2034 {
2035  GList *renderers;
2036  GtkCellRenderer *cr = NULL;
2037 
2038  g_return_val_if_fail (GTK_TREE_VIEW_COLUMN(column), NULL);
2039 
2040  /* Get the list of one renderer */
2041  renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(column));
2042  if (g_list_length (renderers) > 0)
2043  cr = GTK_CELL_RENDERER(renderers->data);
2044  g_list_free (renderers);
2045 
2046  return cr;
2047 }

◆ gnc_tree_view_configure_columns()

void gnc_tree_view_configure_columns ( GncTreeView *  view)

Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.

Parameters
viewA pointer to an gnc tree view.

Definition at line 1597 of file gnc-tree-view.c.

1598 {
1599  GncTreeViewPrivate *priv;
1600  GtkTreeViewColumn *column;
1601  GList *columns;
1602  gboolean hide_menu_column;
1603 
1604  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1605 
1606  ENTER(" ");
1607 
1608  /* Update the view and saved state */
1609  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1610  g_list_foreach (columns, (GFunc)gnc_tree_view_update_visibility, view);
1611  g_list_free (columns);
1612 
1613  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1614  if (priv->state_section)
1615  priv->seen_state_visibility = TRUE;
1616 
1617  /* If only the first column is visible, hide the spacer and make that
1618  * column expand. */
1619  hide_menu_column = (gnc_tree_view_count_visible_columns (view) == 1);
1620  column = gtk_tree_view_get_column (GTK_TREE_VIEW(view), 0);
1621  gtk_tree_view_column_set_expand (column, hide_menu_column);
1622  gtk_tree_view_column_set_visible (priv->column_menu_column, !hide_menu_column);
1623 
1624  LEAVE(" ");
1625 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_expand_columns()

void gnc_tree_view_expand_columns ( GncTreeView *  view,
gchar *  first_column_name,
  ... 
)

This function set the columns that will be allocated the free space in the view.

Parameters
viewThe tree view.
listof column names.

Definition at line 1432 of file gnc-tree-view.c.

1435 {
1436  GtkTreeViewColumn *column;
1437  GList *columns, *tmp;
1438  gchar *name, *pref_name;
1439  va_list args;
1440 
1441  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1442  ENTER(" ");
1443  va_start (args, first_column_name);
1444  name = first_column_name;
1445 
1446  /* First disable the expand property on all (non-infrastructure) columns. */
1447  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1448  for (tmp = columns; tmp; tmp = g_list_next (tmp))
1449  {
1450  column = tmp->data;
1451  pref_name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1452  if (pref_name != NULL)
1453  gtk_tree_view_column_set_expand (column, FALSE);
1454  }
1455  g_list_free(columns);
1456 
1457  /* Now enable it on the requested columns. */
1458  while (name != NULL)
1459  {
1460  column = gnc_tree_view_find_column_by_name (view, name);
1461  if (column != NULL)
1462  {
1463  gtk_tree_view_column_set_expand (column, TRUE);
1464  }
1465  name = va_arg (args, gchar*);
1466  }
1467  va_end (args);
1468 
1469  LEAVE(" ");
1470 }
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_tree_view_find_column_by_name()

GtkTreeViewColumn* gnc_tree_view_find_column_by_name ( GncTreeView *  view,
const gchar *  wanted 
)

Find a tree column given the "pref name" used with saved state.

Find a tree column given the "pref name".

This function simply runs the list of all (visible and invisible) columns looking for a match. Column names were attached to each column at the time the column was created.

Parameters
viewThe visible tree widget.
wantedThe "pref name" to find.

Definition at line 537 of file gnc-tree-view.c.

539 {
540  GtkTreeViewColumn *column, *found = NULL;
541  GList *column_list, *tmp;
542  const gchar *name;
543 
544  // ENTER("view %p, wanted %s", view, wanted);
545  column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
546  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
547  {
548  column = tmp->data;
549  name = g_object_get_data (G_OBJECT(column), PREF_NAME);
550  if (!name || (strcmp(name, wanted) != 0))
551  continue;
552  found = column;
553  break;
554  }
555  g_list_free (column_list);
556 
557  // LEAVE("column %p", found);
558  return found;
559 }

◆ gnc_tree_view_get_show_column_menu()

gboolean gnc_tree_view_get_show_column_menu ( GncTreeView *  view)

This function is called to get the current value of the "show-column-menu" property.

It returns the same value passed to gnc_tree_view_set_show_menu_column().

Parameters are defined in gnc-tree-view.h

Definition at line 1561 of file gnc-tree-view.c.

1562 {
1563  GncTreeViewPrivate *priv;
1564 
1565  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), FALSE);
1566 
1567  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1568  return (priv->show_column_menu);
1569 }
Private Data Structure.

◆ gnc_tree_view_get_state_section()

const gchar* gnc_tree_view_get_state_section ( GncTreeView *  view)

Get the name of the state section this tree view is associated with.

This function is called to get the current association between a saved state section and the display of a view.

It returns the same value passed to gnc_tree_view_set_state_section(); i.e. a string like "dialogs/edit_prices".

Parameters are defined in gnc-tree-view.h

Definition at line 1123 of file gnc-tree-view.c.

1124 {
1125  GncTreeViewPrivate *priv;
1126 
1127  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1128 
1129  priv = GNC_TREE_VIEW_GET_PRIVATE (view);
1130  return priv->state_section;
1131 }
Private Data Structure.

◆ gnc_tree_view_remove_state_information()

void gnc_tree_view_remove_state_information ( GncTreeView *  view)

Completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function is called to completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function may be called at any time; either when the user wants to disconnect or when the view object is being destroyed.

Parameters
viewThe tree view.

Definition at line 981 of file gnc-tree-view.c.

982 {
983  GncTreeViewPrivate *priv;
984  GKeyFile *state_file = gnc_state_get_current ();
985 
986  ENTER(" ");
987  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
988  if (!priv->state_section)
989  {
990  LEAVE("no state section");
991  return;
992  }
993 
994  g_key_file_remove_group (state_file, priv->state_section, NULL);
995  g_free (priv->state_section);
996  priv->state_section = NULL;
997  LEAVE(" ");
998 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_save_state()

void gnc_tree_view_save_state ( GncTreeView *  view)

This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file.

Parameters
viewThe tree view.

Definition at line 1133 of file gnc-tree-view.c.

1134 {
1135  GncTreeViewPrivate *priv;
1136 
1137  ENTER("view %p", view);
1138  g_return_if_fail (view != NULL);
1139  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1140 
1141  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1142 
1143  if (priv->state_section)
1144  {
1145  /* Save state. Only store non-default values when possible. */
1146  GList *column_list, *tmp;
1147  GKeyFile *state_file = gnc_state_get_current();
1148  gsize num_cols = 0;
1149  gchar *sort_column = gnc_tree_view_get_sort_column (view);
1150  gchar *sort_order = gnc_tree_view_get_sort_order (view);
1151  gchar **col_order = gnc_tree_view_get_column_order (view, &num_cols);
1152 
1153  /* Default sort column is the name column */
1154  if (sort_column && (g_strcmp0 (sort_column, "name") != 0))
1155  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, sort_column);
1156  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL))
1157  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL);
1158  g_free (sort_column);
1159 
1160 
1161  /* Default sort order is "ascending" */
1162  if (g_strcmp0 (sort_order, "descending") == 0)
1163  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_ORDER, sort_order);
1164  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL))
1165  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL);
1166  g_free (sort_order);
1167 
1168  if (col_order && (num_cols > 0))
1169  g_key_file_set_string_list (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER,
1170  (const gchar**) col_order, num_cols);
1171  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL))
1172  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL);
1173 
1174  g_strfreev (col_order);
1175 
1176 
1177  // ENTER("view %p, wanted %s", view, wanted);
1178  column_list = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1179  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
1180  {
1181  GtkTreeViewColumn *column = tmp->data;
1182  gchar *key=NULL;
1183  const gchar *name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1184  if (!name)
1185  continue;
1186 
1187  if (!g_object_get_data (G_OBJECT(column), ALWAYS_VISIBLE))
1188  {
1189  key = g_strjoin ("_", name, STATE_KEY_SUFF_VISIBLE, NULL);
1190  g_key_file_set_boolean (state_file, priv->state_section, key,
1191  gtk_tree_view_column_get_visible (column));
1192  g_free (key);
1193  }
1194 
1195  key = g_strjoin ("_", name, STATE_KEY_SUFF_WIDTH, NULL);
1196  if (g_object_get_data (G_OBJECT(column), "default-width") &&
1197  (GPOINTER_TO_INT((g_object_get_data (G_OBJECT(column), "default-width")))
1198  != gtk_tree_view_column_get_width (column)))
1199  {
1200  g_key_file_set_integer (state_file, priv->state_section, key,
1201  gtk_tree_view_column_get_width (column));
1202  }
1203  else if (g_key_file_has_key (state_file, priv->state_section, key, NULL))
1204  g_key_file_remove_key (state_file, priv->state_section, key, NULL);
1205  g_free (key);
1206  }
1207  g_list_free (column_list);
1208  }
1209 
1210  LEAVE(" ");
1211 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_control_column_background()

void gnc_tree_view_set_control_column_background ( GncTreeView *  view,
gint  column,
GtkTreeCellDataFunc  func 
)

This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property.

Parameters
viewThe tree view.
columnThe column in the model containing color strings.
funcThis is a cell data function that sets the "cell-background".

Definition at line 1501 of file gnc-tree-view.c.

1502 {
1503  GncTreeViewPrivate *priv;
1504 
1505  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1506 
1507  ENTER("view %p, column %d, func %p", view, column, func);
1508  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1509 
1510  update_control_cell_renderers_background (view, priv->column_menu_column, column, func);
1511 
1512  LEAVE(" ");
1513 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_show_column_menu()

void gnc_tree_view_set_show_column_menu ( GncTreeView *  view,
gboolean  visible 
)

This function is called to set the "show-column-menu" property on this view.

This function has no visible effect if the "state-section" property has not been set.

Parameters are defined in gnc-tree-view.h

Definition at line 1540 of file gnc-tree-view.c.

1542 {
1543  GncTreeViewPrivate *priv;
1544 
1545  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1546 
1547  ENTER("view %p, show menu %d", view, visible);
1548  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1549  priv->show_column_menu = visible;
1550  gnc_tree_view_build_column_menu (view);
1551  LEAVE(" ");
1552 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_sort_user_data()

void gnc_tree_view_set_sort_user_data ( GncTreeView *  view,
GtkTreeModel *  s_model 
)

This allows the columns to be setup without the model connected.

Parameters
viewThe tree view.
sortmodel.

Definition at line 1519 of file gnc-tree-view.c.

1520 {
1521  GncTreeViewPrivate *priv;
1522 
1523  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1524 
1525  ENTER("view %p, sort_model %p", view, s_model);
1526  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1527 
1528  priv->sort_model = s_model;
1529  LEAVE(" ");
1530 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_state_section()

void gnc_tree_view_set_state_section ( GncTreeView *  view,
const gchar *  section 
)

Set up or remove an association between a saved state section and the display of a view.

This function is called to set up or remove an association between a saved state section and the display of a view.

It will first remove any existing association, and then install the new one. If the new section has state information, update the view with this information.

Parameters are defined in gnc-tree-view.h

Definition at line 1008 of file gnc-tree-view.c.

1010 {
1011  GncTreeViewPrivate *priv;
1012  GKeyFile *state_file;
1013 
1014  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1015 
1016  ENTER("view %p, section %s", view, section);
1017 
1018  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1019 
1020  /* Drop any previous state section */
1021  if (priv->state_section)
1023 
1024  if (!section)
1025  {
1026  LEAVE("cleared state section");
1027  return;
1028  }
1029 
1030  /* Catch changes in state. Propagate to view. */
1031  priv->state_section = g_strdup (section);
1032 
1033  state_file = gnc_state_get_current ();
1034  if (g_key_file_has_group (state_file, priv->state_section))
1035  {
1036  gsize num_keys, idx;
1037  gchar **keys = g_key_file_get_keys (state_file, priv->state_section, &num_keys, NULL);
1038  for (idx = 0; idx < num_keys; idx++)
1039  {
1040  gchar *key = keys[idx];
1041  if (g_strcmp0 (key, STATE_KEY_SORT_COLUMN) == 0)
1042  {
1043  gchar *name = g_key_file_get_string (state_file, priv->state_section,
1044  key, NULL);
1045  gnc_tree_view_set_sort_column (view, name);
1046  g_free (name);
1047  }
1048  else if (g_strcmp0 (key, STATE_KEY_SORT_ORDER) == 0)
1049  {
1050  gchar *name = g_key_file_get_string (state_file, priv->state_section,
1051  key, NULL);
1052  gnc_tree_view_set_sort_order (view, name);
1053  g_free (name);
1054  }
1055  else if (g_strcmp0 (key, STATE_KEY_COLUMN_ORDER) == 0)
1056  {
1057  gsize length;
1058  gchar **columns = g_key_file_get_string_list (state_file, priv->state_section,
1059  key, &length, NULL);
1060  gnc_tree_view_set_column_order (view, columns, length);
1061  g_strfreev (columns);
1062  }
1063  else
1064  {
1065  /* Make a copy of the local part of the key so it can be split
1066  * into column name and key type */
1067  gboolean known = FALSE;
1068  gchar *column_name = g_strdup (key);
1069  gchar *type_name = g_strrstr (column_name, "_");
1070 
1071  if (type_name != NULL) //guard against not finding '_'
1072  {
1073  *type_name++ = '\0';
1074 
1075  if (g_strcmp0 (type_name, STATE_KEY_SUFF_VISIBLE) == 0)
1076  {
1077  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1078  if (column)
1079  {
1080  known = TRUE;
1081  if (!g_object_get_data (G_OBJECT (column), ALWAYS_VISIBLE))
1082  {
1083  gtk_tree_view_column_set_visible (column,
1084  g_key_file_get_boolean (state_file, priv->state_section, key, NULL));
1085  }
1086  }
1087  }
1088  else if (g_strcmp0 (type_name, STATE_KEY_SUFF_WIDTH) == 0)
1089  {
1090  gint width = g_key_file_get_integer (state_file, priv->state_section, key, NULL);
1091  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1092  if (column)
1093  {
1094  known = TRUE;
1095  if (width && (width != gtk_tree_view_column_get_width (column)))
1096  {
1097  gtk_tree_view_column_set_fixed_width (column, width);
1098  }
1099  }
1100  }
1101  if (!known)
1102  DEBUG ("Ignored key %s", key);
1103 
1104  g_free (column_name);
1105  }
1106  }
1107  }
1108  g_strfreev (keys);
1109  }
1110 
1111  /* Rebuild the column visibility menu */
1112  gnc_tree_view_build_column_menu (view);
1113  LEAVE ("set state section");
1114 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_tree_view_remove_state_information(GncTreeView *view)
Completely wipe the treeview&#39;s state information (column visibility, width, sorting order...
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ tree_view_column_set_default_width()

void tree_view_column_set_default_width ( GtkTreeView *  view,
GtkTreeViewColumn *  column,
const gchar *  sizing_text 
)

Set default width for a treeview column.

This base width is the largest of the column title and some arbitrary text passed in via sizing_text. This base width is then increased with some padding.

Definition at line 43 of file tree-view-utils.c.

46 {
47  PangoLayout* layout;
48  int default_width, title_width;
49  const gchar *column_title;
50 
51  /* Default size is the larger of the column title and the sizing text */
52  column_title = gtk_tree_view_column_get_title (column);
53  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
54  pango_layout_get_pixel_size(layout, &title_width, NULL);
55  g_object_unref(layout);
56  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
57  pango_layout_get_pixel_size(layout, &default_width, NULL);
58  g_object_unref(layout);
59  default_width = MAX(default_width, title_width);
60  if (default_width)
61  {
62  default_width += 10; /* add some padding */
63  g_object_set(G_OBJECT(column),
64  "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
65  "fixed-width", default_width,
66  NULL);
67  }
68 }