Date: | 2015-04-22 19:42:47 (7 years 1 month ago) |
---|---|
Author: | Maarten ter Huurne |
Commit: | 9ca019ef513cdaaea64a283dd8f12c9c57787627 |
Message: | 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. |
Files: |
src/menu.cpp (3 diffs) |
Change Details
src/menu.cpp | ||
---|---|---|
78 | 78 | readSections(GMENU2X_SYSTEM_DIR "/sections"); |
79 | 79 | readSections(GMenu2X::getHome() + "/sections"); |
80 | 80 | |
81 | sort(sections.begin(),sections.end(),case_less()); | |
82 | 81 | setSectionIndex(0); |
83 | 82 | readLinks(); |
84 | 83 | |
... | ... | |
118 | 117 | if (!dirp) return; |
119 | 118 | |
120 | 119 | while ((dptr = readdir(dirp))) { |
121 | if (dptr->d_name[0] == '.' || dptr->d_type != DT_DIR) | |
122 | continue; | |
123 | ||
124 | if (find(sections.begin(), sections.end(), dptr->d_name) == sections.end()) { | |
125 | sections.emplace_back(dptr->d_name); | |
126 | vector<Link*> ll; | |
127 | links.push_back(ll); | |
120 | if (dptr->d_name[0] != '.' && dptr->d_type == DT_DIR) { | |
121 | // Create section if it doesn't exist yet. | |
122 | sectionNamed(dptr->d_name); | |
128 | 123 | } |
129 | 124 | } |
130 | 125 | |
... | ... | |
516 | 511 | |
517 | 512 | int Menu::sectionNamed(const char *sectionName) |
518 | 513 | { |
519 | auto it = find(sections.begin(), sections.end(), sectionName); | |
514 | auto it = lower_bound(sections.begin(), sections.end(), sectionName); | |
520 | 515 | int idx = it - sections.begin(); |
521 | if (it == sections.end()) { | |
522 | sections.emplace_back(sectionName); | |
523 | links.emplace_back(); | |
516 | if (it == sections.end() || *it != sectionName) { | |
517 | sections.emplace(it, sectionName); | |
518 | links.emplace(links.begin() + idx); | |
524 | 519 | } |
525 | 520 | return idx; |
526 | 521 | } |
Branches:
install_locations
master
opkrun
packages