From 3f78362a3eaab1027c0dfdba060296b7e059fb7b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 25 Aug 2015 22:46:34 -0700 Subject: [PATCH] GUI: Put an "up" entry in file browser --- src/util/gui/file-select.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index bd9d299ec..9e969225f 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -15,7 +15,7 @@ DEFINE_VECTOR(FileList, char*); 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 @@ static bool _refreshDirectory(const char* currentPath, struct FileList* currentF 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 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP FileListDeinit(¤tFiles); return false; } - if (newInput & (1 << GUI_INPUT_SELECT) && FileListSize(¤tFiles)) { - size_t len = strlen(currentPath); - const char* sep = PATH_SEP; - if (currentPath[len - 1] == *sep) { - sep = ""; + if (newInput & (1 << GUI_INPUT_SELECT)) { + if (fileIndex == 0) { + _upDirectory(currentPath); + _refreshDirectory(currentPath, ¤tFiles, 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(¤tFiles, fileIndex)); + if (!_refreshDirectory(outPath, ¤tFiles, filter)) { + return true; + } + strncpy(currentPath, outPath, outLen); } - snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex)); - if (!_refreshDirectory(outPath, ¤tFiles, filter)) { - return true; - } - strncpy(currentPath, outPath, outLen); fileIndex = 0; } if (newInput & (1 << GUI_INPUT_BACK)) {