Index: src/gnome-utils/gnc-tree-view-account.c =================================================================== --- src/gnome-utils/gnc-tree-view-account.c (revision 22252) +++ src/gnome-utils/gnc-tree-view-account.c (working copy) @@ -77,6 +77,10 @@ GtkTreeIter *iter, gpointer view); +static void select_account_helper(GncTreeViewAccount *view, + Account *account, + gboolean scroll_to_account); + typedef struct GncTreeViewAccountPrivate { AccountViewInfo avi; @@ -85,6 +89,8 @@ gpointer filter_data; GSourceFunc filter_destroy; + GList *selected_but_hidden_accounts; + GtkTreeViewColumn *name_column; GtkTreeViewColumn *code_column; GtkTreeViewColumn *desc_column; @@ -198,6 +204,8 @@ } priv->filter_fn = NULL; + g_list_free(priv->selected_but_hidden_accounts); + if (G_OBJECT_CLASS (parent_class)->finalize) (* G_OBJECT_CLASS (parent_class)->finalize) (object); LEAVE(" "); @@ -1017,13 +1025,30 @@ void gnc_tree_view_account_refilter (GncTreeViewAccount *view) { + GList *to_be_selected; + GncTreeViewAccountPrivate* priv; GtkTreeModel *f_model, *s_model; g_return_if_fail(GNC_IS_TREE_VIEW_ACCOUNT(view)); + priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(view); s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model)); + + /* We will try to select the previously selected accounts, + * because some of them were hidden and need to be set selected + * and some of them are now hidden and need to be added + * to priv->selected_but_hidden_accounts*/ + to_be_selected=gnc_tree_view_account_get_selected_accounts(view); + priv->selected_but_hidden_accounts=NULL; + gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (f_model)); + + while(to_be_selected != NULL) + { + select_account_helper(view, to_be_selected->data, FALSE); + to_be_selected = g_list_delete_link(to_be_selected, to_be_selected); + } } gboolean @@ -1162,28 +1187,30 @@ } /* - * Selects a single account in the account tree view. The account - * tree must be in single selection mode. - */ -void -gnc_tree_view_account_set_selected_account (GncTreeViewAccount *view, - Account *account) + * This helper function selects an account, either by adding it + * to the TreeSelection, if is in the current filter, + * or otherwise by adding it to priv->selected_but_hidden_accounts.*/ +static void +select_account_helper(GncTreeViewAccount *view, + Account *account, + gboolean scroll_to_account) { + GncTreeViewAccountPrivate* priv; GtkTreeModel *model, *f_model, *s_model; GtkTreePath *path, *f_path, *s_path, *parent_path; GtkTreeSelection *selection; ENTER("view %p, account %p (%s)", view, account, xaccAccountGetName (account)); - g_return_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view)); - /* Clear any existing selection. */ - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - gtk_tree_selection_unselect_all (selection); - if (account == NULL) + { + LEAVE("no account"); return; + } + priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(view); + s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model)); model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model)); @@ -1202,6 +1229,7 @@ gtk_tree_path_free(path); if (f_path == NULL) { + priv->selected_but_hidden_accounts=g_list_prepend(priv->selected_but_hidden_accounts, account); LEAVE("no filter path"); return; } @@ -1227,17 +1255,47 @@ } gtk_tree_path_free(parent_path); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_select_path (selection, s_path); - /* give gtk+ a chance to resize the tree view first by handling pending - * configure events */ - while (gtk_events_pending ()) - gtk_main_iteration (); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(view), s_path, NULL, FALSE, 0.0, 0.0); - debug_path(LEAVE, s_path); - gtk_tree_path_free(s_path); + if (scroll_to_account) + { + /* give gtk+ a chance to resize the tree view first by handling pending + * configure events */ + while (gtk_events_pending ()) + gtk_main_iteration (); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(view), s_path, NULL, FALSE, 0.0, 0.0); + debug_path(LEAVE, s_path); + gtk_tree_path_free(s_path); + } + + LEAVE(" "); } +/* + * Selects a single account in the account tree view. The account + * tree must be in single selection mode. + */ +void +gnc_tree_view_account_set_selected_account (GncTreeViewAccount *view, + Account *account) +{ + GtkTreeSelection *selection; + GncTreeViewAccountPrivate* priv; + + g_return_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view)); + + priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(view); + + /* Clear any existing selection. */ + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); + gtk_tree_selection_unselect_all (selection); + g_list_free(priv->selected_but_hidden_accounts); + priv->selected_but_hidden_accounts=NULL; + + select_account_helper(view, account, TRUE); +} + /* Information re selection process */ typedef struct { @@ -1269,11 +1327,7 @@ &iter, &f_iter); account = iter.user_data; - /* 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); - } + gtvsi->return_list = g_list_append(gtvsi->return_list, account); } /* @@ -1288,6 +1342,7 @@ { GtkTreeSelection *selection; GncTreeViewSelectionInfo info; + GList * selected_but_hidden; g_return_val_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view), NULL); @@ -1295,6 +1350,9 @@ 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, &info); + + selected_but_hidden=g_list_copy(info.priv->selected_but_hidden_accounts); + info.return_list=g_list_concat(info.return_list, selected_but_hidden); return info.return_list; } @@ -1307,6 +1365,7 @@ GList *account_list, gboolean show_last) { + GncTreeViewAccountPrivate *priv; GtkTreeModel *model, *f_model, *s_model; GtkTreePath *path, *f_path, *s_path, *parent_path; GtkTreeSelection *selection; @@ -1315,13 +1374,13 @@ g_return_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view)); - s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model)); - model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model)); + priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(view); /* Clear any existing selection. */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_unselect_all (selection); + g_list_free(priv->selected_but_hidden_accounts); + priv->selected_but_hidden_accounts=NULL; gtk_tree_view_collapse_all (GTK_TREE_VIEW(view)); /* Now go select what the user requested. */ @@ -1330,48 +1389,12 @@ account = element->data; element = g_list_next(element); - path = gnc_tree_model_account_get_path_from_account (GNC_TREE_MODEL_ACCOUNT(model), account); - if (path == NULL) - { - /* - * Oops. Someone must have deleted this account and not cleaned - * up all references to it. - */ - continue; - } - - f_path = gtk_tree_model_filter_convert_child_path_to_path (GTK_TREE_MODEL_FILTER (f_model), - path); - gtk_tree_path_free(path); - if (f_path == NULL) - continue; - - s_path = gtk_tree_model_sort_convert_child_path_to_path (GTK_TREE_MODEL_SORT (s_model), - f_path); - gtk_tree_path_free(f_path); - if (s_path == NULL) - continue; - - /* gtk_tree_view requires that a row be visible before it can be selected */ - parent_path = gtk_tree_path_copy (s_path); - if (gtk_tree_path_up (parent_path)) - { - /* This function is misnamed. It expands the actual item - * specified, not the path to the item specified. I.E. It - * expands one level too many, thus the get of the parent. */ - gtk_tree_view_expand_to_path(GTK_TREE_VIEW(view), parent_path); - } - gtk_tree_path_free(parent_path); - - gtk_tree_selection_select_path (selection, s_path); - if (show_last && (element == NULL)) - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(view), s_path, NULL, FALSE, 0.0, 0.0); - gtk_tree_path_free(s_path); + select_account_helper (view, account, show_last && (element == NULL)); } } /* - * Selects all sub-accounts of an acccount. + * Selects all (visible) sub-accounts of an acccount. */ void gnc_tree_view_account_select_subaccounts (GncTreeViewAccount *view,