Compare commits

..

2 Commits

Author SHA1 Message Date
a6543a796d
Implement multiselect for deletion in Current tab 2018-10-21 05:11:20 +02:00
1349e39941
Add keyboard shortcut d for deletion
As in vi(1).
2018-10-21 05:10:04 +02:00

View File

@ -2002,6 +2002,7 @@ g_normal_defaults[] =
// Not sure how to set these up, they're pretty arbitrary so far // Not sure how to set these up, they're pretty arbitrary so far
{ "Enter", ACTION_CHOOSE }, { "Enter", ACTION_CHOOSE },
{ "Delete", ACTION_DELETE }, { "Delete", ACTION_DELETE },
{ "d", ACTION_DELETE },
{ "Backspace", ACTION_UP }, { "Backspace", ACTION_UP },
{ "v", ACTION_MULTISELECT }, { "v", ACTION_MULTISELECT },
{ "/", ACTION_MPD_SEARCH }, { "/", ACTION_MPD_SEARCH },
@ -2219,6 +2220,7 @@ static bool
current_tab_on_action (enum action action) current_tab_on_action (enum action action)
{ {
struct tab *self = g.active_tab; struct tab *self = g.active_tab;
struct tab_range range = tab_selection_range (self);
compact_map_t map = item_list_get (&g.playlist, self->item_selected); compact_map_t map = item_list_get (&g.playlist, self->item_selected);
const char *id; const char *id;
@ -2227,10 +2229,31 @@ current_tab_on_action (enum action action)
switch (action) switch (action)
{ {
// TODO: make this block more than just multiselect-tolerant
case ACTION_MOVE_UP: return current_tab_move_song (id, -1); case ACTION_MOVE_UP: return current_tab_move_song (id, -1);
case ACTION_MOVE_DOWN: return current_tab_move_song (id, 1); case ACTION_MOVE_DOWN: return current_tab_move_song (id, 1);
case ACTION_CHOOSE: return MPD_SIMPLE ("playid", id);
case ACTION_DELETE: return MPD_SIMPLE ("deleteid", id); case ACTION_CHOOSE:
return MPD_SIMPLE ("playid", id);
case ACTION_DELETE:
{
struct mpd_client *c = &g.client;
if (range.from < 0 || c->state != MPD_CONNECTED)
return false;
mpd_client_list_begin (c);
for (int i = range.from; i <= range.upto; i++)
{
if ((map = item_list_get (&g.playlist, i))
&& (id = compact_map_find (map, "id")))
mpd_client_send_command (c, "deleteid", id, NULL);
}
mpd_client_list_end (c);
mpd_client_add_task (c, mpd_on_simple_response, NULL);
mpd_client_idle (c, 0);
return true;
}
default: default:
break; break;
} }
@ -2249,7 +2272,7 @@ current_tab_init (void)
{ {
struct tab *super = &g_current_tab; struct tab *super = &g_current_tab;
tab_init (super, "Current"); tab_init (super, "Current");
// TODO: implement multiselect, set can_multiselect to true super->can_multiselect = true;
super->on_action = current_tab_on_action; super->on_action = current_tab_on_action;
super->on_item_draw = current_tab_on_item_draw; super->on_item_draw = current_tab_on_item_draw;
return super; return super;