lmms icon indicating copy to clipboard operation
lmms copied to clipboard

FileBrowser.cpp : add naturalCompare function

Open Jinxuan2001 opened this issue 1 year ago • 6 comments

add naturalCompare function :In the current FileBrowser::addItems , the ordering of directories and files is based on alphabetical order. Especially when dealing with directories, the code is sorted by name (fileName < d->text(0)). To implement natural sorting, we need to implement a custom comparison function. For example, you can add "file1", "file2",... ", "file10", rather than alphabetically placing "file10" before "file2". This is a realization idea, personal ideas only provide reference

Jinxuan2001 avatar Jun 20 '24 09:06 Jinxuan2001

Take a look at #5772 too.

Thanks for the contribution ;-)

Rossmaxx avatar Jun 20 '24 09:06 Rossmaxx

The sorting function looks good, but it only appears to be applied to root directories. Would you be able to apply it to all file browser entries?

DomClark avatar Jun 20 '24 22:06 DomClark

Another nitpick, @sakertooth sped up file browser searching recently. Hope this PR doesn't undo his speed benefit accidentally, in favour of aesthetics.

Rossmaxx avatar Jun 21 '24 07:06 Rossmaxx

I looked for another method. On quick googling, i found that QString has a compare function. Why not use that instead?

Rossmaxx avatar Jun 21 '24 07:06 Rossmaxx

Another method i found. https://stackoverflow.com/questions/11933883/sort-filenames-naturally-with-qt

Rossmaxx avatar Jun 21 '24 07:06 Rossmaxx

To achieve natural sorting, we can use QCollator instead. I think what is best is to make a global pure function for natural sorting, so that anyone that needs to do a natural sort can choose to do so.

sakertooth avatar Jul 17 '24 10:07 sakertooth