Code

screen_browser: select/add for visual selection
authorJeffrey Middleton <jefromi@gmail.com>
Wed, 25 Mar 2009 04:15:26 +0000 (23:15 -0500)
committerJeffrey Middleton <jefromi@gmail.com>
Wed, 25 Mar 2009 04:22:16 +0000 (23:22 -0500)
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.

src/screen_browser.c

index b616c58ed3925a40d03bf021fbe0c7bfe6eba6bc..c946c9d0d7a3d2c9888a4168f985da46a8015088 100644 (file)
@@ -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