Browse Source

AudioFile: sort filename list by name

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.02
falkTX 3 years ago
parent
commit
f9e5a03ecb
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 15 additions and 5 deletions
  1. +15
    -5
      plugins/Cardinal/src/AudioFile.cpp

+ 15
- 5
plugins/Cardinal/src/AudioFile.cpp View File

@@ -340,7 +340,10 @@ struct AudioFileListWidget : ImGuiWidget {
bool showError = false; bool showError = false;
String errorMessage; 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::string currentDirectory;
std::vector<ghcFile> currentFiles; std::vector<ghcFile> currentFiles;
size_t selectedFile = (size_t)-1; size_t selectedFile = (size_t)-1;
@@ -438,7 +441,6 @@ struct AudioFileListWidget : ImGuiWidget {
currentDirectory = path(module->currentFile).parent_path().string(); currentDirectory = path(module->currentFile).parent_path().string();


directory_iterator it(currentDirectory); directory_iterator it(currentDirectory);
size_t index = 0;
for (directory_iterator itb = begin(it), ite=end(it); itb != ite; ++itb) for (directory_iterator itb = begin(it), ite=end(it); itb != ite; ++itb)
{ {
if (! itb->is_regular_file()) if (! itb->is_regular_file())
@@ -449,14 +451,22 @@ struct AudioFileListWidget : ImGuiWidget {
{ {
if (extension.compare(supportedExtensions[i]) == 0) if (extension.compare(supportedExtensions[i]) == 0)
{ {
if (filepath.compare(module->currentFile) == 0)
selectedFile = index;
currentFiles.push_back({ filepath.string(), filepath.filename().string() }); currentFiles.push_back({ filepath.string(), filepath.filename().string() });
++index;
break; 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;
}
}
} }
}; };




Loading…
Cancel
Save