all repos — mgba @ ccaec37867d2a54d5cd5a56a43df48206d729741

mGBA Game Boy Advance Emulator

GUI: Use trailing slashes for folders in file selector
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Dec 2015 21:58:23 -0800
commit

ccaec37867d2a54d5cd5a56a43df48206d729741

parent

e89837909b3bfc8f1bd4d6740f5f25603611e654

1 files changed, 14 insertions(+), 9 deletions(-)

jump to
M src/util/gui/file-select.csrc/util/gui/file-select.c

@@ -35,15 +35,12 @@ if (!end) {

currentPath[0] = '\0'; return; } - if (end == currentPath) { - end[1] = '\0'; - return; + if (!end[1]) { + // Trailing slash + end[0] = '\0'; + return _upDirectory(currentPath); } - end[0] = '\0'; - if (end[1]) { - return; - } - // TODO: What if there was a trailing slash? + end[1] = '\0'; } static int _strpcmp(const void* a, const void* b) {

@@ -85,7 +82,15 @@ const char* name = de->name(de);

if (name[0] == '.') { continue; } - *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = strdup(name) }; + if (de->type(de) == VFS_DIRECTORY) { + size_t len = strlen(name) + 2; + char* n2 = malloc(len); + snprintf(n2, len, "%s/", name); + name = n2; + } else { + name = strdup(name); + } + *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = name }; ++items; } qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp);