Code

screen_search: moved code to screen_search_reload()
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 18:13:16 +0000 (20:13 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 18:13:16 +0000 (20:13 +0200)
This function creates an empty list when the search query has failed.
It is now used on CMD_SCREEN_UPDATE.

src/screen_search.c

index 2dd911d09b3a8cc3c9cccb5518c62176889845a8..9742410d9b610277a2b0a6c97a64694f46b53a81 100644 (file)
@@ -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;