mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-27 11:33:06 +00:00
j
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@404 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
#include "../external/stb_ds.h"
|
#include "../external/stb_ds.h"
|
||||||
|
|
||||||
typedef struct filechooser {
|
typedef struct filechooser {
|
||||||
|
char* path;
|
||||||
|
|
||||||
|
MwDirectoryEntry** entries;
|
||||||
|
|
||||||
MwWidget nav;
|
MwWidget nav;
|
||||||
MwWidget files;
|
MwWidget files;
|
||||||
MwWidget addr;
|
MwWidget addr;
|
||||||
@@ -25,6 +29,10 @@ typedef struct filechooser {
|
|||||||
|
|
||||||
static void destroy(MwWidget handle) {
|
static void destroy(MwWidget handle) {
|
||||||
filechooser_t* fc = handle->opaque;
|
filechooser_t* fc = handle->opaque;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(fc->entries); i++) MwDirectoryFreeEntry(fc->entries[i]);
|
||||||
|
arrfree(fc->entries);
|
||||||
|
|
||||||
MwLLDestroyPixmap(fc->dir);
|
MwLLDestroyPixmap(fc->dir);
|
||||||
MwLLDestroyPixmap(fc->file);
|
MwLLDestroyPixmap(fc->file);
|
||||||
@@ -253,20 +261,26 @@ static int qsort_files(const void* a, const void* b) {
|
|||||||
static void scan(MwWidget handle, const char* path) {
|
static void scan(MwWidget handle, const char* path) {
|
||||||
filechooser_t* fc = handle->opaque;
|
filechooser_t* fc = handle->opaque;
|
||||||
void* dir = MwDirectoryOpen(path);
|
void* dir = MwDirectoryOpen(path);
|
||||||
MwDirectoryEntry** entries = NULL;
|
|
||||||
int i;
|
int i;
|
||||||
char** names = NULL;
|
char** names = NULL;
|
||||||
char** dates = NULL;
|
char** dates = NULL;
|
||||||
char** sizes = NULL;
|
char** sizes = NULL;
|
||||||
MwLLPixmap* icons = NULL;
|
MwLLPixmap* icons = NULL;
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(fc->entries); i++) MwDirectoryFreeEntry(fc->entries[i]);
|
||||||
|
arrfree(fc->entries);
|
||||||
|
|
||||||
if(dir != NULL) {
|
if(dir != NULL) {
|
||||||
MwDirectoryEntry* entry;
|
MwDirectoryEntry* entry;
|
||||||
while((entry = MwDirectoryRead(dir)) != NULL) arrput(entries, entry);
|
while((entry = MwDirectoryRead(dir)) != NULL) arrput(fc->entries, entry);
|
||||||
MwDirectoryClose(dir);
|
MwDirectoryClose(dir);
|
||||||
|
|
||||||
qsort(entries, arrlen(entries), sizeof(MwDirectoryEntry*), qsort_files);
|
qsort(fc->entries, arrlen(fc->entries), sizeof(MwDirectoryEntry*), qsort_files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(fc->path != NULL) free(fc->path);
|
||||||
|
fc->path = MwStringDupliacte(path);
|
||||||
|
|
||||||
MwVaApply(fc->addr,
|
MwVaApply(fc->addr,
|
||||||
MwNtext, path,
|
MwNtext, path,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -281,28 +295,28 @@ static void scan(MwWidget handle, const char* path) {
|
|||||||
names = NULL;
|
names = NULL;
|
||||||
dates = NULL;
|
dates = NULL;
|
||||||
sizes = NULL;
|
sizes = NULL;
|
||||||
for(i = 0; i < arrlen(entries); i++) {
|
for(i = 0; i < arrlen(fc->entries); i++) {
|
||||||
if(strcmp(entries[i]->name, ".") == 0 || strcmp(entries[i]->name, "..") == 0) continue;
|
if(strcmp(fc->entries[i]->name, ".") == 0 || strcmp(fc->entries[i]->name, "..") == 0) continue;
|
||||||
if(entries[i]->type == MwDIRECTORY_DIRECTORY) {
|
if(fc->entries[i]->type == MwDIRECTORY_DIRECTORY) {
|
||||||
char* date = malloc(128);
|
char* date = malloc(128);
|
||||||
|
|
||||||
MwStringTime(date, entries[i]->mtime);
|
MwStringTime(date, fc->entries[i]->mtime);
|
||||||
|
|
||||||
arrput(names, entries[i]->name);
|
arrput(names, fc->entries[i]->name);
|
||||||
arrput(dates, date);
|
arrput(dates, date);
|
||||||
arrput(sizes, NULL);
|
arrput(sizes, NULL);
|
||||||
arrput(icons, fc->dir);
|
arrput(icons, fc->dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 0; i < arrlen(entries); i++) {
|
for(i = 0; i < arrlen(fc->entries); i++) {
|
||||||
if(entries[i]->type == MwDIRECTORY_FILE) {
|
if(fc->entries[i]->type == MwDIRECTORY_FILE) {
|
||||||
char* date = malloc(128);
|
char* date = malloc(128);
|
||||||
char* size = malloc(128);
|
char* size = malloc(128);
|
||||||
|
|
||||||
MwStringTime(date, entries[i]->mtime);
|
MwStringTime(date, fc->entries[i]->mtime);
|
||||||
MwStringSize(size, entries[i]->size);
|
MwStringSize(size, fc->entries[i]->size);
|
||||||
|
|
||||||
arrput(names, entries[i]->name);
|
arrput(names, fc->entries[i]->name);
|
||||||
arrput(dates, date);
|
arrput(dates, date);
|
||||||
arrput(sizes, size);
|
arrput(sizes, size);
|
||||||
arrput(icons, fc->file);
|
arrput(icons, fc->file);
|
||||||
@@ -319,9 +333,6 @@ static void scan(MwWidget handle, const char* path) {
|
|||||||
arrfree(dates);
|
arrfree(dates);
|
||||||
arrfree(names);
|
arrfree(names);
|
||||||
arrfree(icons);
|
arrfree(icons);
|
||||||
|
|
||||||
for(i = 0; i < arrlen(entries); i++) MwDirectoryFreeEntry(entries[i]);
|
|
||||||
arrfree(entries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MwWidget MwFileChooser(MwWidget handle, const char* title) {
|
MwWidget MwFileChooser(MwWidget handle, const char* title) {
|
||||||
|
|||||||
Reference in New Issue
Block a user