GUI: Put an "up" entry in file browser
Jeffrey Pfau jeffrey@endrift.com
Tue, 25 Aug 2015 22:46:34 -0700
1 files changed,
17 insertions(+),
11 deletions(-)
jump to
M
src/util/gui/file-select.c
→
src/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(¤tFiles);
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 = ""; - } - snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex)); - if (!_refreshDirectory(outPath, ¤tFiles, filter)) { - return true; + 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); } - strncpy(currentPath, outPath, outLen); fileIndex = 0; } if (newInput & (1 << GUI_INPUT_BACK)) {