Skip to content

Commit

Permalink
Squashing branch
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilaPhan80 committed Feb 1, 2021
1 parent 771f2a6 commit 8f0aecc
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
33 changes: 33 additions & 0 deletions es-app/src/FileSorts.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "FileSorts.h"

#include "utils/StringUtil.h"
#include "Settings.h"
#include "Log.h"

namespace FileSorts
{

const FileData::SortType typesArr[] = {
FileData::SortType(&compareName, true, "filename, ascending"),
FileData::SortType(&compareName, false, "filename, descending"),
Expand Down Expand Up @@ -50,6 +53,9 @@ namespace FileSorts
if(name2.empty()){
name2 = Utils::String::toUpper(file2->metadata.get("name"));
}

ignoreLeadingArticles(name1, name2);

return name1.compare(name2) < 0;
}

Expand Down Expand Up @@ -115,4 +121,31 @@ namespace FileSorts
std::string system2 = Utils::String::toUpper(file2->getSystemName());
return system1.compare(system2) < 0;
}

//If option is enabled, ignore leading articles by temporarily modifying the name prior to sorting
//(Artciles are defined within the settings config file)
void ignoreLeadingArticles(std::string &name1, std::string &name2) {

if (Settings::getInstance()->getBool("IgnoreLeadingArticles"))
{

std::vector<std::string> articles = Utils::String::delimitedStringToVector(Settings::getInstance()->getString("LeadingArticles"), ",");

for(Utils::String::stringVector::iterator it = articles.begin(); it != articles.end(); it++)
{

if (Utils::String::startsWith(Utils::String::toUpper(name1), Utils::String::toUpper(it[0]) + " ")) {
name1 = Utils::String::replace(Utils::String::toUpper(name1), Utils::String::toUpper(it[0]) + " ", "");
}

if (Utils::String::startsWith(Utils::String::toUpper(name2), Utils::String::toUpper(it[0]) + " ")) {
name2 = Utils::String::replace(Utils::String::toUpper(name2), Utils::String::toUpper(it[0]) + " ", "");
}

}

}

}

};
2 changes: 2 additions & 0 deletions es-app/src/FileSorts.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace FileSorts
bool comparePublisher(const FileData* file1, const FileData* file2);
bool compareSystem(const FileData* file1, const FileData* file2);

void ignoreLeadingArticles(std::string &name1, std::string &name2);

extern const std::vector<FileData::SortType> SortTypes;
};

Expand Down
1 change: 1 addition & 0 deletions es-app/src/guis/GuiGamelistOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui

mMenu.addWithLabel("SORT GAMES BY", mListSort);
}

// show filtered menu
if(!Settings::getInstance()->getBool("ForceDisableFilters"))
{
Expand Down
29 changes: 29 additions & 0 deletions es-app/src/guis/GuiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <SDL_events.h>
#include <algorithm>
#include "platform.h"
#include "FileSorts.h"
#include "views/gamelist/IGameListView.h"
#include "guis/GuiInfoPopup.h"

GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MENU"), mVersion(window)
{
Expand Down Expand Up @@ -332,6 +335,32 @@ void GuiMenu::openUISettings()
ViewController::get()->reloadAll();
});

// Optionally ignore leading articles when sorting game titles
auto ignore_articles = std::make_shared<SwitchComponent>(mWindow);
ignore_articles->setState(Settings::getInstance()->getBool("IgnoreLeadingArticles"));
s->addWithLabel("IGNORE ARTICLES (NAME SORT ONLY)", ignore_articles);
s->addSaveFunc([ignore_articles, window] {
bool articles_are_ignored = Settings::getInstance()->getBool("IgnoreLeadingArticles");
Settings::getInstance()->setBool("IgnoreLeadingArticles", ignore_articles->getState());
if (ignore_articles->getState() != articles_are_ignored)
{
//For each system...
for (auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); it++)
{
//Apply sort recursively
FileData* root = (*it)->getRootFolder();
root->sort(FileSorts::SortTypes.at(Settings::getInstance()->getInt("SortType")));

//Notify that the root folder was sorted
ViewController::get()->getGameListView((*it))->onFileChanged(root, FILE_SORTED);
}

//Display popup to inform user
GuiInfoPopup* popup = new GuiInfoPopup(window, "Files sorted", 4000);
window->setInfoPopup(popup);
}
});

// Optionally start in selected system
auto systemfocus_list = std::make_shared< OptionListComponent<std::string> >(mWindow, "START ON SYSTEM", false);
systemfocus_list->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == "");
Expand Down
5 changes: 5 additions & 0 deletions es-app/src/guis/GuiMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "components/MenuComponent.h"
#include "GuiComponent.h"
#include "components/OptionListComponent.h"
#include "FileData.h"

class GuiMenu : public GuiComponent
{
Expand All @@ -29,6 +31,9 @@ class GuiMenu : public GuiComponent

MenuComponent mMenu;
TextComponent mVersion;

typedef OptionListComponent<const FileData::SortType*> SortList;
std::shared_ptr<SortList> mListSort;
};

#endif // ES_APP_GUIS_GUI_MENU_H
5 changes: 5 additions & 0 deletions es-core/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void Settings::setDefaults()
mIntMap["ScreenOffsetX"] = 0;
mIntMap["ScreenOffsetY"] = 0;
mIntMap["ScreenRotate"] = 0;

mBoolMap["IgnoreLeadingArticles"] = false;
//No spaces! Order is important!
//"The A Squad" given [a,an,the] will sort as "A Squad", but given [the,a,an] will sort as "Squad"
mStringMap["LeadingArticles"] = "a,an,the";
}

template <typename K, typename V>
Expand Down

0 comments on commit 8f0aecc

Please sign in to comment.