GUI: Put an "up" entry in file browser

This commit is contained in:
Jeffrey Pfau 2015-08-25 22:46:34 -07:00
parent d67844e95f
commit 3f78362a3e
1 changed files with 17 additions and 11 deletions

View File

@ -15,7 +15,7 @@ DEFINE_VECTOR(FileList, char*);
static void _cleanFiles(struct FileList* currentFiles) { static void _cleanFiles(struct FileList* currentFiles) {
size_t size = FileListSize(currentFiles); size_t size = FileListSize(currentFiles);
size_t i; size_t i;
for (i = 0; i < size; ++i) { for (i = 1; i < size; ++i) {
free(*FileListGetPointer(currentFiles, i)); free(*FileListGetPointer(currentFiles, i));
} }
FileListClear(currentFiles); FileListClear(currentFiles);
@ -44,6 +44,7 @@ static bool _refreshDirectory(const char* currentPath, struct FileList* currentF
if (!dir) { if (!dir) {
return false; return false;
} }
*FileListAppend(currentFiles) = "(Up)";
struct VDirEntry* de; struct VDirEntry* de;
while ((de = dir->listNext(dir))) { while ((de = dir->listNext(dir))) {
const char* name = de->name(de); const char* name = de->name(de);
@ -111,17 +112,22 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
FileListDeinit(&currentFiles); FileListDeinit(&currentFiles);
return false; return false;
} }
if (newInput & (1 << GUI_INPUT_SELECT) && FileListSize(&currentFiles)) { if (newInput & (1 << GUI_INPUT_SELECT)) {
size_t len = strlen(currentPath); if (fileIndex == 0) {
const char* sep = PATH_SEP; _upDirectory(currentPath);
if (currentPath[len - 1] == *sep) { _refreshDirectory(currentPath, &currentFiles, filter);
sep = ""; } 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);
} }
snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(&currentFiles, fileIndex));
if (!_refreshDirectory(outPath, &currentFiles, filter)) {
return true;
}
strncpy(currentPath, outPath, outLen);
fileIndex = 0; fileIndex = 0;
} }
if (newInput & (1 << GUI_INPUT_BACK)) { if (newInput & (1 << GUI_INPUT_BACK)) {