Merge pull request #282 from zigurana/JumpToLetterWhenFiltered

Allow JUMP TO...  in case of filtered lists
This commit is contained in:
Jools Wills 2017-11-05 08:30:30 +00:00 committed by GitHub
commit d53fdd3420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,39 +18,53 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
// check it's not a placeholder folder - if it is, only show "Filter Options"
FileData* file = getGamelist()->getCursor();
fromPlaceholder = file->isPlaceHolder();
bool isFiltered = system->getIndex()->isFiltered();
ComponentListRow row;
if (!fromPlaceholder) {
// jump to letter
row.elements.clear();
if (!isFiltered) {
// jump to letter
row.elements.clear();
char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
if(curChar < 'A' || curChar > 'Z')
curChar = 'A';
// define supported character range
// this range includes all numbers, capital letters, and most reasonable symbols
char startChar = '!';
char endChar = '_';
mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO LETTER", false);
for(char c = 'A'; c <= 'Z'; c++)
mJumpToLetterList->add(std::string(1, c), c, c == curChar);
char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
if(curChar < startChar || curChar > endChar)
curChar = startChar;
row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO LETTER", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.addElement(mJumpToLetterList, false);
row.input_handler = [&](InputConfig* config, Input input) {
if(config->isMappedTo("a", input) && input.value)
mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO...", false);
for (char c = startChar; c <= endChar; c++)
{
// check if c is a valid first letter in current list
const std::vector<FileData*>& files = getGamelist()->getCursor()->getParent()->getChildrenListToDisplay();
for (auto file : files)
{
char candidate = toupper(file->getName()[0]);
if (c == candidate)
{
jumpToLetter();
return true;
mJumpToLetterList->add(std::string(1, c), c, c == curChar);
break;
}
else if(mJumpToLetterList->input(config, input))
{
return true;
}
return false;
};
mMenu.addRow(row);
}
}
row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO...", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.addElement(mJumpToLetterList, false);
row.input_handler = [&](InputConfig* config, Input input) {
if(config->isMappedTo("a", input) && input.value)
{
jumpToLetter();
return true;
}
else if(mJumpToLetterList->input(config, input))
{
return true;
}
return false;
};
mMenu.addRow(row);
// sort list by
mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
@ -189,7 +203,7 @@ void GuiGamelistOptions::jumpToLetter()
IGameListView* gamelist = getGamelist();
// this is a really shitty way to get a list of files
const std::vector<FileData*>& files = gamelist->getCursor()->getParent()->getChildren();
const std::vector<FileData*>& files = gamelist->getCursor()->getParent()->getChildrenListToDisplay();
long min = 0;
long max = files.size() - 1;