playlist catalog: sort independently from file browser

Allow independent sorting of playlists in the
playlist catalog, using the context menu.

You may want to usually sort playlists by their date
(modified), but sort audio tracks alphabetically.
This is now possible without having to constantly
adjust a setting.

The fact that 'Sort Files' applied to both the file
browser and playlist catalog seems more like a side
effect of the implementation, rather than behavior
that is wanted. Additionally, the 'By Type' sorting
makes no sense when only a single type is displayed.

Since many of the other File View settings don't
apply to the playlist catalog, hide the menu there.

Change-Id: Ic35038015d0860998ae117f472ce23ce3bc80cfa
This commit is contained in:
Christian Soffke 2025-04-18 20:37:51 +02:00 committed by Solomon Peachy
parent 6e06319988
commit 4346a1e8e7
10 changed files with 62 additions and 7 deletions

View file

@ -58,6 +58,7 @@
static struct compare_data static struct compare_data
{ {
int sort_dir; /* qsort key for sorting directories */ int sort_dir; /* qsort key for sorting directories */
int sort_file; /* ...for sorting files */
int(*_compar)(const char*, const char*, size_t); int(*_compar)(const char*, const char*, size_t);
} cmp_data; } cmp_data;
@ -234,7 +235,7 @@ static int compare(const void* p1, const void* p2)
if (cmp_data.sort_dir == SORT_AS_FILE) if (cmp_data.sort_dir == SORT_AS_FILE)
{ /* treat as two files */ { /* treat as two files */
criteria = global_settings.sort_file; criteria = cmp_data.sort_file;
} }
else if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) else if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY)
{ /* two directories */ { /* two directories */
@ -253,7 +254,7 @@ static int compare(const void* p1, const void* p2)
} }
else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY)) else if (!(e1->attr & ATTR_DIRECTORY) && !(e2->attr & ATTR_DIRECTORY))
{ /* two files */ { /* two files */
criteria = global_settings.sort_file; criteria = cmp_data.sort_file;
} }
else /* dir and file, dir goes first */ else /* dir and file, dir goes first */
return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY); return (e2->attr & ATTR_DIRECTORY) - (e1->attr & ATTR_DIRECTORY);
@ -425,6 +426,10 @@ int ft_load(struct tree_context* c, const char* tempdir)
/* allow directories to be sorted into file list */ /* allow directories to be sorted into file list */
cmp_data.sort_dir = (*c->dirfilter == SHOW_PLUGINS) ? SORT_AS_FILE : c->sort_dir; cmp_data.sort_dir = (*c->dirfilter == SHOW_PLUGINS) ? SORT_AS_FILE : c->sort_dir;
/* playlist catalog uses sorting independent from file browser */
cmp_data.sort_file = (*c->dirfilter == SHOW_M3U) ?
global_settings.sort_playlists : global_settings.sort_file;
if (global_settings.sort_case) if (global_settings.sort_case)
{ {
if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER) if (global_settings.interpret_numbers == SORT_INTERPRET_AS_NUMBER)

View file

@ -16956,3 +16956,17 @@
*: "Playlist finished. Play again?" *: "Playlist finished. Play again?"
</voice> </voice>
</phrase> </phrase>
<phrase>
id: LANG_SORT_PLAYLISTS
desc: playlists sorting setting
user: core
<source>
*: "Sort Playlists"
</source>
<dest>
*: "Sort Playlists"
</dest>
<voice>
*: "sort playlists"
</voice>
</phrase>

View file

@ -578,7 +578,9 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected,
shortcuts_add(SHORTCUT_SETTING, (void*)setting); shortcuts_add(SHORTCUT_SETTING, (void*)setting);
break; break;
#endif #endif
} /* swicth(do_menu()) */ } /* switch(do_menu()) */
if (menu->flags & MENU_EXITAFTERTHISMENU)
done = true; /* in case onplay menu contains setting */
redraw_lists = true; redraw_lists = true;
} }
} /* else if (!in_stringlist) */ } /* else if (!in_stringlist) */

View file

@ -157,9 +157,11 @@ MAKE_MENU(currentplaylist_settings_menu, ID2P(LANG_CURRENT_PLAYLIST),
&show_shuffled_adding_options, &show_shuffled_adding_options,
&show_queue_options); &show_queue_options);
MENUITEM_SETTING(sort_playlists, &global_settings.sort_playlists, NULL);
MAKE_MENU(playlist_settings, ID2P(LANG_PLAYLISTS), NULL, MAKE_MENU(playlist_settings, ID2P(LANG_PLAYLISTS), NULL,
Icon_Playlist, Icon_Playlist,
&viewer_settings_menu, &recursive_dir_insert, &currentplaylist_settings_menu); &sort_playlists, &viewer_settings_menu, &recursive_dir_insert,
&currentplaylist_settings_menu);
MAKE_MENU(playlist_options, ID2P(LANG_PLAYLISTS), NULL, MAKE_MENU(playlist_options, ID2P(LANG_PLAYLISTS), NULL,
Icon_Playlist, Icon_Playlist,
&view_cur_playlist, &save_playlist, &view_cur_playlist, &save_playlist,

View file

@ -220,10 +220,13 @@ static int filemenu_callback(int action,
{ {
(void)this_list; (void)this_list;
/* Show File View menu in Settings or File Browser,
but not in Database or Playlist Catalog */
if (action == ACTION_REQUEST_MENUITEM && if (action == ACTION_REQUEST_MENUITEM &&
this_item == &file_menu && this_item == &file_menu &&
get_onplay_context() == CONTEXT_ID3DB && get_current_activity() != ACTIVITY_SETTINGS &&
get_current_activity() != ACTIVITY_SETTINGS) (get_onplay_context() != CONTEXT_TREE
|| *tree_get_context()->dirfilter == SHOW_M3U))
return ACTION_EXIT_MENUITEM; return ACTION_EXIT_MENUITEM;
return action; return action;

View file

@ -1132,6 +1132,23 @@ MAKE_ONPLAYMENU( wps_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE),
#endif #endif
); );
int sort_playlists_callback(int action,
const struct menu_item_ex *this_item,
struct gui_synclist *this_list)
{
(void) this_list;
(void) this_item;
if (action == ACTION_REQUEST_MENUITEM &&
*tree_get_context()->dirfilter != SHOW_M3U)
{
return ACTION_EXIT_MENUITEM;
}
return action;
}
MENUITEM_SETTING(sort_playlists, &global_settings.sort_playlists, sort_playlists_callback);
MENUITEM_FUNCTION(view_playlist_item, 0, ID2P(LANG_VIEW), MENUITEM_FUNCTION(view_playlist_item, 0, ID2P(LANG_VIEW),
view_playlist, view_playlist,
onplaymenu_callback, Icon_Playlist); onplaymenu_callback, Icon_Playlist);
@ -1149,7 +1166,7 @@ MAKE_ONPLAYMENU( tree_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE),
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
&set_backdrop_item, &set_backdrop_item,
#endif #endif
&add_to_faves_item, &set_as_dir_menu, &file_menu, &add_to_faves_item, &set_as_dir_menu, &file_menu, &sort_playlists,
); );
static int onplaymenu_callback(int action, static int onplaymenu_callback(int action,
const struct menu_item_ex *this_item, const struct menu_item_ex *this_item,

View file

@ -682,6 +682,7 @@ struct user_settings
bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */ bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */
int sort_dir; /* 0=alpha, 1=date (old first), 2=date (new first) */ int sort_dir; /* 0=alpha, 1=date (old first), 2=date (new first) */
int sort_file; /* 0=alpha, 1=date, 2=date (new first), 3=type */ int sort_file; /* 0=alpha, 1=date, 2=date (new first), 3=type */
int sort_playlists; /* in playlist catalog 0=alpha, 1=date, 2=date (new first) */
int interpret_numbers; /* true=strnatcmp, false=strcmp */ int interpret_numbers; /* true=strnatcmp, false=strcmp */
/* power settings */ /* power settings */

View file

@ -1415,6 +1415,10 @@ const struct settings_list settings[] = {
"sort files", "alpha,oldest,newest,type", treesort_callback, 4, "sort files", "alpha,oldest,newest,type", treesort_callback, 4,
ID2P(LANG_SORT_ALPHA), ID2P(LANG_SORT_DATE), ID2P(LANG_SORT_ALPHA), ID2P(LANG_SORT_DATE),
ID2P(LANG_SORT_DATE_REVERSE) , ID2P(LANG_SORT_TYPE)), ID2P(LANG_SORT_DATE_REVERSE) , ID2P(LANG_SORT_TYPE)),
CHOICE_SETTING(0, sort_playlists, LANG_SORT_PLAYLISTS, 0 ,
"sort playlists", "alpha,oldest,newest", treesort_callback, 3,
ID2P(LANG_SORT_ALPHA), ID2P(LANG_SORT_DATE),
ID2P(LANG_SORT_DATE_REVERSE)),
CHOICE_SETTING(0, interpret_numbers, LANG_SORT_INTERPRET_NUMBERS, 1, CHOICE_SETTING(0, interpret_numbers, LANG_SORT_INTERPRET_NUMBERS, 1,
"sort interpret number", "digits,numbers",treesort_callback, 2, "sort interpret number", "digits,numbers",treesort_callback, 2,
ID2P(LANG_SORT_INTERPRET_AS_DIGIT), ID2P(LANG_SORT_INTERPRET_AS_DIGIT),

View file

@ -150,6 +150,7 @@
delete, insert, insert shuffled & N/A\\} delete, insert, insert shuffled & N/A\\}
} }
sort files & alpha, oldest, newest, type & N/A\\ sort files & alpha, oldest, newest, type & N/A\\
sort playlists & alpha, oldest, newest & N/A\\
sort dirs & alpha, oldest, newest & N/A\\ sort dirs & alpha, oldest, newest & N/A\\
sort interpret number & digits, numbers & N/A\\ sort interpret number & digits, numbers & N/A\\
tagcache\_autoupdate tagcache\_autoupdate

View file

@ -7,6 +7,12 @@ related to playlists.
\begin{description} \begin{description}
\item[Sort Playlists.]
This option adjusts the sorting of items listed in the \setting{Playlists}
menu (see \reference{ref:playlistoptions}). You can also press
\ActionStdContext{} in the \setting{Playlists} menu to access the option
from there, directly.
\item[Playlist Viewer Settings.] \item[Playlist Viewer Settings.]
This submenu contains settings related to the Playlist Viewer. This submenu contains settings related to the Playlist Viewer.
\begin{description} \begin{description}