From f328b1686dbb1b7daa1c259fbbb27401263790b9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 22 Jan 2016 14:16:51 -0500 Subject: [PATCH] gui/view: Scroll to the current queue's iterator position Signed-off-by: Anna Schumaker --- gui/audio.c | 2 ++ gui/queue.c | 1 + gui/view.c | 23 +++++++++++++++++++++++ include/gui/view.h | 3 +++ 4 files changed, 29 insertions(+) diff --git a/gui/audio.c b/gui/audio.c index 3758dd6b..34216593 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -6,6 +6,7 @@ #include #include #include +#include static inline void __audio_set_label(const gchar *label, const gchar *size, @@ -35,6 +36,7 @@ static void __audio_load(struct track *track) playlist_has(PL_HIDDEN, track)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")), playlist_has(PL_FAVORITED, track)); + gui_view_scroll(); } static void __audio_change_state(GstState state) diff --git a/gui/queue.c b/gui/queue.c index 17624336..83c86470 100644 --- a/gui/queue.c +++ b/gui/queue.c @@ -82,6 +82,7 @@ void __queue_filter(GtkSearchEntry *entry, gpointer data) if (strlen(text) > 0) filter_search(text, &gq_queue->gq_visible); gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(gq_queue->gq_filter)); + gui_view_scroll(); } struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text, diff --git a/gui/view.c b/gui/view.c index 5e0bef43..7b0d33b7 100644 --- a/gui/view.c +++ b/gui/view.c @@ -341,4 +341,27 @@ void gui_view_set_model(GtkTreeModelFilter *filter) view_sort_count = 0; __view_display_sorting(""); __view_set_sort_indicators(); + + gui_view_scroll(); +} + +void gui_view_scroll() +{ + struct queue *queue = __view_filter_get_queue(); + GtkTreePath *real, *path; + + if (!queue || (int)queue->q_cur.it_pos < 0) + return; + + real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1); + path = gtk_tree_model_filter_convert_child_path_to_path(view_filter, real); + + if (path) { + gtk_tree_view_scroll_to_cell(view_treeview, path, + NULL, TRUE, 0.5, 0.5); + gtk_tree_view_set_cursor(view_treeview, path, NULL, false); + gtk_tree_path_free(path); + } + + gtk_tree_path_free(real); } diff --git a/include/gui/view.h b/include/gui/view.h index 30d3543c..6d8255b6 100644 --- a/include/gui/view.h +++ b/include/gui/view.h @@ -7,6 +7,9 @@ /* Called to initialize structures needed by the treeview. */ void gui_view_init(); +/* Called to scroll the GUI treeview to the queue's current position. */ +void gui_view_scroll(); + /* Called to set the currently displayed model. */ void gui_view_set_model(GtkTreeModelFilter *);