Rename "user actions" to "actions"

This commit is contained in:
Přemysl Eric Janouch 2016-10-12 16:06:23 +02:00
parent 0999159b3d
commit e92a23d679
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 83 additions and 83 deletions

166
nncmpp.c
View File

@ -538,10 +538,10 @@ item_list_resize (struct item_list *self, size_t len)
struct tab; struct tab;
struct row_buffer; struct row_buffer;
enum user_action; enum action;
/// Try to handle an action in the tab /// Try to handle an action in the tab
typedef bool (*tab_action_fn) (enum user_action action); typedef bool (*tab_action_fn) (enum action action);
/// Draw an item to the screen using the row buffer API /// Draw an item to the screen using the row buffer API
typedef void (*tab_item_draw_fn) typedef void (*tab_item_draw_fn)
@ -1590,7 +1590,7 @@ app_goto_tab (int tab_index)
// --- User input handling ----------------------------------------------------- // --- User input handling -----------------------------------------------------
#define USER_ACTIONS(XX) \ #define ACTIONS(XX) \
XX( NONE, "Do nothing" ) \ XX( NONE, "Do nothing" ) \
\ \
XX( QUIT, "Quit application" ) \ XX( QUIT, "Quit application" ) \
@ -1621,23 +1621,23 @@ app_goto_tab (int tab_index)
XX( GOTO_PAGE_PREVIOUS, "Go to the previous page" ) \ XX( GOTO_PAGE_PREVIOUS, "Go to the previous page" ) \
XX( GOTO_PAGE_NEXT, "Go to the next page" ) XX( GOTO_PAGE_NEXT, "Go to the next page" )
enum user_action enum action
{ {
#define XX(name, description) USER_ACTION_ ## name, #define XX(name, description) ACTION_ ## name,
USER_ACTIONS (XX) ACTIONS (XX)
#undef XX #undef XX
USER_ACTION_COUNT ACTION_COUNT
}; };
static struct user_action_info static struct action_info
{ {
const char *name; ///< Name for user bindings const char *name; ///< Name for user bindings
const char *description; ///< Human-readable description const char *description; ///< Human-readable description
} }
g_user_actions[] = g_actions[] =
{ {
#define XX(name, description) { #name, description }, #define XX(name, description) { #name, description },
USER_ACTIONS (XX) ACTIONS (XX)
#undef XX #undef XX
}; };
@ -1653,7 +1653,7 @@ g_user_actions[] =
} }
static bool static bool
app_process_user_action (enum user_action action) app_process_action (enum action action)
{ {
// First let the tab try to handle this // First let the tab try to handle this
struct tab *tab = g_ctx.active_tab; struct tab *tab = g_ctx.active_tab;
@ -1663,39 +1663,39 @@ app_process_user_action (enum user_action action)
struct mpd_client *c = &g_ctx.client; struct mpd_client *c = &g_ctx.client;
switch (action) switch (action)
{ {
case USER_ACTION_QUIT: case ACTION_QUIT:
app_quit (); app_quit ();
break; break;
case USER_ACTION_REDRAW: case ACTION_REDRAW:
clear (); clear ();
app_invalidate (); app_invalidate ();
break; break;
case USER_ACTION_LAST_TAB: case ACTION_LAST_TAB:
if (!g_ctx.last_tab) if (!g_ctx.last_tab)
return false; return false;
app_switch_tab (g_ctx.last_tab); app_switch_tab (g_ctx.last_tab);
break; break;
case USER_ACTION_HELP_TAB: case ACTION_HELP_TAB:
app_switch_tab (g_ctx.help_tab); app_switch_tab (g_ctx.help_tab);
break; break;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case USER_ACTION_MPD_PREVIOUS: case ACTION_MPD_PREVIOUS:
MPD_SIMPLE ("previous") MPD_SIMPLE ("previous")
break; break;
case USER_ACTION_MPD_TOGGLE: case ACTION_MPD_TOGGLE:
if (g_ctx.state == PLAYER_PLAYING) MPD_SIMPLE ("pause", "1") if (g_ctx.state == PLAYER_PLAYING) MPD_SIMPLE ("pause", "1")
else if (g_ctx.state == PLAYER_PAUSED) MPD_SIMPLE ("pause", "0") else if (g_ctx.state == PLAYER_PAUSED) MPD_SIMPLE ("pause", "0")
else MPD_SIMPLE ("play") else MPD_SIMPLE ("play")
break; break;
case USER_ACTION_MPD_STOP: case ACTION_MPD_STOP:
MPD_SIMPLE ("stop") MPD_SIMPLE ("stop")
break; break;
case USER_ACTION_MPD_NEXT: case ACTION_MPD_NEXT:
MPD_SIMPLE ("next") MPD_SIMPLE ("next")
break; break;
case USER_ACTION_MPD_VOLUME_UP: case ACTION_MPD_VOLUME_UP:
if (g_ctx.volume >= 0) if (g_ctx.volume >= 0)
{ {
char *volume = xstrdup_printf ("%d", MIN (100, g_ctx.volume + 10)); char *volume = xstrdup_printf ("%d", MIN (100, g_ctx.volume + 10));
@ -1703,7 +1703,7 @@ app_process_user_action (enum user_action action)
free (volume); free (volume);
} }
break; break;
case USER_ACTION_MPD_VOLUME_DOWN: case ACTION_MPD_VOLUME_DOWN:
if (g_ctx.volume >= 0) if (g_ctx.volume >= 0)
{ {
char *volume = xstrdup_printf ("%d", MAX (0, g_ctx.volume - 10)); char *volume = xstrdup_printf ("%d", MAX (0, g_ctx.volume - 10));
@ -1721,14 +1721,14 @@ app_process_user_action (enum user_action action)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX: these should rather be parametrized // XXX: these should rather be parametrized
case USER_ACTION_SCROLL_UP: case ACTION_SCROLL_UP:
app_scroll (-3); app_scroll (-3);
break; break;
case USER_ACTION_SCROLL_DOWN: case ACTION_SCROLL_DOWN:
app_scroll (3); app_scroll (3);
break; break;
case USER_ACTION_GOTO_TOP: case ACTION_GOTO_TOP:
if (tab->item_count) if (tab->item_count)
{ {
g_ctx.active_tab->item_selected = 0; g_ctx.active_tab->item_selected = 0;
@ -1736,7 +1736,7 @@ app_process_user_action (enum user_action action)
app_invalidate (); app_invalidate ();
} }
break; break;
case USER_ACTION_GOTO_BOTTOM: case ACTION_GOTO_BOTTOM:
if (tab->item_count) if (tab->item_count)
{ {
g_ctx.active_tab->item_selected = g_ctx.active_tab->item_selected =
@ -1746,25 +1746,25 @@ app_process_user_action (enum user_action action)
} }
break; break;
case USER_ACTION_GOTO_ITEM_PREVIOUS: case ACTION_GOTO_ITEM_PREVIOUS:
app_move_selection (-1); app_move_selection (-1);
break; break;
case USER_ACTION_GOTO_ITEM_NEXT: case ACTION_GOTO_ITEM_NEXT:
app_move_selection (1); app_move_selection (1);
break; break;
case USER_ACTION_GOTO_PAGE_PREVIOUS: case ACTION_GOTO_PAGE_PREVIOUS:
app_scroll ((int) g_ctx.header_height - LINES); app_scroll ((int) g_ctx.header_height - LINES);
app_move_selection ((int) g_ctx.header_height - LINES); app_move_selection ((int) g_ctx.header_height - LINES);
break; break;
case USER_ACTION_GOTO_PAGE_NEXT: case ACTION_GOTO_PAGE_NEXT:
app_scroll (LINES - (int) g_ctx.header_height); app_scroll (LINES - (int) g_ctx.header_height);
app_move_selection (LINES - (int) g_ctx.header_height); app_move_selection (LINES - (int) g_ctx.header_height);
break; break;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case USER_ACTION_NONE: case ACTION_NONE:
break; break;
default: default:
beep (); beep ();
@ -1782,14 +1782,14 @@ app_process_left_mouse_click (int line, int column)
{ {
// XXX: there could be a push_widget(buf, text, attrs, handler) // XXX: there could be a push_widget(buf, text, attrs, handler)
// function to help with this but it might not be worth it // function to help with this but it might not be worth it
enum user_action action = USER_ACTION_NONE; enum action action = ACTION_NONE;
if (column >= 0 && column <= 1) action = USER_ACTION_MPD_PREVIOUS; if (column >= 0 && column <= 1) action = ACTION_MPD_PREVIOUS;
if (column >= 3 && column <= 4) action = USER_ACTION_MPD_TOGGLE; if (column >= 3 && column <= 4) action = ACTION_MPD_TOGGLE;
if (column >= 6 && column <= 7) action = USER_ACTION_MPD_STOP; if (column >= 6 && column <= 7) action = ACTION_MPD_STOP;
if (column >= 9 && column <= 10) action = USER_ACTION_MPD_NEXT; if (column >= 9 && column <= 10) action = ACTION_MPD_NEXT;
if (action) if (action)
return app_process_user_action (action); return app_process_action (action);
int gauge_offset = column - g_ctx.gauge_offset; int gauge_offset = column - g_ctx.gauge_offset;
if (g_ctx.gauge_offset < 0 if (g_ctx.gauge_offset < 0
@ -1863,9 +1863,9 @@ app_process_mouse (termo_key_t *event)
if (button == 1) if (button == 1)
return app_process_left_mouse_click (line, column); return app_process_left_mouse_click (line, column);
else if (button == 4) else if (button == 4)
return app_process_user_action (USER_ACTION_SCROLL_UP); return app_process_action (ACTION_SCROLL_UP);
else if (button == 5) else if (button == 5)
return app_process_user_action (USER_ACTION_SCROLL_DOWN); return app_process_action (ACTION_SCROLL_DOWN);
return false; return false;
} }
@ -1874,45 +1874,45 @@ app_process_mouse (termo_key_t *event)
static struct binding static struct binding
{ {
const char *key; ///< Key definition const char *key; ///< Key definition
enum user_action action; ///< Action to take enum action action; ///< Action to take
} }
g_default_bindings[] = g_default_bindings[] =
{ {
{ "Escape", USER_ACTION_QUIT }, { "Escape", ACTION_QUIT },
{ "q", USER_ACTION_QUIT }, { "q", ACTION_QUIT },
{ "C-l", USER_ACTION_REDRAW }, { "C-l", ACTION_REDRAW },
{ "M-Tab", USER_ACTION_LAST_TAB }, { "M-Tab", ACTION_LAST_TAB },
{ "F1", USER_ACTION_HELP_TAB }, { "F1", ACTION_HELP_TAB },
{ "Home", USER_ACTION_GOTO_TOP }, { "Home", ACTION_GOTO_TOP },
{ "End", USER_ACTION_GOTO_BOTTOM }, { "End", ACTION_GOTO_BOTTOM },
{ "M-<", USER_ACTION_GOTO_TOP }, { "M-<", ACTION_GOTO_TOP },
{ "M->", USER_ACTION_GOTO_BOTTOM }, { "M->", ACTION_GOTO_BOTTOM },
{ "Up", USER_ACTION_GOTO_ITEM_PREVIOUS }, { "Up", ACTION_GOTO_ITEM_PREVIOUS },
{ "Down", USER_ACTION_GOTO_ITEM_NEXT }, { "Down", ACTION_GOTO_ITEM_NEXT },
{ "k", USER_ACTION_GOTO_ITEM_PREVIOUS }, { "k", ACTION_GOTO_ITEM_PREVIOUS },
{ "j", USER_ACTION_GOTO_ITEM_NEXT }, { "j", ACTION_GOTO_ITEM_NEXT },
{ "PageUp", USER_ACTION_GOTO_PAGE_PREVIOUS }, { "PageUp", ACTION_GOTO_PAGE_PREVIOUS },
{ "PageDown", USER_ACTION_GOTO_PAGE_NEXT }, { "PageDown", ACTION_GOTO_PAGE_NEXT },
{ "C-p", USER_ACTION_GOTO_ITEM_PREVIOUS }, { "C-p", ACTION_GOTO_ITEM_PREVIOUS },
{ "C-n", USER_ACTION_GOTO_ITEM_NEXT }, { "C-n", ACTION_GOTO_ITEM_NEXT },
{ "C-b", USER_ACTION_GOTO_PAGE_PREVIOUS }, { "C-b", ACTION_GOTO_PAGE_PREVIOUS },
{ "C-f", USER_ACTION_GOTO_PAGE_NEXT }, { "C-f", ACTION_GOTO_PAGE_NEXT },
// 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", USER_ACTION_CHOOSE }, { "Enter", ACTION_CHOOSE },
{ "Delete", USER_ACTION_DELETE }, { "Delete", ACTION_DELETE },
{ "a", USER_ACTION_MPD_ADD }, { "a", ACTION_MPD_ADD },
{ "r", USER_ACTION_MPD_REPLACE }, { "r", ACTION_MPD_REPLACE },
{ "Left", USER_ACTION_MPD_PREVIOUS }, { "Left", ACTION_MPD_PREVIOUS },
{ "Right", USER_ACTION_MPD_NEXT }, { "Right", ACTION_MPD_NEXT },
{ "h", USER_ACTION_MPD_PREVIOUS }, { "h", ACTION_MPD_PREVIOUS },
{ "l", USER_ACTION_MPD_NEXT }, { "l", ACTION_MPD_NEXT },
{ "Space", USER_ACTION_MPD_TOGGLE }, { "Space", ACTION_MPD_TOGGLE },
{ "C-Space", USER_ACTION_MPD_STOP }, { "C-Space", ACTION_MPD_STOP },
{ "M-PageUp", USER_ACTION_MPD_VOLUME_UP }, { "M-PageUp", ACTION_MPD_VOLUME_UP },
{ "M-PageDown", USER_ACTION_MPD_VOLUME_DOWN }, { "M-PageDown", ACTION_MPD_VOLUME_DOWN },
}; };
static bool static bool
@ -1929,7 +1929,7 @@ app_process_termo_event (termo_key_t *event)
hard_assert (!*termo_strpkey_utf8 (g_ctx.tk, binding->key, &key, hard_assert (!*termo_strpkey_utf8 (g_ctx.tk, binding->key, &key,
TERMO_FORMAT_ALTISMETA)); TERMO_FORMAT_ALTISMETA));
if (!termo_keycmp (g_ctx.tk, event, &key)) if (!termo_keycmp (g_ctx.tk, event, &key))
return app_process_user_action (binding->action); return app_process_action (binding->action);
} }
// TODO: parametrize actions, put this among other bindings // TODO: parametrize actions, put this among other bindings
@ -1964,7 +1964,7 @@ current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer,
} }
static bool static bool
current_tab_on_action (enum user_action action) current_tab_on_action (enum action action)
{ {
struct tab *self = g_ctx.active_tab; struct tab *self = g_ctx.active_tab;
if (self->item_selected < 0) if (self->item_selected < 0)
@ -1974,12 +1974,12 @@ current_tab_on_action (enum user_action action)
switch (action) switch (action)
{ {
char *song; char *song;
case USER_ACTION_CHOOSE: case ACTION_CHOOSE:
song = xstrdup_printf ("%d", self->item_selected); song = xstrdup_printf ("%d", self->item_selected);
MPD_SIMPLE ("play", song) MPD_SIMPLE ("play", song)
free (song); free (song);
return true; return true;
case USER_ACTION_DELETE: case ACTION_DELETE:
song = xstrdup_printf ("%d", self->item_selected); song = xstrdup_printf ("%d", self->item_selected);
MPD_SIMPLE ("delete", song) MPD_SIMPLE ("delete", song)
free (song); free (song);
@ -2170,7 +2170,7 @@ library_tab_reload (const char *new_path)
} }
static bool static bool
library_tab_on_action (enum user_action action) library_tab_on_action (enum action action)
{ {
struct tab *self = g_ctx.active_tab; struct tab *self = g_ctx.active_tab;
if (self->item_selected < 0) if (self->item_selected < 0)
@ -2186,7 +2186,7 @@ library_tab_on_action (enum user_action action)
switch (action) switch (action)
{ {
case USER_ACTION_CHOOSE: case ACTION_CHOOSE:
switch (type) switch (type)
{ {
case LIBRARY_ROOT: library_tab_reload (""); break; case LIBRARY_ROOT: library_tab_reload (""); break;
@ -2209,7 +2209,7 @@ library_tab_on_action (enum user_action action)
default: hard_assert (!"invalid item type"); default: hard_assert (!"invalid item type");
} }
return true; return true;
case USER_ACTION_MPD_REPLACE: case ACTION_MPD_REPLACE:
// FIXME: we also need to play it if we've been playing things already // FIXME: we also need to play it if we've been playing things already
if (type == LIBRARY_DIR || type == LIBRARY_FILE) if (type == LIBRARY_DIR || type == LIBRARY_FILE)
{ {
@ -2218,7 +2218,7 @@ library_tab_on_action (enum user_action action)
return true; return true;
} }
return false; return false;
case USER_ACTION_MPD_ADD: case ACTION_MPD_ADD:
if (type == LIBRARY_DIR || type == LIBRARY_FILE) if (type == LIBRARY_DIR || type == LIBRARY_FILE)
{ {
MPD_SIMPLE ("add", item_path) MPD_SIMPLE ("add", item_path)
@ -2452,7 +2452,7 @@ error:
} }
static bool static bool
streams_tab_on_action (enum user_action action) streams_tab_on_action (enum action action)
{ {
struct tab *self = g_ctx.active_tab; struct tab *self = g_ctx.active_tab;
if (self->item_selected < 0) if (self->item_selected < 0)
@ -2464,11 +2464,11 @@ streams_tab_on_action (enum user_action action)
// TODO: show any error to the user // TODO: show any error to the user
switch (action) switch (action)
{ {
case USER_ACTION_MPD_REPLACE: case ACTION_MPD_REPLACE:
streams_tab_process (uri, true, NULL); streams_tab_process (uri, true, NULL);
return true; return true;
case USER_ACTION_CHOOSE: case ACTION_CHOOSE:
case USER_ACTION_MPD_ADD: case ACTION_MPD_ADD:
streams_tab_process (uri, false, NULL); streams_tab_process (uri, false, NULL);
return true; return true;
default: default:
@ -2578,7 +2578,7 @@ help_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width)
hard_assert (item_index < N_ELEMENTS (g_default_bindings)); hard_assert (item_index < N_ELEMENTS (g_default_bindings));
struct binding *binding = &g_default_bindings[item_index]; struct binding *binding = &g_default_bindings[item_index];
char *text = xstrdup_printf ("%-12s %s", char *text = xstrdup_printf ("%-12s %s",
binding->key, g_user_actions[binding->action].description); binding->key, g_actions[binding->action].description);
row_buffer_append (buffer, text, 0); row_buffer_append (buffer, text, 0);
free (text); free (text);
} }