From 45d2422be3d625e366a9bfa2ac41b173b410ac52 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 28 Aug 2018 08:57:12 -0400 Subject: [PATCH] gui: Refilter playlists when adding tracks I was running into a situation where new tracks added to a playlist were showing up even if they didn't match the current filter text. Let's fix this by refiltering the current playlist when new tracks are added to it. Fixes #114: New tracks added to filtered view Signed-off-by: Anna Schumaker --- gui/filter.c | 6 ++++++ gui/playlist.c | 1 + include/gui/filter.h | 3 +++ 3 files changed, 10 insertions(+) diff --git a/gui/filter.c b/gui/filter.c index 9a089cf1..df486d32 100644 --- a/gui/filter.c +++ b/gui/filter.c @@ -134,3 +134,9 @@ GtkTreePath *gui_filter_path_from_index(unsigned int index) gtk_tree_path_free(real); return path; } + +void gui_filter_refilter(struct playlist *playlist) +{ + if (!playlist || playlist == gui_model_get_playlist()) + gtk_tree_model_filter_refilter(gui_filter_get()); +} diff --git a/gui/playlist.c b/gui/playlist.c index 51315dd7..c7e2af37 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -37,6 +37,7 @@ static void __gui_playlist_alloc(struct playlist *playlist) static void __gui_playlist_added(struct playlist *playlist, struct track *track) { gui_model_add(playlist, track); + gui_filter_refilter(playlist); __gui_playlist_update_size(playlist); } diff --git a/include/gui/filter.h b/include/gui/filter.h index f7722085..2f9f38a1 100644 --- a/include/gui/filter.h +++ b/include/gui/filter.h @@ -38,6 +38,9 @@ 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 refilter a playlist. Pass NULL to refilter the current playlist */ +void gui_filter_refilter(struct playlist *); + /* Called to access the filter search-entry. */ static inline GtkSearchEntry *gui_filter_search(void) {