r18216 - gnucash/trunk/src/gnome-utils - Fix bug 363339 – Exclude hidden accounts from reports
Phil Longstaff
plongstaff at code.gnucash.org
Sat Jul 18 12:12:03 EDT 2009
Author: plongstaff
Date: 2009-07-18 12:12:02 -0400 (Sat, 18 Jul 2009)
New Revision: 18216
Trac: http://svn.gnucash.org/trac/changeset/18216
Modified:
gnucash/trunk/src/gnome-utils/dialog-options.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-account.h
Log:
Fix bug 363339 – Exclude hidden accounts from reports
New check box added below account list to toggle excluding hidden accounts from the report.
Default is to exclude.
Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c 2009-07-18 01:54:08 UTC (rev 18215)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c 2009-07-18 16:12:02 UTC (rev 18216)
@@ -389,6 +389,19 @@
gnc_options_dialog_changed_internal (widget, TRUE);
}
+static void
+gnc_option_show_hidden_toggled_cb(GtkWidget *widget, GNCOption* option)
+{
+ AccountViewInfo avi;
+ GncTreeViewAccount *tree_view;
+
+ tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_widget (option));
+ gnc_tree_view_account_get_view_info (tree_view, &avi);
+ avi.show_hidden = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ gnc_tree_view_account_set_view_info (tree_view, &avi);
+ gnc_option_changed_widget_cb(widget, option);
+}
+
#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
static void
gnc_option_multichoice_cb(GtkWidget *widget, gpointer data)
@@ -852,6 +865,7 @@
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
avi.include_type[i] = FALSE;
+ avi.show_hidden = FALSE;
for (node = acct_type_list; node; node = node->next) {
GNCAccountType type = GPOINTER_TO_INT (node->data);
@@ -860,6 +874,16 @@
gnc_tree_view_account_set_view_info (GNC_TREE_VIEW_ACCOUNT (tree), &avi);
g_list_free (acct_type_list);
+ } else {
+ AccountViewInfo avi;
+ int i;
+
+ gnc_tree_view_account_get_view_info (GNC_TREE_VIEW_ACCOUNT (tree), &avi);
+
+ for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
+ avi.include_type[i] = TRUE;
+ avi.show_hidden = FALSE;
+ gnc_tree_view_account_set_view_info (GNC_TREE_VIEW_ACCOUNT (tree), &avi);
}
scroll_win = gtk_scrolled_window_new(NULL, NULL);
@@ -899,6 +923,13 @@
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(gnc_option_default_cb), option);
+ button = gtk_check_button_new_with_label(_("Show Hidden"));
+ gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
+ gtk_tooltips_set_tip(tooltips, button, _("Show hidden accounts."), NULL);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
+ g_signal_connect(G_OBJECT(button), "toggled",
+ G_CALLBACK(gnc_option_show_hidden_toggled_cb), option);
+
gnc_option_set_widget (option, tree);
return frame;
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2009-07-18 01:54:08 UTC (rev 18215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2009-07-18 16:12:02 UTC (rev 18216)
@@ -158,6 +158,7 @@
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
avi->include_type[i] = TRUE;
+ avi->show_hidden = FALSE;
}
static void
@@ -849,13 +850,9 @@
sel_bits |= avi->include_type[i] ? (1 << i): 0;
}
- /* FIXME: if we want to allow a truly empty bitfield, we'll have to fix
- the callers who don't set the include_type fields. */
- if (sel_bits) {
- gnc_tree_view_account_set_filter(
- account_view, gnc_tree_view_account_filter_by_type_selection,
- GUINT_TO_POINTER(sel_bits), NULL);
- }
+ gnc_tree_view_account_set_filter(
+ account_view, gnc_tree_view_account_filter_by_view_info,
+ &priv->avi, NULL);
LEAVE(" ");
}
@@ -942,6 +939,20 @@
return (sel_bits & (1 << acct_type)) ? TRUE : FALSE;
}
+gboolean
+gnc_tree_view_account_filter_by_view_info(Account* acct, gpointer data)
+{
+ GNCAccountType acct_type;
+ AccountViewInfo* avi = (AccountViewInfo*)data;
+
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acct), FALSE);
+ acct_type = xaccAccountGetType(acct);
+
+ if(!avi->include_type[acct_type]) return FALSE;
+ if(!avi->show_hidden && xaccAccountIsHidden(acct)) return FALSE;
+ return TRUE;
+}
+
/************************************************************/
/* Account Tree View Get/Set Functions */
/************************************************************/
@@ -1131,6 +1142,12 @@
gtk_tree_path_free(s_path);
}
+/* Information re selection process */
+typedef struct {
+ GList* return_list;
+ GncTreeViewAccountPrivate* priv;
+} GncTreeViewSelectionInfo;
+
/*
* This helper function is called once for each row in the tree view
* that is currently selected. Its task is to append the corresponding
@@ -1142,7 +1159,7 @@
GtkTreeIter *s_iter,
gpointer data)
{
- GList **return_list = data;
+ GncTreeViewSelectionInfo *gtvsi = data;
GtkTreeModel *f_model;
GtkTreeIter iter, f_iter;
Account *account;
@@ -1154,7 +1171,12 @@
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (f_model),
&iter, &f_iter);
account = iter.user_data;
- *return_list = g_list_append(*return_list, account);
+
+ /* Only selected if it passes the filter */
+ if (gtvsi->priv->filter_fn == NULL || gtvsi->priv->filter_fn(account, gtvsi->priv->filter_data))
+ {
+ gtvsi->return_list = g_list_append(gtvsi->return_list, account);
+ }
}
/*
@@ -1168,13 +1190,15 @@
gnc_tree_view_account_get_selected_accounts (GncTreeViewAccount *view)
{
GtkTreeSelection *selection;
- GList *return_list = NULL;
+ GncTreeViewSelectionInfo info;
g_return_val_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view), NULL);
+ info.return_list = NULL;
+ info.priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(view);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
- gtk_tree_selection_selected_foreach(selection, get_selected_accounts_helper, &return_list);
- return return_list;
+ gtk_tree_selection_selected_foreach(selection, get_selected_accounts_helper, &info);
+ return info.return_list;
}
/*
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.h 2009-07-18 01:54:08 UTC (rev 18215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.h 2009-07-18 16:12:02 UTC (rev 18216)
@@ -59,6 +59,7 @@
struct AccountViewInfo_s
{
gboolean include_type[NUM_ACCOUNT_TYPES];
+ gboolean show_hidden;
};
@@ -265,7 +266,7 @@
* thinks should possibly show. The filter may perform any actions
* necessary on the account to decide whether it should be shown or
* not. (I.E. Check type, placeholder status, etc.) If the filter
- * returns TRUE then the account wil be displayed.
+ * returns TRUE then the account will be displayed.
*
* @param account_view A pointer to an account tree view.
*
@@ -304,7 +305,18 @@
gboolean gnc_tree_view_account_filter_by_type_selection(
Account* acct, gpointer data);
+/* This is a convenient filter function for use with
+ * gnc_tree_view_account_set_filter() and the functions in
+ * gnc-tree-model-account-types.h. If you have some view that is
+ * backed by the "account types" tree model, you can get a guint32
+ * from that view's tree selection. Then, you can use that account
+ * type selection as a filter for the account tree view. This also
+ * can filter by whether an account is hidden or not.
+ */
+gboolean gnc_tree_view_account_filter_by_view_info(
+ Account* acct, gpointer data);
+
/** This function forces the account tree filter to be evaluated. It
* may be necessary to call this function if the initial state of the
* view is incorrect. This appears to only be necessary if the
More information about the gnucash-changes
mailing list