all repos — mgba @ 3f78362a3eaab1027c0dfdba060296b7e059fb7b

mGBA Game Boy Advance Emulator

GUI: Put an "up" entry in file browser
Jeffrey Pfau jeffrey@endrift.com
Tue, 25 Aug 2015 22:46:34 -0700
commit

3f78362a3eaab1027c0dfdba060296b7e059fb7b

parent

d67844e95fe95343efc7e45378b4a99859453cad

1 files changed, 17 insertions(+), 11 deletions(-)

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

@@ -15,7 +15,7 @@

static void _cleanFiles(struct FileList* currentFiles) { size_t size = FileListSize(currentFiles); size_t i; - for (i = 0; i < size; ++i) { + for (i = 1; i < size; ++i) { free(*FileListGetPointer(currentFiles, i)); } FileListClear(currentFiles);

@@ -44,6 +44,7 @@ struct VDir* dir = VDirOpen(currentPath);

if (!dir) { return false; } + *FileListAppend(currentFiles) = "(Up)"; struct VDirEntry* de; while ((de = dir->listNext(dir))) { const char* name = de->name(de);

@@ -111,17 +112,22 @@ _cleanFiles(&currentFiles);

FileListDeinit(&currentFiles); return false; } - if (newInput & (1 << GUI_INPUT_SELECT) && FileListSize(&currentFiles)) { - size_t len = strlen(currentPath); - const char* sep = PATH_SEP; - if (currentPath[len - 1] == *sep) { - sep = ""; - } - snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(&currentFiles, fileIndex)); - if (!_refreshDirectory(outPath, &currentFiles, filter)) { - return true; + if (newInput & (1 << GUI_INPUT_SELECT)) { + if (fileIndex == 0) { + _upDirectory(currentPath); + _refreshDirectory(currentPath, &currentFiles, filter); + } else { + size_t len = strlen(currentPath); + const char* sep = PATH_SEP; + if (currentPath[len - 1] == *sep) { + sep = ""; + } + snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(&currentFiles, fileIndex)); + if (!_refreshDirectory(outPath, &currentFiles, filter)) { + return true; + } + strncpy(currentPath, outPath, outLen); } - strncpy(currentPath, outPath, outLen); fileIndex = 0; } if (newInput & (1 << GUI_INPUT_BACK)) {