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:
parent
306fef2b37
commit
edc1d31d2e
11
gui/filter.c
11
gui/filter.c
|
@ -131,3 +131,14 @@ unsigned int gui_filter_path_get_index(GtkTreePath *path)
|
||||||
gtk_tree_path_free(real);
|
gtk_tree_path_free(real);
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|
10
gui/view.c
10
gui/view.c
|
@ -408,20 +408,16 @@ void gui_view_scroll()
|
||||||
{
|
{
|
||||||
struct playlist *playlist = gui_model_get_playlist();
|
struct playlist *playlist = gui_model_get_playlist();
|
||||||
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
|
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)
|
if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1);
|
path = gui_filter_path_from_index(queue->q_cur.it_pos);
|
||||||
path = gtk_tree_model_filter_convert_child_path_to_path(
|
|
||||||
gui_filter_get(), real);
|
|
||||||
if (!path)
|
if (!path)
|
||||||
goto out;
|
return;
|
||||||
|
|
||||||
gtk_tree_view_set_cursor(view_treeview, path, NULL, false);
|
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_view_scroll_to_cell(view_treeview, path, NULL, TRUE, 0.5, 0.5);
|
||||||
gtk_tree_path_free(path);
|
gtk_tree_path_free(path);
|
||||||
out:
|
|
||||||
gtk_tree_path_free(real);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ struct track *gui_filter_path_get_track(GtkTreePath *);
|
||||||
/* Called to convert a filter model path into a queue index. */
|
/* Called to convert a filter model path into a queue index. */
|
||||||
unsigned int gui_filter_path_get_index(GtkTreePath *);
|
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. */
|
/* Called to access the filter search-entry. */
|
||||||
static inline GtkSearchEntry *gui_filter_search(void)
|
static inline GtkSearchEntry *gui_filter_search(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,15 +62,21 @@ void test_filter()
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
|
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++) {
|
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);
|
track = gui_filter_path_get_track(path);
|
||||||
g_assert_nonnull(track);
|
g_assert_nonnull(track);
|
||||||
g_assert_cmpuint(track->tr_track, ==, i + 1);
|
g_assert_cmpuint(track->tr_track, ==, i + 1);
|
||||||
g_assert_cmpuint(gui_filter_path_get_index(path), ==, i);
|
gtk_tree_path_free(path);
|
||||||
gtk_tree_path_next(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));
|
g_assert_null(gui_filter_path_get_track(path));
|
||||||
gtk_tree_path_free(path);
|
gtk_tree_path_free(path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue