mirror of
https://github.com/rvtr/TDT.git
synced 2025-10-31 13:51:07 -04:00
Alphabetically sort lists
This commit is contained in:
parent
ccf02d7ab9
commit
923676b24a
@ -160,6 +160,8 @@ static void generateList(Menu* m)
|
|||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
sortMenuItems(m);
|
||||||
|
|
||||||
m->nextPage = done;
|
m->nextPage = done;
|
||||||
|
|
||||||
if (m->cursor >= m->itemCount)
|
if (m->cursor >= m->itemCount)
|
||||||
|
|||||||
@ -221,6 +221,8 @@ static void generateList(Menu* m)
|
|||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
sortMenuItems(m);
|
||||||
|
|
||||||
m->nextPage = done;
|
m->nextPage = done;
|
||||||
|
|
||||||
if (m->cursor >= m->itemCount)
|
if (m->cursor >= m->itemCount)
|
||||||
|
|||||||
@ -56,6 +56,24 @@ void addMenuItem(Menu* m, char const* label, char const* value, bool directory)
|
|||||||
m->itemCount += 1;
|
m->itemCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int alphabeticalCompare(const void* a, const void* b)
|
||||||
|
{
|
||||||
|
const Item* itemA = (const Item*)a;
|
||||||
|
const Item* itemB = (const Item*)b;
|
||||||
|
|
||||||
|
if (itemA->directory && !itemB->directory)
|
||||||
|
return -1;
|
||||||
|
else if (!itemA->directory && itemB->directory)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return strcasecmp(itemA->label, itemB->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortMenuItems(Menu* m)
|
||||||
|
{
|
||||||
|
qsort(m->items, m->itemCount, sizeof(Item), alphabeticalCompare);
|
||||||
|
}
|
||||||
|
|
||||||
void setMenuHeader(Menu* m, char* str)
|
void setMenuHeader(Menu* m, char* str)
|
||||||
{
|
{
|
||||||
if (!m) return;
|
if (!m) return;
|
||||||
|
|||||||
@ -25,6 +25,7 @@ Menu* newMenu();
|
|||||||
void freeMenu(Menu* m);
|
void freeMenu(Menu* m);
|
||||||
|
|
||||||
void addMenuItem(Menu* m, char const* label, char const* value, bool directory);
|
void addMenuItem(Menu* m, char const* label, char const* value, bool directory);
|
||||||
|
void sortMenuItems(Menu* m);
|
||||||
void setMenuHeader(Menu* m, char* str);
|
void setMenuHeader(Menu* m, char* str);
|
||||||
|
|
||||||
void resetMenu(Menu* m);
|
void resetMenu(Menu* m);
|
||||||
|
|||||||
@ -174,6 +174,8 @@ static void generateList(Menu* m)
|
|||||||
free(dirPath);
|
free(dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortMenuItems(m);
|
||||||
|
|
||||||
m->nextPage = done;
|
m->nextPage = done;
|
||||||
|
|
||||||
if (m->cursor >= m->itemCount)
|
if (m->cursor >= m->itemCount)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user