gui/filter: Add a function for getting filter treepaths from index

This keeps the treepath conversions contained to the filter code when
finding paths to scroll to.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-24 08:02:59 -04:00
parent 32d712c213
commit ac3c316d9a
4 changed files with 27 additions and 11 deletions

View File

@ -131,3 +131,14 @@ unsigned int gui_filter_path_get_index(GtkTreePath *path)
gtk_tree_path_free(real);
return ret;
}
GtkTreePath *gui_filter_path_from_index(unsigned int index)
{
GtkTreePath *real, *path;
real = gtk_tree_path_new_from_indices(index, -1);
path = gtk_tree_model_filter_convert_child_path_to_path(filter_model,
real);
gtk_tree_path_free(real);
return path;
}

View File

@ -408,20 +408,16 @@ void gui_view_scroll()
{
struct playlist *playlist = gui_model_get_playlist();
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
GtkTreePath *real, *path;
GtkTreePath *path;
if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll)
return;
real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1);
path = gtk_tree_model_filter_convert_child_path_to_path(
gui_filter_get(), real);
path = gui_filter_path_from_index(queue->q_cur.it_pos);
if (!path)
goto out;
return;
gtk_tree_view_set_cursor(view_treeview, path, NULL, false);
gtk_tree_view_scroll_to_cell(view_treeview, path, NULL, TRUE, 0.5, 0.5);
gtk_tree_path_free(path);
out:
gtk_tree_path_free(real);
}

View File

@ -35,6 +35,9 @@ struct track *gui_filter_path_get_track(GtkTreePath *);
/* Called to convert a filter model path into a queue index. */
unsigned int gui_filter_path_get_index(GtkTreePath *);
/* Called to convert a playlist iterator index into a path. */
GtkTreePath *gui_filter_path_from_index(unsigned int);
/* Called to access the filter search-entry. */
static inline GtkSearchEntry *gui_filter_search(void)
{

View File

@ -62,15 +62,21 @@ void test_filter()
while (idle_run_task()) {};
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
path = gtk_tree_model_get_path(model, &iter);
for (i = 0; i < 13; i++) {
path = gui_filter_path_from_index(i);
g_assert_nonnull(path);
g_assert_cmpuint(gui_filter_path_get_index(path), ==, i);
track = gui_filter_path_get_track(path);
g_assert_nonnull(track);
g_assert_cmpuint(track->tr_track, ==, i + 1);
g_assert_cmpuint(gui_filter_path_get_index(path), ==, i);
gtk_tree_path_next(path);
gtk_tree_path_free(path);
}
path = gui_filter_path_from_index(i);
g_assert_null(path);
path = gui_filter_path_from_index(12);
gtk_tree_path_next(path);
g_assert_null(gui_filter_path_get_track(path));
gtk_tree_path_free(path);