Sort directories first in file picker
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
#include <EpdRenderer.h>
|
#include <EpdRenderer.h>
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
|
|
||||||
void caseInsensitiveSort(std::vector<std::string>& strs) {
|
void sortFileList(std::vector<std::string>& strs) {
|
||||||
std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) {
|
std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) {
|
||||||
|
if (str1.back() == '/' && str2.back() != '/') return true;
|
||||||
|
if (str1.back() != '/' && str2.back() == '/') return false;
|
||||||
return lexicographical_compare(
|
return lexicographical_compare(
|
||||||
begin(str1), end(str1), begin(str2), end(str2),
|
begin(str1), end(str1), begin(str2), end(str2),
|
||||||
[](const char& char1, const char& char2) { return tolower(char1) < tolower(char2); });
|
[](const char& char1, const char& char2) { return tolower(char1) < tolower(char2); });
|
||||||
@@ -35,7 +37,7 @@ void FileSelectionScreen::loadFiles() {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
root.close();
|
root.close();
|
||||||
caseInsensitiveSort(files);
|
sortFileList(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSelectionScreen::onEnter() {
|
void FileSelectionScreen::onEnter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user