From ffee3c4bd98a01443799aa3f2d7dc4e0a84f28d9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 3 Oct 2009 20:13:16 +0200 Subject: [PATCH] screen_search: moved code to screen_search_reload() This function creates an empty list when the search query has failed. It is now used on CMD_SCREEN_UPDATE. --- src/screen_search.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/screen_search.c b/src/screen_search.c index 2dd911d..9742410 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -321,6 +321,26 @@ do_search(struct mpdclient *c, char *query) return fl; } +static void +screen_search_reload(struct mpdclient *c) +{ + if (pattern == NULL) + return; + + if (browser.filelist != NULL) { + filelist_free(browser.filelist); + browser.filelist = NULL; + } + + browser.filelist = do_search(c, pattern); + if (browser.filelist == NULL) + browser.filelist = filelist_new(); + + screen_browser_sync_highlights(browser.filelist, &c->playlist); + list_window_check_selected(browser.lw, + filelist_length(browser.filelist)); +} + static void search_new(struct mpdclient *c) { @@ -340,17 +360,7 @@ search_new(struct mpdclient *c) return; } - if (browser.filelist != NULL) { - filelist_free(browser.filelist); - browser.filelist = NULL; - } - - browser.filelist = do_search(c, pattern); - if (browser.filelist == NULL) - browser.filelist = filelist_new(); - - screen_browser_sync_highlights(browser.filelist, &c->playlist); - list_window_check_selected(browser.lw, filelist_length(browser.filelist)); + screen_search_reload(c); } static void @@ -443,12 +453,7 @@ screen_search_cmd(struct mpdclient *c, command_t cmd) _(mode[options.search_mode].label)); /* continue and update... */ case CMD_SCREEN_UPDATE: - if (pattern) { - search_clear(false); - browser.filelist = do_search(c, pattern); - screen_browser_sync_highlights(browser.filelist, - &c->playlist); - } + screen_search_reload(c); search_repaint(); return true; -- 2.30.2