Compare commits
No commits in common. "cdb86652b98d0dd570da3f1a74bd5c99aec31ded" and "2cd100af7ac24f323c9a705e0a1033506c689fc0" have entirely different histories.
cdb86652b9
...
2cd100af7a
80
nncmpp.c
80
nncmpp.c
@ -1716,6 +1716,7 @@ app_process_action (enum action action)
|
|||||||
struct tab *tab = g.active_tab;
|
struct tab *tab = g.active_tab;
|
||||||
if (tab->on_action && tab->on_action (action))
|
if (tab->on_action && tab->on_action (action))
|
||||||
{
|
{
|
||||||
|
tab->item_mark = -1;
|
||||||
app_invalidate ();
|
app_invalidate ();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2218,56 +2219,40 @@ mpd_on_move_response (const struct mpd_response *response,
|
|||||||
print_error ("%s: %s", "command failed", response->message_text);
|
print_error ("%s: %s", "command failed", response->message_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
current_tab_move (int from, int to)
|
|
||||||
{
|
|
||||||
compact_map_t map;
|
|
||||||
const char *id;
|
|
||||||
if (!(map = item_list_get (&g.playlist, from))
|
|
||||||
|| !(id = compact_map_find (map, "id")))
|
|
||||||
return;
|
|
||||||
|
|
||||||
char *target_str = xstrdup_printf ("%d", to);
|
|
||||||
mpd_client_send_command (&g.client, "moveid", id, target_str, NULL);
|
|
||||||
free (target_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
current_tab_move_selection (int diff)
|
current_tab_move_selection (int diff)
|
||||||
{
|
{
|
||||||
static bool already_moving;
|
static bool already_moving;
|
||||||
if (already_moving || diff == 0)
|
if (already_moving)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// TODO: handle multiselect properly
|
||||||
|
struct tab *self = &g_current_tab;
|
||||||
struct mpd_client *c = &g.client;
|
struct mpd_client *c = &g.client;
|
||||||
if (c->state != MPD_CONNECTED)
|
compact_map_t map = item_list_get (&g.playlist, self->item_selected);
|
||||||
|
|
||||||
|
const char *id;
|
||||||
|
if (!map || !(id = compact_map_find (map, "id")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct tab *tab = &g_current_tab;
|
int target = self->item_selected + diff;
|
||||||
struct tab_range range = tab_selection_range (tab);
|
if (c->state != MPD_CONNECTED || target < 0)
|
||||||
if (range.from + diff < 0
|
|
||||||
|| range.upto + diff >= (int) tab->item_count)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mpd_client_list_begin (c);
|
char *target_str = xstrdup_printf ("%d", target);
|
||||||
if (diff < 0)
|
mpd_client_send_command (c, "moveid", id, target_str, NULL);
|
||||||
for (int i = range.from; i <= range.upto; i++)
|
free (target_str);
|
||||||
current_tab_move (i, i + diff);
|
|
||||||
else
|
|
||||||
for (int i = range.upto; i >= range.from; i--)
|
|
||||||
current_tab_move (i, i + diff);
|
|
||||||
mpd_client_list_end (c);
|
|
||||||
|
|
||||||
mpd_client_add_task (c, mpd_on_move_response, &already_moving);
|
mpd_client_add_task (c, mpd_on_move_response, &already_moving);
|
||||||
mpd_client_idle (c, 0);
|
mpd_client_idle (c, 0);
|
||||||
|
|
||||||
return already_moving = true;
|
return already_moving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
current_tab_on_action (enum action action)
|
current_tab_on_action (enum action action)
|
||||||
{
|
{
|
||||||
struct tab *tab = &g_current_tab;
|
struct tab *self = &g_current_tab;
|
||||||
compact_map_t map = item_list_get (&g.playlist, tab->item_selected);
|
compact_map_t map = item_list_get (&g.playlist, self->item_selected);
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
const char *id;
|
const char *id;
|
||||||
@ -2276,13 +2261,12 @@ current_tab_on_action (enum action action)
|
|||||||
case ACTION_MOVE_DOWN:
|
case ACTION_MOVE_DOWN:
|
||||||
return current_tab_move_selection (+1);
|
return current_tab_move_selection (+1);
|
||||||
case ACTION_CHOOSE:
|
case ACTION_CHOOSE:
|
||||||
tab->item_mark = -1;
|
|
||||||
return map && (id = compact_map_find (map, "id"))
|
return map && (id = compact_map_find (map, "id"))
|
||||||
&& MPD_SIMPLE ("playid", id);
|
&& MPD_SIMPLE ("playid", id);
|
||||||
case ACTION_DELETE:
|
case ACTION_DELETE:
|
||||||
{
|
{
|
||||||
struct mpd_client *c = &g.client;
|
struct mpd_client *c = &g.client;
|
||||||
struct tab_range range = tab_selection_range (tab);
|
struct tab_range range = tab_selection_range (self);
|
||||||
if (range.from < 0 || c->state != MPD_CONNECTED)
|
if (range.from < 0 || c->state != MPD_CONNECTED)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2495,7 +2479,6 @@ library_tab_change_level (const char *new_path)
|
|||||||
|
|
||||||
free (g_library_tab.super.header);
|
free (g_library_tab.super.header);
|
||||||
g_library_tab.super.header = NULL;
|
g_library_tab.super.header = NULL;
|
||||||
g_library_tab.super.item_mark = -1;
|
|
||||||
|
|
||||||
if (path->len)
|
if (path->len)
|
||||||
g_library_tab.super.header = xstrdup_printf ("/%s", path->str);
|
g_library_tab.super.header = xstrdup_printf ("/%s", path->str);
|
||||||
@ -2639,12 +2622,8 @@ static bool
|
|||||||
library_tab_on_action (enum action action)
|
library_tab_on_action (enum action action)
|
||||||
{
|
{
|
||||||
struct mpd_client *c = &g.client;
|
struct mpd_client *c = &g.client;
|
||||||
if (c->state != MPD_CONNECTED)
|
struct tab_range range = tab_selection_range (&g_library_tab.super);
|
||||||
return false;
|
if (range.from < 0 || c->state != MPD_CONNECTED)
|
||||||
|
|
||||||
struct tab *tab = &g_library_tab.super;
|
|
||||||
struct tab_range range = tab_selection_range (tab);
|
|
||||||
if (range.from < 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct library_tab_item x =
|
struct library_tab_item x =
|
||||||
@ -2665,7 +2644,6 @@ library_tab_on_action (enum action action)
|
|||||||
case LIBRARY_FILE: MPD_SIMPLE ("add", x.path); break;
|
case LIBRARY_FILE: MPD_SIMPLE ("add", x.path); break;
|
||||||
default: hard_assert (!"invalid item type");
|
default: hard_assert (!"invalid item type");
|
||||||
}
|
}
|
||||||
tab->item_mark = -1;
|
|
||||||
return true;
|
return true;
|
||||||
case ACTION_UP:
|
case ACTION_UP:
|
||||||
{
|
{
|
||||||
@ -2692,8 +2670,8 @@ library_tab_on_action (enum action action)
|
|||||||
free (fake_subdir);
|
free (fake_subdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (tab->header);
|
free (g_library_tab.super.header);
|
||||||
tab->header = xstrdup_printf ("Global search");
|
g_library_tab.super.header = xstrdup_printf ("Global search");
|
||||||
g_library_tab.searching = true;
|
g_library_tab.searching = true;
|
||||||
|
|
||||||
// Since we've already changed the header, empty the list,
|
// Since we've already changed the header, empty the list,
|
||||||
@ -2717,7 +2695,6 @@ library_tab_on_action (enum action action)
|
|||||||
if (x.type == LIBRARY_DIR || x.type == LIBRARY_FILE)
|
if (x.type == LIBRARY_DIR || x.type == LIBRARY_FILE)
|
||||||
MPD_SIMPLE ("add", x.path);
|
MPD_SIMPLE ("add", x.path);
|
||||||
}
|
}
|
||||||
tab->item_mark = -1;
|
|
||||||
return true;
|
return true;
|
||||||
case ACTION_MPD_REPLACE:
|
case ACTION_MPD_REPLACE:
|
||||||
if (!library_tab_is_range_playable (range))
|
if (!library_tab_is_range_playable (range))
|
||||||
@ -2742,7 +2719,6 @@ library_tab_on_action (enum action action)
|
|||||||
mpd_client_list_end (c);
|
mpd_client_list_end (c);
|
||||||
mpd_client_add_task (c, mpd_on_simple_response, NULL);
|
mpd_client_add_task (c, mpd_on_simple_response, NULL);
|
||||||
mpd_client_idle (c, 0);
|
mpd_client_idle (c, 0);
|
||||||
tab->item_mark = -1;
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -2985,12 +2961,12 @@ error:
|
|||||||
static bool
|
static bool
|
||||||
streams_tab_on_action (enum action action)
|
streams_tab_on_action (enum action action)
|
||||||
{
|
{
|
||||||
struct tab *tab = g.active_tab;
|
struct tab *self = g.active_tab;
|
||||||
if (tab->item_selected < 0 || !tab->item_count)
|
if (self->item_selected < 0 || !self->item_count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// For simplicity the URL is the string following the stream name
|
// For simplicity the URL is the string following the stream name
|
||||||
const char *uri = 1 + strchr (g.streams.vector[tab->item_selected], 0);
|
const char *uri = 1 + strchr (g.streams.vector[self->item_selected], 0);
|
||||||
|
|
||||||
struct error *e = NULL;
|
struct error *e = NULL;
|
||||||
switch (action)
|
switch (action)
|
||||||
@ -3117,13 +3093,13 @@ g_help_tab;
|
|||||||
static bool
|
static bool
|
||||||
help_tab_on_action (enum action action)
|
help_tab_on_action (enum action action)
|
||||||
{
|
{
|
||||||
struct tab *tab = &g_help_tab.super;
|
struct tab *self = g.active_tab;
|
||||||
if (tab->item_selected < 0
|
if (self->item_selected < 0
|
||||||
|| tab->item_selected >= (int) g_help_tab.actions_len
|
|| self->item_selected >= (int) g_help_tab.actions_len
|
||||||
|| action != ACTION_CHOOSE)
|
|| action != ACTION_CHOOSE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
action = g_help_tab.actions[tab->item_selected];
|
action = g_help_tab.actions[self->item_selected];
|
||||||
return action != ACTION_NONE
|
return action != ACTION_NONE
|
||||||
&& action != ACTION_CHOOSE // avoid recursion
|
&& action != ACTION_CHOOSE // avoid recursion
|
||||||
&& app_process_action (action);
|
&& app_process_action (action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user