-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)
This commit is contained in:
fix94.1 2013-04-09 23:24:42 +00:00
parent 3e62aeb278
commit b2aef2cdaa
4 changed files with 27 additions and 16 deletions

View File

@ -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)

View File

@ -443,3 +443,17 @@ string rtrim(string s)
s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(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;
}

View File

@ -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)

View File

@ -19,7 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <algorithm>
#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;
}