From b2aef2cdaa71afb04f5d6d0dee55bb21c63bcbae Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Tue, 9 Apr 2013 23:24:42 +0000 Subject: [PATCH] -sorting plugins by display names now so they are displayed ordered in the plugin menu -using the newly created sort function for covers too now so we dont need to use two separate ones (covers should be sorted same way still) --- source/gui/coverflow.cpp | 18 +++--------------- source/gui/text.cpp | 14 ++++++++++++++ source/gui/text.hpp | 1 + source/plugin/plugin.cpp | 10 +++++++++- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index eb5666f5..24952259 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -1823,21 +1823,9 @@ bool CCoverFlow::_sortByGameID(CItem item1, CItem item2) bool CCoverFlow::_sortByAlpha(CItem item1, CItem item2) { - u32 s = min(wcslen(item1.hdr->title), wcslen(item2.hdr->title)); - wstringEx title1 = item1.hdr->title; - wstringEx title2 = item2.hdr->title; - - for (u32 j = 0, k = 0; j < s && k < s; ++j && ++k) - { - while (!iswalnum(title1[j]) && j < s) j++; - while (!iswalnum(title2[k]) && k < s) k++; - - if (upperCaseWChar(title1[j]) < upperCaseWChar(title2[k])) - return true; - else if(upperCaseWChar(title1[j]) > upperCaseWChar(title2[k])) - return false; - } - return title1.length() < title2.length(); + const wchar_t *first = item1.hdr->title; + const wchar_t *second = item2.hdr->title; + return wchar_cmp(first, second, wcslen(first), wcslen(second)); } bool CCoverFlow::_sortByPlayers(CItem item1, CItem item2) diff --git a/source/gui/text.cpp b/source/gui/text.cpp index f53d1fb8..5bec68cf 100644 --- a/source/gui/text.cpp +++ b/source/gui/text.cpp @@ -443,3 +443,17 @@ string rtrim(string s) s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), s.end()); return s; } + +bool wchar_cmp(const wchar_t *first, const wchar_t *second, u32 first_len, u32 second_len) +{ + u32 i = 0; + while((i < first_len) && (i < second_len)) + { + if(tolower(first[i]) < tolower(second[i])) + return true; + else if(tolower(first[i]) > tolower(second[i])) + return false; + ++i; + } + return first_len < second_len; +} diff --git a/source/gui/text.hpp b/source/gui/text.hpp index db1bce87..5f74fb53 100644 --- a/source/gui/text.hpp +++ b/source/gui/text.hpp @@ -68,5 +68,6 @@ std::string upperCase(std::string text); std::string lowerCase(std::string text); std::string ltrim(std::string s); std::string rtrim(std::string s); +bool wchar_cmp(const wchar_t *first, const wchar_t *second, u32 first_len, u32 second_len); #endif // !defined(__TEXT_HPP) diff --git a/source/plugin/plugin.cpp b/source/plugin/plugin.cpp index 09a2fa5b..155bbd02 100644 --- a/source/plugin/plugin.cpp +++ b/source/plugin/plugin.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include #include "plugin.hpp" #include "gui/text.hpp" #include "gecko/gecko.hpp" @@ -37,8 +37,16 @@ void Plugin::init(const string& m_pluginsDir) adding = true; } +static bool PluginOptions_cmp(PluginOptions lhs, PluginOptions rhs) +{ + const wchar_t *first = lhs.DisplayName.c_str(); + const wchar_t *second = rhs.DisplayName.c_str(); + return wchar_cmp(first, second, wcslen(first), wcslen(second)); +} + void Plugin::EndAdd() { + std::sort(Plugins.begin(), Plugins.end(), PluginOptions_cmp); adding = false; }