From: Jeffrey Middleton Date: Wed, 25 Mar 2009 04:15:26 +0000 (-0500) Subject: screen_browser: select/add for visual selection X-Git-Tag: release-0.14~54 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f6d4abc72b4b62d5bab4936060c23612903a1fb3;p=ncmpc.git screen_browser: select/add for visual selection The select (toggle in playlist) and add (append to playlist) commands now work for visual selections in browser screens. The status output should eventually be reconsidered - a message is wastefully printed for each item before it is overwritten by one displaying a count of items added. The "enter" (CMD_PLAY) command has been disabled for multiple selection for now; this is better than acting just on the item at the end of the selection range. Eventually it should do something fancy like appending all selected items (directory, song, or playlist) then playing the first song of the first item. --- diff --git a/src/screen_browser.c b/src/screen_browser.c index b616c58..c946c9d 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -279,13 +279,23 @@ browser_get_selected(const struct screen_browser *browser) return filelist_get(browser->filelist, browser->lw->selected); } +static struct filelist_entry * +browser_get_index(const struct screen_browser *browser, unsigned i) +{ + if (browser->filelist == NULL || + i >= filelist_length(browser->filelist)) + return NULL; + + return filelist_get(browser->filelist, i); +} + static bool browser_handle_enter(struct screen_browser *browser, mpdclient_t *c) { struct filelist_entry *entry = browser_get_selected(browser); mpd_InfoEntity *entity; - if( entry==NULL ) + if( entry==NULL || browser->lw->selected_start < browser->lw->selected_end) return false; entity = entry->entity; @@ -361,23 +371,49 @@ browser_select_entry(mpdclient_t *c, filelist_entry_t *entry, static bool browser_handle_select(struct screen_browser *browser, mpdclient_t *c) { - struct filelist_entry *entry = browser_get_selected(browser); + struct filelist_entry *entry; + + if (browser->lw->visual_selection) { + for (unsigned i = browser->lw->selected_start; + i <= browser->lw->selected_end; i++) { + entry = browser_get_index(browser, i); - if (entry == NULL || entry->entity == NULL) + if (entry != NULL && entry->entity != NULL) + browser_select_entry(c, entry, TRUE); + } return false; + } else { + entry = browser_get_selected(browser); - return browser_select_entry(c, entry, TRUE); + if (entry == NULL || entry->entity == NULL) + return false; + + return browser_select_entry(c, entry, TRUE); + } } static bool browser_handle_add(struct screen_browser *browser, mpdclient_t *c) { - struct filelist_entry *entry = browser_get_selected(browser); + struct filelist_entry *entry; + + if (browser->lw->visual_selection) { + for (unsigned i = browser->lw->selected_start; + i <= browser->lw->selected_end; i++) { + entry = browser_get_index(browser, i); - if (entry == NULL || entry->entity == NULL) + if (entry != NULL && entry->entity != NULL) + browser_select_entry(c, entry, FALSE); + } return false; + } else { + entry = browser_get_selected(browser); - return browser_select_entry(c, entry, FALSE); + if (entry == NULL || entry->entity == NULL) + return false; + + return browser_select_entry(c, entry, FALSE); + } } static void