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,7 +112,11 @@ 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)) {
if (fileIndex == 0) {
_upDirectory(currentPath);
_refreshDirectory(currentPath, &currentFiles, filter);
} else {
size_t len = strlen(currentPath); size_t len = strlen(currentPath);
const char* sep = PATH_SEP; const char* sep = PATH_SEP;
if (currentPath[len - 1] == *sep) { if (currentPath[len - 1] == *sep) {
@ -122,6 +127,7 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
return true; return true;
} }
strncpy(currentPath, outPath, outLen); strncpy(currentPath, outPath, outLen);
}
fileIndex = 0; fileIndex = 0;
} }
if (newInput & (1 << GUI_INPUT_BACK)) { if (newInput & (1 << GUI_INPUT_BACK)) {