diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index a8c90fc77..326401de0 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -92,7 +92,7 @@ CollectionSystemManager::~CollectionSystemManager() removeCollectionsFromDisplayedSystems(); // Delete all custom collections. - for (std::map::const_iterator + for (std::map::const_iterator it = mCustomCollectionSystemsData.cbegin(); it != mCustomCollectionSystemsData.cend() ; it++) delete it->second.system; @@ -232,7 +232,7 @@ void CollectionSystemManager::loadEnabledListFromSettings() Settings::getInstance()->getString("CollectionSystemsAuto"), true); // Iterate the map. - for (std::map::iterator + for (std::map::iterator it = mAutoCollectionSystemsData.begin(); it != mAutoCollectionSystemsData.end() ; it++ ) { @@ -247,7 +247,7 @@ void CollectionSystemManager::loadEnabledListFromSettings() Settings::getInstance()->getString("CollectionSystemsCustom"), true); // Iterate the map. - for (std::map::iterator + for (std::map::iterator it = mCustomCollectionSystemsData.begin(); it != mCustomCollectionSystemsData.end() ; it++ ) { @@ -719,7 +719,7 @@ SystemData* CollectionSystemManager::getSystemToView(SystemData* sys) // Loads Automatic Collection systems (All, Favorites, Last Played). void CollectionSystemManager::initAutoCollectionSystems() { - for (std::map::const_iterator + for (std::map::const_iterator it = mCollectionSystemDeclsIndex.cbegin(); it != mCollectionSystemDeclsIndex.cend() ; it++ ) { CollectionSystemDecl sysDecl = it->second; @@ -824,8 +824,8 @@ SystemData* CollectionSystemManager::addNewCustomCollection(std::string name) SystemData* CollectionSystemManager::createNewCollectionEntry( std::string name, CollectionSystemDecl sysDecl, bool index, bool custom) { - SystemData* newSys = new SystemData( - name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true, custom); + SystemData* newSys = new SystemData(name, sysDecl.longName, + mCollectionEnvData, sysDecl.themeFolder, true, custom); CollectionSystemData newCollectionData; newCollectionData.system = newSys; @@ -976,10 +976,10 @@ void CollectionSystemManager::removeCollectionsFromDisplayedSystems() } void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems( - std::map* colSystemData) + std::map* colSystemData) { // Add auto enabled collections. - for (std::map::iterator + for (std::map::iterator it = colSystemData->begin() ; it != colSystemData->end() ; it++ ) { if (it->second.isEnabled) { // Check if populated, otherwise populate. @@ -1155,7 +1155,7 @@ std::vector CollectionSystemManager::getCollectionsFromConfigFolder std::vector CollectionSystemManager::getCollectionThemeFolders(bool custom) { std::vector systems; - for (std::map::const_iterator + for (std::map::const_iterator it = mCollectionSystemDeclsIndex.cbegin(); it != mCollectionSystemDeclsIndex.cend() ; it++ ) { CollectionSystemDecl sysDecl = it->second; @@ -1169,7 +1169,7 @@ std::vector CollectionSystemManager::getCollectionThemeFolders(bool std::vector CollectionSystemManager::getUserCollectionThemeFolders() { std::vector systems; - for (std::map::const_iterator + for (std::map::const_iterator it = mCustomCollectionSystemsData.cbegin(); it != mCustomCollectionSystemsData.cend() ; it++ ) systems.push_back(it->second.decl.themeFolder); @@ -1213,7 +1213,7 @@ bool systemSort(SystemData* sys1, SystemData* sys2) bool CollectionSystemManager::getIsCustomCollection(SystemData* system) { // Iterate the map. - for (std::map::const_iterator + for (std::map::const_iterator it = mCustomCollectionSystemsData.cbegin(); it != mCustomCollectionSystemsData.cend() ; it++) { if (it->second.system == system) diff --git a/es-app/src/CollectionSystemManager.h b/es-app/src/CollectionSystemManager.h index 36f959f52..dbb90021a 100644 --- a/es-app/src/CollectionSystemManager.h +++ b/es-app/src/CollectionSystemManager.h @@ -22,6 +22,8 @@ #ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H #define ES_APP_COLLECTION_SYSTEM_MANAGER_H +#include "utils/StringUtil.h" + #include #include #include @@ -53,6 +55,13 @@ struct CollectionSystemData { bool isPopulated; }; +struct stringComparator { + bool operator()(const std::string& a, const std::string& b) const + { + return Utils::String::toUpper(a) < Utils::String::toUpper(b); + } +}; + class CollectionSystemManager { public: @@ -72,10 +81,10 @@ public: void updateCollectionSystem(FileData* file, CollectionSystemData sysData); void deleteCollectionFiles(FileData* file); - inline std::map getAutoCollectionSystems() - { return mAutoCollectionSystemsData; }; - inline std::map getCustomCollectionSystems() - { return mCustomCollectionSystemsData; }; + inline std::map + getAutoCollectionSystems() { return mAutoCollectionSystemsData; }; + inline std::map + getCustomCollectionSystems() { return mCustomCollectionSystemsData; }; inline SystemData* getCustomCollectionsBundle() { return mCustomCollectionsBundle; }; std::vector getUnusedSystemsFromTheme(); SystemData* addNewCustomCollection(std::string name); @@ -98,9 +107,9 @@ public: private: static CollectionSystemManager* sInstance; SystemEnvironmentData* mCollectionEnvData; - std::map mCollectionSystemDeclsIndex; - std::map mAutoCollectionSystemsData; - std::map mCustomCollectionSystemsData; + std::map mCollectionSystemDeclsIndex; + std::map mAutoCollectionSystemsData; + std::map mCustomCollectionSystemsData; Window* mWindow; bool mIsEditingCustom; bool mHasEnabledCustomCollection; @@ -117,7 +126,7 @@ private: void removeCollectionsFromDisplayedSystems(); void addEnabledCollectionsToDisplayedSystems(std::map* colSystemData); + CollectionSystemData, stringComparator>* colSystemData); std::vector getSystemsFromConfig(); std::vector getSystemsFromTheme(); diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 796dc5fe2..92becfe0b 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -447,11 +447,9 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending, std::vector mChildrenFolders; std::vector mChildrenOthers; - // For grouped custom collections, always sort the collection list as 'filename, ascending'. + // The main custom collections view is sorted during startup in CollectionSystemManager. // The individual collections are however sorted as any normal systems/folders. if (mSystem->isCollection() && mSystem->getFullName() == "collections") { - std::stable_sort(mChildren.begin(), mChildren.end(), - getSortTypeFromString("filename, ascending").comparisonFunction); for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) { // Build mFirstLetterIndex. const char firstChar = toupper((*it)->getSortName().front()); @@ -564,11 +562,9 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop"); bool hasFolders = false; - // For grouped custom collections, always sort the collection list as 'filename, ascending'. + // The main custom collections view is sorted during startup in CollectionSystemManager. // The individual collections are however sorted as any normal systems/folders. if (mSystem->isCollection() && mSystem->getFullName() == "collections") { - std::stable_sort(mChildren.begin(), mChildren.end(), - getSortTypeFromString("filename, ascending").comparisonFunction); for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) { // Build mFirstLetterIndex. const char firstChar = toupper((*it)->getSortName().front()); diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.cpp b/es-app/src/guis/GuiCollectionSystemsOptions.cpp index c429c54d7..e489cbcfb 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.cpp +++ b/es-app/src/guis/GuiCollectionSystemsOptions.cpp @@ -140,8 +140,8 @@ void GuiCollectionSystemsOptions::createCollection(std::string inName) { customOptionList->add(name, name, true); std::string outAuto = Utils::String::vectorToCommaString( autoOptionList->getSelectedObjects()); - std::string outCustom = Utils::String::vectorToCommaString( - customOptionList->getSelectedObjects()); + std::vector customSystems = customOptionList->getSelectedObjects(); + std::string outCustom = Utils::String::vectorToCommaString(customSystems, true); updateSettings(outAuto, outCustom); ViewController::get()->goToSystemView(newSys); @@ -164,27 +164,27 @@ GuiCollectionSystemsOptions::~GuiCollectionSystemsOptions() void GuiCollectionSystemsOptions::addSystemsToMenu() { - std::map autoSystems = + std::map autoSystems = CollectionSystemManager::get()->getAutoCollectionSystems(); autoOptionList = std::make_shared> (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); // Add automatic systems. - for (std::map::const_iterator it = autoSystems.cbegin(); - it != autoSystems.cend() ; it++ ) + for (std::map::const_iterator + it = autoSystems.cbegin(); it != autoSystems.cend() ; it++) autoOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); mMenu.addWithLabel("AUTOMATIC GAME COLLECTIONS", autoOptionList); - std::map customSystems = + std::map customSystems = CollectionSystemManager::get()->getCustomCollectionSystems(); customOptionList = std::make_shared> (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); // Add custom systems. - for (std::map::const_iterator it = customSystems.cbegin(); - it != customSystems.cend() ; it++ ) + for (std::map::const_iterator + it = customSystems.cbegin(); it != customSystems.cend() ; it++) customOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); mMenu.addWithLabel("CUSTOM GAME COLLECTIONS", customOptionList); } @@ -194,8 +194,8 @@ void GuiCollectionSystemsOptions::applySettings() std::string outAuto = Utils::String::vectorToCommaString( autoOptionList->getSelectedObjects()); std::string prevAuto = Settings::getInstance()->getString("CollectionSystemsAuto"); - std::string outCustom = Utils::String::vectorToCommaString( - customOptionList->getSelectedObjects()); + std::vector customSystems = customOptionList->getSelectedObjects(); + std::string outCustom = Utils::String::vectorToCommaString(customSystems, true); std::string prevCustom = Settings::getInstance()->getString("CollectionSystemsCustom"); bool outSort = sortFavFirstCustomSwitch->getState(); bool prevSort = Settings::getInstance()->getBool("FavFirstCustom"); diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 47825f90e..499629f3e 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -144,7 +144,7 @@ GuiGamelistOptions::GuiGamelistOptions( } } - std::map customCollections = + std::map customCollections = CollectionSystemManager::get()->getCustomCollectionSystems(); if (UIModeController::getInstance()->isUIModeFull() &&