-
-
Notifications
You must be signed in to change notification settings - Fork 9k
frontend, libobs, plugins: Natural sorting for files, profile and scene names #12577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Updated the list of filenames I tested the sorting with and I'm happy with the results. One issue remains: There is also a question if the default locale set with |
b12ac87 to
35c77a8
Compare
Warchamp7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving on a conceptual/UX level, but others will need to speak to the technical implications
28140c8 to
1c78f24
Compare
Sort drag&dropped sources using locale-aware natural sorting with QCollator and system locale.
Change locale-aware sorting of profiles and scene collections in menus to locale-aware natural sorting, so number sequences in names are treated by value rather than their alphabetical order.
New comparison methods astrnatcmpi() and wstrnatcmpi() for sorting strings and documentation for them. Uses locale aware strcol() / wcscoll() and a custom implementation of natural comparison for number sequences. Supports multibyte and whcar surrogate characters. This is intended to be used for parts that do not have direct access to higher level methods like Qt QCollator.
Applies locale-aware natural sorting to the cycled files when adding directory to image slideshow. Previously files in directories were cycled in arbitrary order by os_readdir(). Locale-awareness is limited on Windows currently, because we are using minimal 'C' locale for it. This is to be addressed separately.
Applies the same natural, alphabetical sort to vlc playlist directories that was added for slideshow.
Description
Applies natural, locale aware sorting when drag&dropping many sources at once and to profile and scene names in menus. For slideshow (mk2) and VLC the files in added directories are cycled using this sorting method instead of an arbitrary order. The order of items in the slideshow listbox is otherwise preserved.
For background: Natural sort means sorting by numerical value. Alphabetical sort arranges numbers like this: 1 < 10 < 11 < 2 < 3.
Natural sort does it this way: 1 < 2 < 3 < 10 < 11.
The natural sort is what Windows explorer uses under the hood when you sort by name or use
ls -von unix.For general use,
qt-wrappershas couple new methods for natural sorting:The list parameter is sorted using locale and number value aware algorithm with
QCollator. It works withQStringandQStringView. System locale is used to achieve the locale-aware sorting.For lower level stuff in C, like slideshow plugin, there's new comparison functions for
char*andwchar_t*indstrlibrary.The return value is <0, 0 or >0 as expected for return value of
qsort()'s callback function. This sorting usesstrcoll()andwcscoll()respectively for locale aware sorting, but does natural number sorting using a custom implementation. The locale aware sorting, however, is currently with limited use on Windows, as the program is using the process wide 'C' locale. Changing this behavior is out of this PR scope, so I made another here #12624.OBSBasic_Dropfiles.cpp has somewhat sizable changes, due to how late the names for listed sources were acquired. This changes it so names are gathered first for sorting and only later added to the UI.
Motivation and Context
Fixes #10382
Couple requests on forums here and here. Most recently I saw a Youtuber mention this during a live stream.
The issue is with filenames and other listings that contain incremental numbers which are not sorted intuitively when sorted alphabetically. In fact the alphabetical sorting is also coincidental, since the methods for iterating over files give no guarantee about the order.
How Has This Been Tested?
I tested the features with files in directories with the following file names to see if they are sorted correctly:
testnames.txt
The files should appear in the order listed for en_FI locale. The files with 'ä' or 'ö' could be in another place for different locales. The important part is the numerical comparison works, so 5.jpg is before 10.jpg while the opposite is true for basic alphabetical sorting.
I'm on Windows 11 English US version, but with Finnish region/locale settings.
Types of changes
Checklist: