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