From 7c7a6e5cff4105d0a54ccb9fe1eb272002c89ee3 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Thu, 24 Mar 2022 10:24:12 -0400 Subject: [PATCH] sort file lists before showing user. closes #1559 (#1943) --- .../ext/launcher/src/launcherwindow.cpp | 36 +++++++++++++++---- src/interaction/sessionrecording.cpp | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 8702e0e8da..c330a9c619 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -354,13 +354,18 @@ void LauncherWindow::populateProfilesList(std::string preset) { ++_userAssetCount; // Add all the files with the .profile extension to the dropdown + std::vector profiles; for (const fs::directory_entry& p : fs::directory_iterator(_userProfilePath)) { if (p.path().extension() != ".profile") { continue; } - _profileBox->addItem(QString::fromStdString(p.path().stem().string())); + profiles.push_back(p); ++_userAssetCount; } + std::sort(profiles.begin(), profiles.end()); + for (const fs::directory_entry& p : profiles) { + _profileBox->addItem(QString::fromStdString(p.path().stem().string())); + } _profileBox->addItem(QString::fromStdString("--- OpenSpace Profiles ---")); model = qobject_cast(_profileBox->model()); @@ -368,11 +373,17 @@ void LauncherWindow::populateProfilesList(std::string preset) { ++_userAssetCount; // Add all the files with the .profile extension to the dropdown - for (const fs::directory_entry& p : fs::directory_iterator(_profilePath)) { - if (p.path().extension() != ".profile") { + profiles.clear(); + for (const fs::directory_entry& path : fs::directory_iterator(_profilePath)) { + if (path.path().extension() != ".profile") { continue; } - _profileBox->addItem(QString::fromStdString(p.path().stem().string())); + profiles.push_back(path); + } + std::sort(profiles.begin(), profiles.end()); + //add sorted items to list + for (const fs::directory_entry& profile : profiles) { + _profileBox->addItem(QString::fromStdString(profile.path().stem().string())); } // Try to find the requested profile and set it as the current one @@ -414,8 +425,15 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) { bool hasXmlConfig = false; - // Add all the files with the .xml or .json extension to the dropdown + //sort files + std::vector files; for (const fs::directory_entry& p : fs::directory_iterator(_userConfigPath)) { + files.push_back(p); + } + std::sort(files.begin(), files.end()); + + // Add all the files with the .xml or .json extension to the dropdown + for (const fs::directory_entry& p : files) { bool isConfigFile = handleConfigurationFile(*_windowConfigBox, p); if (isConfigFile) { ++_userConfigCount; @@ -428,8 +446,14 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) { model->item(_userConfigCount)->setEnabled(false); if (std::filesystem::exists(_configPath)) { - // Add all the files with the .xml or .json extension to the dropdown + //sort files + files.clear(); for (const fs::directory_entry& p : fs::directory_iterator(_configPath)) { + files.push_back(p); + } + std::sort(files.begin(), files.end()); + // Add all the files with the .xml or .json extension to the dropdown + for (const fs::directory_entry& p : files) { handleConfigurationFile(*_windowConfigBox, p); hasXmlConfig |= p.path().extension() == ".xml"; } diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 8ccd49385c..3d6ce56dc8 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -2155,6 +2155,7 @@ std::vector SessionRecording::playbackList() const { } } } + std::sort(fileList.begin(), fileList.end()); return fileList; }