mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-04 23:25:19 +02:00
Keep list of section names sorted at all times
Keeping it sorted when sections are inserted after startup improves the user experience and if we have code for that already, we might as well use it during startup too.
This commit is contained in:
parent
fad68bfb6e
commit
9ca019ef51
19
src/menu.cpp
19
src/menu.cpp
@ -78,7 +78,6 @@ Menu::Menu(GMenu2X& gmenu2x, Touchscreen &ts)
|
|||||||
readSections(GMENU2X_SYSTEM_DIR "/sections");
|
readSections(GMENU2X_SYSTEM_DIR "/sections");
|
||||||
readSections(GMenu2X::getHome() + "/sections");
|
readSections(GMenu2X::getHome() + "/sections");
|
||||||
|
|
||||||
sort(sections.begin(),sections.end(),case_less());
|
|
||||||
setSectionIndex(0);
|
setSectionIndex(0);
|
||||||
readLinks();
|
readLinks();
|
||||||
|
|
||||||
@ -118,13 +117,9 @@ void Menu::readSections(std::string parentDir)
|
|||||||
if (!dirp) return;
|
if (!dirp) return;
|
||||||
|
|
||||||
while ((dptr = readdir(dirp))) {
|
while ((dptr = readdir(dirp))) {
|
||||||
if (dptr->d_name[0] == '.' || dptr->d_type != DT_DIR)
|
if (dptr->d_name[0] != '.' && dptr->d_type == DT_DIR) {
|
||||||
continue;
|
// Create section if it doesn't exist yet.
|
||||||
|
sectionNamed(dptr->d_name);
|
||||||
if (find(sections.begin(), sections.end(), dptr->d_name) == sections.end()) {
|
|
||||||
sections.emplace_back(dptr->d_name);
|
|
||||||
vector<Link*> ll;
|
|
||||||
links.push_back(ll);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,11 +511,11 @@ bool Menu::addLink(string path, string file, string sectionName) {
|
|||||||
|
|
||||||
int Menu::sectionNamed(const char *sectionName)
|
int Menu::sectionNamed(const char *sectionName)
|
||||||
{
|
{
|
||||||
auto it = find(sections.begin(), sections.end(), sectionName);
|
auto it = lower_bound(sections.begin(), sections.end(), sectionName);
|
||||||
int idx = it - sections.begin();
|
int idx = it - sections.begin();
|
||||||
if (it == sections.end()) {
|
if (it == sections.end() || *it != sectionName) {
|
||||||
sections.emplace_back(sectionName);
|
sections.emplace(it, sectionName);
|
||||||
links.emplace_back();
|
links.emplace(links.begin() + idx);
|
||||||
}
|
}
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user