From f9e5a03ecb4e4d85c06ce1f9bb7a108d882e9463 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 1 Feb 2022 19:06:29 +0000 Subject: [PATCH] AudioFile: sort filename list by name Signed-off-by: falkTX --- plugins/Cardinal/src/AudioFile.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/Cardinal/src/AudioFile.cpp b/plugins/Cardinal/src/AudioFile.cpp index e10e51b..6ab8759 100644 --- a/plugins/Cardinal/src/AudioFile.cpp +++ b/plugins/Cardinal/src/AudioFile.cpp @@ -340,7 +340,10 @@ struct AudioFileListWidget : ImGuiWidget { bool showError = false; String errorMessage; - struct ghcFile { std::string full, base; }; + struct ghcFile { + std::string full, base; + bool operator<(const ghcFile& other) noexcept { return base < other.base; } + }; std::string currentDirectory; std::vector currentFiles; size_t selectedFile = (size_t)-1; @@ -438,7 +441,6 @@ struct AudioFileListWidget : ImGuiWidget { currentDirectory = path(module->currentFile).parent_path().string(); directory_iterator it(currentDirectory); - size_t index = 0; for (directory_iterator itb = begin(it), ite=end(it); itb != ite; ++itb) { if (! itb->is_regular_file()) @@ -449,14 +451,22 @@ struct AudioFileListWidget : ImGuiWidget { { if (extension.compare(supportedExtensions[i]) == 0) { - if (filepath.compare(module->currentFile) == 0) - selectedFile = index; currentFiles.push_back({ filepath.string(), filepath.filename().string() }); - ++index; break; } } } + + std::sort(currentFiles.begin(), currentFiles.end()); + + for (size_t index = 0; index < currentFiles.size(); ++index) + { + if (currentFiles[index].full.compare(module->currentFile) == 0) + { + selectedFile = index; + break; + } + } } };