Skip to content

Commit

Permalink
Add functions to gnc-query-view to do scrolling to selection
Browse files Browse the repository at this point in the history
Add the ability when a row is selected to scroll to that row so it is
always visible when reordering the list.

The first function, gnc_query_use_scroll_to_selection can enable or
disable this for the query view, the default is off.

Two functions do the scrolling, gnc_query_scroll_to_selection and
gnc_query_force_scroll_to_selection with the first one respecting the
value of use scrolling to selection whereas the second will always do
it.
  • Loading branch information
Bob-IT committed Feb 8, 2022
1 parent c054b97 commit a9faf86
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
54 changes: 54 additions & 0 deletions gnucash/gnome-utils/gnc-query-view.c
Expand Up @@ -200,6 +200,8 @@ gnc_query_view_init (GNCQueryView *qview)
qview->num_columns = 0;
qview->column_params = NULL;

qview->use_scroll_to_selection = FALSE;

qview->sort_column = 0;
qview->increasing = FALSE;

Expand Down Expand Up @@ -604,6 +606,57 @@ gnc_query_view_get_selected_entry_list (GNCQueryView *qview)
return acc_entries.entries;
}

void
gnc_query_use_scroll_to_selection (GNCQueryView *qview, gboolean scroll)
{
g_return_if_fail (qview != NULL);
g_return_if_fail (GNC_IS_QUERY_VIEW(qview));

qview->use_scroll_to_selection = scroll;
}

static void
scroll_to_selection (GNCQueryView *qview, gboolean override_scroll)
{
GtkTreeSelection *selection;
GList *path_list, *node;

if (!qview->use_scroll_to_selection && !override_scroll)
return;

selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));

/* Ensure last selected item, if any, can be seen */
path_list = gtk_tree_selection_get_selected_rows (selection, NULL);
node = g_list_last (path_list);

if (node)
{
GtkTreePath *tree_path = node->data;
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(qview),
tree_path, NULL, FALSE, 0.0, 0.0);
}
g_list_free_full (path_list, (GDestroyNotify) gtk_tree_path_free);
}

void
gnc_query_scroll_to_selection (GNCQueryView *qview)
{
g_return_if_fail (qview != NULL);
g_return_if_fail (GNC_IS_QUERY_VIEW(qview));

scroll_to_selection (qview, FALSE);
}

void
gnc_query_force_scroll_to_selection (GNCQueryView *qview)
{
g_return_if_fail (qview != NULL);
g_return_if_fail (GNC_IS_QUERY_VIEW(qview));

scroll_to_selection (qview, TRUE);
}

static void
gnc_query_view_refresh_selected (GNCQueryView *qview, GList *old_entry)
{
Expand Down Expand Up @@ -641,6 +694,7 @@ gnc_query_view_refresh_selected (GNCQueryView *qview, GList *old_entry)
valid = gtk_tree_model_iter_next (model, &iter);
}
}
gnc_query_scroll_to_selection (qview);
}
}

Expand Down
7 changes: 7 additions & 0 deletions gnucash/gnome-utils/gnc-query-view.h
Expand Up @@ -52,6 +52,7 @@ struct _GNCQueryView
/* Select information */
gint toggled_row;
gint toggled_column;
gboolean use_scroll_to_selection;

/* Column information */
gint num_columns;
Expand Down Expand Up @@ -118,6 +119,12 @@ gboolean gnc_query_view_item_in_view (GNCQueryView *qview, gpointer item);

void gnc_query_sort_order (GNCQueryView *qview, gint column, GtkSortType order);

void gnc_query_scroll_to_selection (GNCQueryView *qview);

void gnc_query_force_scroll_to_selection (GNCQueryView *qview);

void gnc_query_use_scroll_to_selection (GNCQueryView *qview, gboolean scroll);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down

0 comments on commit a9faf86

Please sign in to comment.