Hotkeys: Add placeholder for function return value

Seems a bit clearer to me than redefining the meaning
of ONPLAY_OK in this context, which was easy to miss.

Fixes the return value for the bookmark_create_menu
hotkey, too. It was previously mapped to ONPLAY_OK
in case the function failed, and to ONPLAY_RELOAD_DIR
if it succeeded. This had no ill effect - or any effect –
since either of the values were disregarded by the WPS
when executing a hotkey.

Return values of playlist_insert_shuffled also had no
effect (by design, apparently, see commit 482b45b).
Use ONPLAY_FUNC_RETURN in hotkey_assignment.

Behavior hasn't changed, it's only been made more
explicit.

Change-Id: Iefc60c9f42c1063af78d368dc382916848064d38
This commit is contained in:
Christian Soffke 2022-11-22 08:12:17 +01:00 committed by William Wilgus
parent 0d355a9c47
commit 6bc443f474
2 changed files with 25 additions and 25 deletions

View file

@ -1785,7 +1785,7 @@ static int onplaymenu_callback(int action,
#ifdef HAVE_HOTKEY #ifdef HAVE_HOTKEY
/* direct function calls, no need for menu callbacks */ /* direct function calls, no need for menu callbacks */
static bool delete_item(void) static bool hotkey_delete_item(void)
{ {
#ifdef HAVE_MULTIVOLUME #ifdef HAVE_MULTIVOLUME
/* no delete for volumes */ /* no delete for volumes */
@ -1795,7 +1795,7 @@ static bool delete_item(void)
return delete_file_dir(); return delete_file_dir();
} }
static bool open_with(void) static bool hotkey_open_with(void)
{ {
/* only open files */ /* only open files */
if (selected_file_attr & ATTR_DIRECTORY) if (selected_file_attr & ATTR_DIRECTORY)
@ -1807,20 +1807,18 @@ static bool open_with(void)
return list_viewers(); return list_viewers();
} }
static int playlist_insert_shuffled(void) static int hotkey_tree_pl_insert_shuffled(void)
{ {
if ((audio_status() & AUDIO_STATUS_PLAY) || if ((audio_status() & AUDIO_STATUS_PLAY) ||
(selected_file_attr & ATTR_DIRECTORY) || (selected_file_attr & ATTR_DIRECTORY) ||
((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)) ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U))
{ {
add_to_playlist(&addtopl_insert_shuf); add_to_playlist(&addtopl_insert_shuf);
return ONPLAY_START_PLAY;
} }
return ONPLAY_RELOAD_DIR; return ONPLAY_RELOAD_DIR;
} }
static int tree_hotkey_run_plugin(void *param) static int hotkey_tree_run_plugin(void *param)
{ {
if (filetype_load_plugin((const char*)param, selected_file) == PLUGIN_GOTO_WPS) if (filetype_load_plugin((const char*)param, selected_file) == PLUGIN_GOTO_WPS)
return ONPLAY_START_PLAY; return ONPLAY_START_PLAY;
@ -1828,7 +1826,7 @@ static int tree_hotkey_run_plugin(void *param)
return ONPLAY_RELOAD_DIR; return ONPLAY_RELOAD_DIR;
} }
static int hotkey_run_plugin(void) static int hotkey_wps_run_plugin(void)
{ {
open_plugin_run(ID2P(LANG_HOTKEY_WPS)); open_plugin_run(ID2P(LANG_HOTKEY_WPS));
return ONPLAY_OK; return ONPLAY_OK;
@ -1838,8 +1836,8 @@ struct hotkey_assignment {
int action; /* hotkey_action */ int action; /* hotkey_action */
int lang_id; /* Language ID */ int lang_id; /* Language ID */
struct menu_func func; /* Function to run if this entry is selected */ struct menu_func func; /* Function to run if this entry is selected */
int return_code; /* What to return after the function is run. ONPLAY_OK here */ int return_code; /* What to return after the function is run. */
}; /* means to use function return code, see execute_hotkey */ }; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */
#define HOTKEY_FUNC(func, param) {{(void *)func}, param} #define HOTKEY_FUNC(func, param) {{(void *)func}, param}
@ -1859,30 +1857,30 @@ static struct hotkey_assignment hotkey_items[] = {
ONPLAY_RELOAD_DIR }, ONPLAY_RELOAD_DIR },
#endif #endif
{ HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH, { HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH,
HOTKEY_FUNC(open_with, NULL), HOTKEY_FUNC(hotkey_open_with, NULL),
ONPLAY_RELOAD_DIR }, ONPLAY_RELOAD_DIR },
{ HOTKEY_DELETE, LANG_DELETE, { HOTKEY_DELETE, LANG_DELETE,
HOTKEY_FUNC(delete_item, NULL), HOTKEY_FUNC(hotkey_delete_item, NULL),
ONPLAY_RELOAD_DIR }, ONPLAY_RELOAD_DIR },
{ HOTKEY_INSERT, LANG_INSERT, { HOTKEY_INSERT, LANG_INSERT,
HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert),
ONPLAY_RELOAD_DIR }, ONPLAY_RELOAD_DIR },
{ HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED, { HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED,
HOTKEY_FUNC(playlist_insert_shuffled, NULL), HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL),
ONPLAY_RELOAD_DIR }, ONPLAY_FUNC_RETURN },
{ HOTKEY_PLUGIN, LANG_OPEN_PLUGIN, { HOTKEY_PLUGIN, LANG_OPEN_PLUGIN,
HOTKEY_FUNC(hotkey_run_plugin, NULL), HOTKEY_FUNC(hotkey_wps_run_plugin, NULL),
ONPLAY_OK }, ONPLAY_FUNC_RETURN },
{ HOTKEY_BOOKMARK, LANG_BOOKMARK_MENU_CREATE, { HOTKEY_BOOKMARK, LANG_BOOKMARK_MENU_CREATE,
HOTKEY_FUNC(bookmark_create_menu, NULL), HOTKEY_FUNC(bookmark_create_menu, NULL),
ONPLAY_OK }, ONPLAY_OK },
{ HOTKEY_PROPERTIES, LANG_PROPERTIES, { HOTKEY_PROPERTIES, LANG_PROPERTIES,
HOTKEY_FUNC(tree_hotkey_run_plugin, (void *)"properties"), HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"),
ONPLAY_OK }, ONPLAY_FUNC_RETURN },
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
{ HOTKEY_PICTUREFLOW, LANG_ONPLAY_PICTUREFLOW, { HOTKEY_PICTUREFLOW, LANG_ONPLAY_PICTUREFLOW,
HOTKEY_FUNC(tree_hotkey_run_plugin, (void *)"pictureflow"), HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"),
ONPLAY_OK }, ONPLAY_FUNC_RETURN },
#endif #endif
}; };
@ -1923,12 +1921,11 @@ static int execute_hotkey(bool is_wps)
else else
func_return = (*func.function)(); func_return = (*func.function)();
} }
/* return with the associated code */
const int return_code = this_item->return_code; const int return_code = this_item->return_code;
/* ONPLAY_OK here means to use the function return code */
if (return_code == ONPLAY_OK) if (return_code == ONPLAY_FUNC_RETURN)
return func_return; return func_return; /* Use value returned by function */
return return_code; return return_code; /* or return the associated value */
} }
} }

View file

@ -31,6 +31,9 @@ enum {
ONPLAY_START_PLAY, ONPLAY_START_PLAY,
ONPLAY_PLAYLIST, ONPLAY_PLAYLIST,
ONPLAY_PLUGIN, ONPLAY_PLUGIN,
#ifdef HAVE_HOTKEY
ONPLAY_FUNC_RETURN, /* for use in hotkey_assignment only */
#endif
}; };
#ifdef HAVE_HOTKEY #ifdef HAVE_HOTKEY