aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-05 22:19:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-05 22:19:39 +0200
commitd0c0af0e3874c0bcaffebb61b7bce348b5576e25 (patch)
treeba7a8528dada2333b75c974cfa8477ebf2b9a2b2
parentc5fcc1c8c1fc0fb42704de8cff372754b133ed67 (diff)
downloadnncmpp-d0c0af0e3874c0bcaffebb61b7bce348b5576e25.tar.gz
nncmpp-d0c0af0e3874c0bcaffebb61b7bce348b5576e25.tar.xz
nncmpp-d0c0af0e3874c0bcaffebb61b7bce348b5576e25.zip
Allow modifying playlist order
-rw-r--r--nncmpp.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/nncmpp.c b/nncmpp.c
index c459949..d1e5b8d 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -1516,6 +1516,8 @@ app_goto_tab (int tab_index)
\
XX( SCROLL_UP, "Scroll up" ) \
XX( SCROLL_DOWN, "Scroll down" ) \
+ XX( MOVE_UP, "Move selection up" ) \
+ XX( MOVE_DOWN, "Move selection down" ) \
\
XX( GOTO_TOP, "Go to the top" ) \
XX( GOTO_BOTTOM, "Go to the bottom" ) \
@@ -1817,6 +1819,8 @@ g_default_bindings[] =
{ "End", ACTION_GOTO_BOTTOM, {}},
{ "M-<", ACTION_GOTO_TOP, {}},
{ "M->", ACTION_GOTO_BOTTOM, {}},
+ { "S-Up", ACTION_MOVE_UP, {}},
+ { "S-Down", ACTION_MOVE_DOWN, {}},
{ "Up", ACTION_GOTO_ITEM_PREVIOUS, {}},
{ "Down", ACTION_GOTO_ITEM_NEXT, {}},
{ "k", ACTION_GOTO_ITEM_PREVIOUS, {}},
@@ -1930,6 +1934,27 @@ current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer,
}
static bool
+current_tab_move_song (const char *id, int diff)
+{
+ struct mpd_client *c = &g.client;
+ int target = g_current_tab.item_selected + diff;
+ if (c->state != MPD_CONNECTED || target < 0)
+ return false;
+
+ char *target_str = xstrdup_printf ("%d", target);
+ mpd_client_send_command (c, "moveid", id, target_str, NULL);
+ free (target_str);
+ mpd_client_add_task (c, mpd_on_simple_response, NULL);
+ mpd_client_idle (c, 0);
+
+ // XXX: this behaves a bit erratically, as even if we waited for
+ // a confirmation from the daemon, it would precede the playlist update
+ g_current_tab.item_selected = target;
+ app_move_selection (0);
+ return true;
+}
+
+static bool
current_tab_on_action (enum action action)
{
struct tab *self = g.active_tab;
@@ -1939,10 +1964,10 @@ current_tab_on_action (enum action action)
if (!map || !(id = compact_map_find (map, "id")))
return false;
- // TODO: add actions to move the current selection up or down with Shift,
- // with multiple items we need to use all number indexes, but "moveid"
switch (action)
{
+ case ACTION_MOVE_UP: 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);
default: