Changed to case insensitive sorting of the custom collections.

This commit is contained in:
Leon Styhre 2020-10-22 21:23:16 +02:00
parent ab87063770
commit 127d900212
5 changed files with 41 additions and 36 deletions

View file

@ -92,7 +92,7 @@ CollectionSystemManager::~CollectionSystemManager()
removeCollectionsFromDisplayedSystems(); removeCollectionsFromDisplayedSystems();
// Delete all custom collections. // Delete all custom collections.
for (std::map<std::string, CollectionSystemData>::const_iterator for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
it = mCustomCollectionSystemsData.cbegin(); it = mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend() ; it++) it != mCustomCollectionSystemsData.cend() ; it++)
delete it->second.system; delete it->second.system;
@ -232,7 +232,7 @@ void CollectionSystemManager::loadEnabledListFromSettings()
Settings::getInstance()->getString("CollectionSystemsAuto"), true); Settings::getInstance()->getString("CollectionSystemsAuto"), true);
// Iterate the map. // Iterate the map.
for (std::map<std::string, CollectionSystemData>::iterator for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
it = mAutoCollectionSystemsData.begin(); it = mAutoCollectionSystemsData.begin();
it != mAutoCollectionSystemsData.end() ; it++ ) { it != mAutoCollectionSystemsData.end() ; it++ ) {
@ -247,7 +247,7 @@ void CollectionSystemManager::loadEnabledListFromSettings()
Settings::getInstance()->getString("CollectionSystemsCustom"), true); Settings::getInstance()->getString("CollectionSystemsCustom"), true);
// Iterate the map. // Iterate the map.
for (std::map<std::string, CollectionSystemData>::iterator for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
it = mCustomCollectionSystemsData.begin(); it = mCustomCollectionSystemsData.begin();
it != mCustomCollectionSystemsData.end() ; it++ ) { it != mCustomCollectionSystemsData.end() ; it++ ) {
@ -719,7 +719,7 @@ SystemData* CollectionSystemManager::getSystemToView(SystemData* sys)
// Loads Automatic Collection systems (All, Favorites, Last Played). // Loads Automatic Collection systems (All, Favorites, Last Played).
void CollectionSystemManager::initAutoCollectionSystems() void CollectionSystemManager::initAutoCollectionSystems()
{ {
for (std::map<std::string, CollectionSystemDecl>::const_iterator for (std::map<std::string, CollectionSystemDecl, stringComparator>::const_iterator
it = mCollectionSystemDeclsIndex.cbegin(); it = mCollectionSystemDeclsIndex.cbegin();
it != mCollectionSystemDeclsIndex.cend() ; it++ ) { it != mCollectionSystemDeclsIndex.cend() ; it++ ) {
CollectionSystemDecl sysDecl = it->second; CollectionSystemDecl sysDecl = it->second;
@ -824,8 +824,8 @@ SystemData* CollectionSystemManager::addNewCustomCollection(std::string name)
SystemData* CollectionSystemManager::createNewCollectionEntry( SystemData* CollectionSystemManager::createNewCollectionEntry(
std::string name, CollectionSystemDecl sysDecl, bool index, bool custom) std::string name, CollectionSystemDecl sysDecl, bool index, bool custom)
{ {
SystemData* newSys = new SystemData( SystemData* newSys = new SystemData(name, sysDecl.longName,
name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true, custom); mCollectionEnvData, sysDecl.themeFolder, true, custom);
CollectionSystemData newCollectionData; CollectionSystemData newCollectionData;
newCollectionData.system = newSys; newCollectionData.system = newSys;
@ -976,10 +976,10 @@ void CollectionSystemManager::removeCollectionsFromDisplayedSystems()
} }
void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems( void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems(
std::map<std::string, CollectionSystemData>* colSystemData) std::map<std::string, CollectionSystemData, stringComparator>* colSystemData)
{ {
// Add auto enabled collections. // Add auto enabled collections.
for (std::map<std::string, CollectionSystemData>::iterator for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
it = colSystemData->begin() ; it != colSystemData->end() ; it++ ) { it = colSystemData->begin() ; it != colSystemData->end() ; it++ ) {
if (it->second.isEnabled) { if (it->second.isEnabled) {
// Check if populated, otherwise populate. // Check if populated, otherwise populate.
@ -1155,7 +1155,7 @@ std::vector<std::string> CollectionSystemManager::getCollectionsFromConfigFolder
std::vector<std::string> CollectionSystemManager::getCollectionThemeFolders(bool custom) std::vector<std::string> CollectionSystemManager::getCollectionThemeFolders(bool custom)
{ {
std::vector<std::string> systems; std::vector<std::string> systems;
for (std::map<std::string, CollectionSystemDecl>::const_iterator for (std::map<std::string, CollectionSystemDecl, stringComparator>::const_iterator
it = mCollectionSystemDeclsIndex.cbegin(); it = mCollectionSystemDeclsIndex.cbegin();
it != mCollectionSystemDeclsIndex.cend() ; it++ ) { it != mCollectionSystemDeclsIndex.cend() ; it++ ) {
CollectionSystemDecl sysDecl = it->second; CollectionSystemDecl sysDecl = it->second;
@ -1169,7 +1169,7 @@ std::vector<std::string> CollectionSystemManager::getCollectionThemeFolders(bool
std::vector<std::string> CollectionSystemManager::getUserCollectionThemeFolders() std::vector<std::string> CollectionSystemManager::getUserCollectionThemeFolders()
{ {
std::vector<std::string> systems; std::vector<std::string> systems;
for (std::map<std::string, CollectionSystemData>::const_iterator for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
it = mCustomCollectionSystemsData.cbegin(); it = mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend() ; it++ ) it != mCustomCollectionSystemsData.cend() ; it++ )
systems.push_back(it->second.decl.themeFolder); systems.push_back(it->second.decl.themeFolder);
@ -1213,7 +1213,7 @@ bool systemSort(SystemData* sys1, SystemData* sys2)
bool CollectionSystemManager::getIsCustomCollection(SystemData* system) bool CollectionSystemManager::getIsCustomCollection(SystemData* system)
{ {
// Iterate the map. // Iterate the map.
for (std::map<std::string, CollectionSystemData>::const_iterator for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
it = mCustomCollectionSystemsData.cbegin(); it = mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend() ; it++) { it != mCustomCollectionSystemsData.cend() ; it++) {
if (it->second.system == system) if (it->second.system == system)

View file

@ -22,6 +22,8 @@
#ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H #ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H
#define ES_APP_COLLECTION_SYSTEM_MANAGER_H #define ES_APP_COLLECTION_SYSTEM_MANAGER_H
#include "utils/StringUtil.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
@ -53,6 +55,13 @@ struct CollectionSystemData {
bool isPopulated; 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 class CollectionSystemManager
{ {
public: public:
@ -72,10 +81,10 @@ public:
void updateCollectionSystem(FileData* file, CollectionSystemData sysData); void updateCollectionSystem(FileData* file, CollectionSystemData sysData);
void deleteCollectionFiles(FileData* file); void deleteCollectionFiles(FileData* file);
inline std::map<std::string, CollectionSystemData> getAutoCollectionSystems() inline std::map<std::string, CollectionSystemData, stringComparator>
{ return mAutoCollectionSystemsData; }; getAutoCollectionSystems() { return mAutoCollectionSystemsData; };
inline std::map<std::string, CollectionSystemData> getCustomCollectionSystems() inline std::map<std::string, CollectionSystemData, stringComparator>
{ return mCustomCollectionSystemsData; }; getCustomCollectionSystems() { return mCustomCollectionSystemsData; };
inline SystemData* getCustomCollectionsBundle() { return mCustomCollectionsBundle; }; inline SystemData* getCustomCollectionsBundle() { return mCustomCollectionsBundle; };
std::vector<std::string> getUnusedSystemsFromTheme(); std::vector<std::string> getUnusedSystemsFromTheme();
SystemData* addNewCustomCollection(std::string name); SystemData* addNewCustomCollection(std::string name);
@ -98,9 +107,9 @@ public:
private: private:
static CollectionSystemManager* sInstance; static CollectionSystemManager* sInstance;
SystemEnvironmentData* mCollectionEnvData; SystemEnvironmentData* mCollectionEnvData;
std::map<std::string, CollectionSystemDecl> mCollectionSystemDeclsIndex; std::map<std::string, CollectionSystemDecl, stringComparator> mCollectionSystemDeclsIndex;
std::map<std::string, CollectionSystemData> mAutoCollectionSystemsData; std::map<std::string, CollectionSystemData, stringComparator> mAutoCollectionSystemsData;
std::map<std::string, CollectionSystemData> mCustomCollectionSystemsData; std::map<std::string, CollectionSystemData, stringComparator> mCustomCollectionSystemsData;
Window* mWindow; Window* mWindow;
bool mIsEditingCustom; bool mIsEditingCustom;
bool mHasEnabledCustomCollection; bool mHasEnabledCustomCollection;
@ -117,7 +126,7 @@ private:
void removeCollectionsFromDisplayedSystems(); void removeCollectionsFromDisplayedSystems();
void addEnabledCollectionsToDisplayedSystems(std::map<std::string, void addEnabledCollectionsToDisplayedSystems(std::map<std::string,
CollectionSystemData>* colSystemData); CollectionSystemData, stringComparator>* colSystemData);
std::vector<std::string> getSystemsFromConfig(); std::vector<std::string> getSystemsFromConfig();
std::vector<std::string> getSystemsFromTheme(); std::vector<std::string> getSystemsFromTheme();

View file

@ -447,11 +447,9 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending,
std::vector<FileData*> mChildrenFolders; std::vector<FileData*> mChildrenFolders;
std::vector<FileData*> mChildrenOthers; std::vector<FileData*> 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. // The individual collections are however sorted as any normal systems/folders.
if (mSystem->isCollection() && mSystem->getFullName() == "collections") { 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++) { for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
// Build mFirstLetterIndex. // Build mFirstLetterIndex.
const char firstChar = toupper((*it)->getSortName().front()); 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 foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
bool hasFolders = false; 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. // The individual collections are however sorted as any normal systems/folders.
if (mSystem->isCollection() && mSystem->getFullName() == "collections") { 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++) { for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
// Build mFirstLetterIndex. // Build mFirstLetterIndex.
const char firstChar = toupper((*it)->getSortName().front()); const char firstChar = toupper((*it)->getSortName().front());

View file

@ -140,8 +140,8 @@ void GuiCollectionSystemsOptions::createCollection(std::string inName) {
customOptionList->add(name, name, true); customOptionList->add(name, name, true);
std::string outAuto = Utils::String::vectorToCommaString( std::string outAuto = Utils::String::vectorToCommaString(
autoOptionList->getSelectedObjects()); autoOptionList->getSelectedObjects());
std::string outCustom = Utils::String::vectorToCommaString( std::vector<std::string> customSystems = customOptionList->getSelectedObjects();
customOptionList->getSelectedObjects()); std::string outCustom = Utils::String::vectorToCommaString(customSystems, true);
updateSettings(outAuto, outCustom); updateSettings(outAuto, outCustom);
ViewController::get()->goToSystemView(newSys); ViewController::get()->goToSystemView(newSys);
@ -164,27 +164,27 @@ GuiCollectionSystemsOptions::~GuiCollectionSystemsOptions()
void GuiCollectionSystemsOptions::addSystemsToMenu() void GuiCollectionSystemsOptions::addSystemsToMenu()
{ {
std::map<std::string, CollectionSystemData> autoSystems = std::map<std::string, CollectionSystemData, stringComparator> autoSystems =
CollectionSystemManager::get()->getAutoCollectionSystems(); CollectionSystemManager::get()->getAutoCollectionSystems();
autoOptionList = std::make_shared<OptionListComponent<std::string>> autoOptionList = std::make_shared<OptionListComponent<std::string>>
(mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true);
// Add automatic systems. // Add automatic systems.
for (std::map<std::string, CollectionSystemData>::const_iterator it = autoSystems.cbegin(); for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
it != autoSystems.cend() ; it++ ) it = autoSystems.cbegin(); it != autoSystems.cend() ; it++)
autoOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); autoOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled);
mMenu.addWithLabel("AUTOMATIC GAME COLLECTIONS", autoOptionList); mMenu.addWithLabel("AUTOMATIC GAME COLLECTIONS", autoOptionList);
std::map<std::string, CollectionSystemData> customSystems = std::map<std::string, CollectionSystemData, stringComparator> customSystems =
CollectionSystemManager::get()->getCustomCollectionSystems(); CollectionSystemManager::get()->getCustomCollectionSystems();
customOptionList = std::make_shared<OptionListComponent<std::string>> customOptionList = std::make_shared<OptionListComponent<std::string>>
(mWindow, getHelpStyle(), "SELECT COLLECTIONS", true); (mWindow, getHelpStyle(), "SELECT COLLECTIONS", true);
// Add custom systems. // Add custom systems.
for (std::map<std::string, CollectionSystemData>::const_iterator it = customSystems.cbegin(); for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
it != customSystems.cend() ; it++ ) it = customSystems.cbegin(); it != customSystems.cend() ; it++)
customOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled); customOptionList->add(it->second.decl.longName, it->second.decl.name, it->second.isEnabled);
mMenu.addWithLabel("CUSTOM GAME COLLECTIONS", customOptionList); mMenu.addWithLabel("CUSTOM GAME COLLECTIONS", customOptionList);
} }
@ -194,8 +194,8 @@ void GuiCollectionSystemsOptions::applySettings()
std::string outAuto = Utils::String::vectorToCommaString( std::string outAuto = Utils::String::vectorToCommaString(
autoOptionList->getSelectedObjects()); autoOptionList->getSelectedObjects());
std::string prevAuto = Settings::getInstance()->getString("CollectionSystemsAuto"); std::string prevAuto = Settings::getInstance()->getString("CollectionSystemsAuto");
std::string outCustom = Utils::String::vectorToCommaString( std::vector<std::string> customSystems = customOptionList->getSelectedObjects();
customOptionList->getSelectedObjects()); std::string outCustom = Utils::String::vectorToCommaString(customSystems, true);
std::string prevCustom = Settings::getInstance()->getString("CollectionSystemsCustom"); std::string prevCustom = Settings::getInstance()->getString("CollectionSystemsCustom");
bool outSort = sortFavFirstCustomSwitch->getState(); bool outSort = sortFavFirstCustomSwitch->getState();
bool prevSort = Settings::getInstance()->getBool("FavFirstCustom"); bool prevSort = Settings::getInstance()->getBool("FavFirstCustom");

View file

@ -144,7 +144,7 @@ GuiGamelistOptions::GuiGamelistOptions(
} }
} }
std::map<std::string, CollectionSystemData> customCollections = std::map<std::string, CollectionSystemData, stringComparator> customCollections =
CollectionSystemManager::get()->getCustomCollectionSystems(); CollectionSystemManager::get()->getCustomCollectionSystems();
if (UIModeController::getInstance()->isUIModeFull() && if (UIModeController::getInstance()->isUIModeFull() &&