Added jump to folder to the quick selector and improved the folder sorting.

This commit is contained in:
Leon Styhre 2020-09-20 12:17:38 +02:00
parent 83bae1e963
commit d4e614c0c1
6 changed files with 47 additions and 23 deletions

View file

@ -430,6 +430,7 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending)
mFirstLetterIndex.clear();
mOnlyFolders = true;
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
bool hasFolders = false;
std::vector<FileData*> mChildrenFolders;
std::vector<FileData*> mChildrenOthers;
@ -452,17 +453,23 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending)
if (foldersOnTop) {
for (unsigned int i = 0; i < mChildren.size(); i++) {
if (mChildren[i]->getType() == FOLDER)
if (mChildren[i]->getType() == FOLDER) {
mChildrenFolders.push_back(mChildren[i]);
else
hasFolders = true;
}
else {
mChildrenOthers.push_back(mChildren[i]);
mOnlyFolders = false;
}
}
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
if (foldersOnTop && mOnlyFolders)
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(), comparator);
if (!ascending) {
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
if (foldersOnTop && mOnlyFolders)
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
std::reverse(mChildrenOthers.begin(), mChildrenOthers.end());
}
@ -505,6 +512,10 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending)
std::sort(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
auto last = std::unique(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
mFirstLetterIndex.erase(last, mFirstLetterIndex.end());
// If it's a mixed list and folders are sorted on top, add a folder icon to the index.
if (foldersOnTop && hasFolders && !mOnlyFolders)
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FOLDER_CHAR);
}
void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending)
@ -516,6 +527,7 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
std::vector<FileData*> mChildrenOthers;
bool showHiddenGames = Settings::getInstance()->getBool("ShowHiddenGames");
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
bool hasFolders = false;
for (unsigned int i = 0; i < mChildren.size(); i++) {
// Exclude game if it's marked as hidden and the hide setting has been set.
@ -527,6 +539,7 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
if (foldersOnTop && mChildren[i]->getType() == FOLDER) {
mChildrenFolders.push_back(mChildren[i]);
hasFolders = true;
}
else if (mChildren[i]->getFavorite()) {
mChildrenFavorites.push_back(mChildren[i]);
@ -576,8 +589,13 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
if (mChildrenOthers.size() > 0 && mChildrenFavorites.size() > 0)
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FAVORITE_CHAR);
// If it's a mixed list and folders are sorted on top, add a folder icon to the index.
if (foldersOnTop && hasFolders && !mOnlyFolders)
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FOLDER_CHAR);
// Sort favorite games and the other games separately.
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
if (foldersOnTop && mOnlyFolders)
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
std::stable_sort(mChildrenFavorites.begin(), mChildrenFavorites.end(), comparator);
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(), comparator);
@ -600,7 +618,8 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
}
if (!ascending) {
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
if (foldersOnTop && mOnlyFolders)
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
std::reverse(mChildrenFavorites.begin(), mChildrenFavorites.end());
std::reverse(mChildrenOthers.begin(), mChildrenOthers.end());
}

View file

@ -132,6 +132,9 @@ public:
// Return sort type based on a string description.
FileData::SortType getSortTypeFromString(std::string desc);
const std::string FAVORITE_CHAR = "\uF005";
const std::string FOLDER_CHAR = "\uF07C";
protected:
FileData* mSourceFileData;
FileData* mParent;
@ -150,7 +153,7 @@ private:
bool mOnlyFolders;
// Used for flagging a game for deletion from its gamelist.xml file.
bool mDeletionFlag;
const std::string FAVORITE_CHAR = "\uF005";
};
class CollectionFileData : public FileData

View file

@ -38,6 +38,8 @@ GuiGamelistOptions::GuiGamelistOptions(
// Check that it's not a placeholder folder - if it is, only show "Filter Options".
FileData* file = getGamelist()->getCursor();
FAVORITE_CHAR = file->FAVORITE_CHAR;
FOLDER_CHAR = file->FOLDER_CHAR;
fromPlaceholder = file->isPlaceHolder();
ComponentListRow row;
@ -64,17 +66,14 @@ GuiGamelistOptions::GuiGamelistOptions(
// Don't include the folder name starting characters if folders are sorted on top
// unless the list only contains folders.
if (!mOnlyHasFolders && mFoldersOnTop && file->getType() == FOLDER) {
mCurrentFirstCharacter = mFirstLetterIndex.front();
mCurrentFirstCharacter = FOLDER_CHAR;
}
else {
// Set the quick selector to the first character of the selected game.
if (mFavoritesSorting && file->getFavorite() &&
mFirstLetterIndex.front() == FAVORITE_CHAR) {
mFirstLetterIndex.front() == FAVORITE_CHAR)
mCurrentFirstCharacter = FAVORITE_CHAR;
}
else {
else
mCurrentFirstCharacter = toupper(file->getSortName().front());
}
}
mJumpToLetterList = std::make_shared<LetterList>(mWindow, getHelpStyle(),
@ -201,10 +200,9 @@ GuiGamelistOptions::~GuiGamelistOptions()
}
// Has the user changed the letter using the quick selector?
if ((mFoldersOnTop && !mOnlyHasFolders &&
getGamelist()->getCursor()->getType() == FOLDER) ||
mCurrentFirstCharacter != mJumpToLetterList->getSelected()) {
if (mJumpToLetterList->getSelected() == FAVORITE_CHAR)
if (mCurrentFirstCharacter != mJumpToLetterList->getSelected()) {
if (mJumpToLetterList->getSelected() == FAVORITE_CHAR ||
mJumpToLetterList->getSelected() == FOLDER_CHAR)
jumpToFirstRow();
else
jumpToLetter();
@ -359,7 +357,7 @@ void GuiGamelistOptions::jumpToLetter()
void GuiGamelistOptions::jumpToFirstRow()
{
if (mFoldersOnTop) {
if (mFoldersOnTop && mJumpToLetterList->getSelected() == FAVORITE_CHAR) {
// Get the gamelist.
const std::vector<FileData*>& files = getGamelist()->getCursor()->
getParent()->getChildrenListToDisplay();

View file

@ -59,7 +59,8 @@ private:
bool mCancelled;
std::vector<std::string> mFirstLetterIndex;
std::string mCurrentFirstCharacter;
const std::string FAVORITE_CHAR = "\uF005";
std::string FAVORITE_CHAR;
std::string FOLDER_CHAR;
};

View file

@ -18,6 +18,9 @@
BasicGameListView::BasicGameListView(Window* window, FileData* root)
: ISimpleGameListView(window, root), mList(window)
{
FAVORITE_CHAR = root->FAVORITE_CHAR;
FOLDER_CHAR = root->FOLDER_CHAR;
mList.setSize(mSize.x(), mSize.y() * 0.8f);
mList.setPosition(0, mSize.y() * 0.2f);
mList.setDefaultZIndex(20);
@ -59,12 +62,12 @@ void BasicGameListView::populateList(const std::vector<FileData*>& files)
if ((*it)->getFavorite() &&
mRoot->getSystem()->getName() != "favorites") {
mList.add(FAVORITE_GAME_CHAR + " " + (*it)->getName(),
mList.add(FAVORITE_CHAR + " " + (*it)->getName(),
*it, ((*it)->getType() == FOLDER));
}
else if ((*it)->getType() == FOLDER &&
mRoot->getSystem()->getName() != "collections") {
mList.add(FAVORITE_FOLDER_CHAR + " " + (*it)->getName(), *it, true);
mList.add(FOLDER_CHAR + " " + (*it)->getName(), *it, true);
}
else {
mList.add((*it)->getName(), *it, ((*it)->getType() == FOLDER));

View file

@ -50,8 +50,8 @@ protected:
// Points to the first game in the list, i.e. the first entry which is of the type 'GAME'.
FileData* firstGameEntry;
const std::string FAVORITE_GAME_CHAR = "\uF005";
const std::string FAVORITE_FOLDER_CHAR = "\uF07C";
std::string FAVORITE_CHAR;
std::string FOLDER_CHAR;
};
#endif // ES_APP_VIEWS_GAME_LIST_BASIC_GAME_LIST_VIEW_H