dir loader
This commit is contained in:
parent
7b017bcf3f
commit
9fb0925e9a
3 changed files with 55 additions and 6 deletions
55
src/dir.c
55
src/dir.c
|
|
@ -10,6 +10,14 @@ struct direntry {
|
|||
char* path;
|
||||
};
|
||||
|
||||
struct watchentry {
|
||||
void* tv;
|
||||
void* loading;
|
||||
char* path;
|
||||
};
|
||||
|
||||
static struct watchentry* watchlist = NULL;
|
||||
|
||||
static int sort_de(const void* _a, const void* _b) {
|
||||
struct direntry* a = (struct direntry*)_a;
|
||||
struct direntry* b = (struct direntry*)_b;
|
||||
|
|
@ -20,15 +28,29 @@ static int sort_de(const void* _a, const void* _b) {
|
|||
return strcmp(a->d.d_name, b->d.d_name);
|
||||
}
|
||||
|
||||
static void dir_recursion(const char* path, const char* path2, void* tv) {
|
||||
static void dir_recursion(const char* path, const char* path2, void* tv, int level, int notop) {
|
||||
PPR_DIR* dir;
|
||||
struct ppr_dirent* d;
|
||||
struct direntry* de = NULL;
|
||||
int i;
|
||||
|
||||
tv = MwTreeViewAdd(fileview, tv, NULL, path2);
|
||||
if(path != path2) MwTreeViewSetOpened(fileview, tv, 0);
|
||||
if(!notop) {
|
||||
tv = MwTreeViewAdd(fileview, tv, NULL, path2);
|
||||
if(path != path2) MwTreeViewSetOpened(fileview, tv, 0);
|
||||
}
|
||||
if((dir = ppr_opendir(path)) != NULL) {
|
||||
if(level == 0) {
|
||||
struct watchentry we;
|
||||
|
||||
we.tv = tv;
|
||||
we.loading = MwTreeViewAdd(fileview, tv, NULL, "Loading...");
|
||||
we.path = MwStringDuplicate(path);
|
||||
arrput(watchlist, we);
|
||||
|
||||
ppr_closedir(dir);
|
||||
return;
|
||||
}
|
||||
|
||||
while((d = ppr_readdir(dir)) != NULL) {
|
||||
struct direntry new_de;
|
||||
|
||||
|
|
@ -39,10 +61,12 @@ static void dir_recursion(const char* path, const char* path2, void* tv) {
|
|||
#else
|
||||
new_de.path = ppr_strvacat(path, "/", d->d_name, NULL);
|
||||
#endif
|
||||
new_de.d = *d;
|
||||
new_de.d = *d;
|
||||
ppr_stat(new_de.path, &new_de.s);
|
||||
arrput(de, new_de);
|
||||
}
|
||||
|
||||
ppr_closedir(dir);
|
||||
}
|
||||
|
||||
if(de != NULL) {
|
||||
|
|
@ -54,7 +78,9 @@ static void dir_recursion(const char* path, const char* path2, void* tv) {
|
|||
char* p = ppr_strvacat(de[i].d.d_name, PPR_S_ISDIR(de[i].s.st_mode) ? "/" : "", NULL);
|
||||
#endif
|
||||
|
||||
//dir_recursion(de[i].path, p, tv);
|
||||
if(level > 0) {
|
||||
dir_recursion(de[i].path, p, tv, level - 1, 0);
|
||||
}
|
||||
|
||||
free(p);
|
||||
|
||||
|
|
@ -74,5 +100,22 @@ void dir_scan(const char* dir) {
|
|||
realpath(dir, real);
|
||||
#endif
|
||||
|
||||
dir_recursion(real, real, NULL);
|
||||
dir_recursion(real, real, NULL, 1, 0);
|
||||
}
|
||||
|
||||
void dir_tick(void) {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < arrlen(watchlist); i++) {
|
||||
if(MwTreeViewGetOpened(fileview, watchlist[i].tv)) {
|
||||
MwTreeViewDelete(fileview, watchlist[i].loading);
|
||||
|
||||
dir_recursion(watchlist[i].path, watchlist[i].path, watchlist[i].tv, 1, 1);
|
||||
|
||||
free(watchlist[i].path);
|
||||
arrdel(watchlist, i);
|
||||
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tick(MwWidget handle, void* user, void* client) {
|
||||
dir_tick();
|
||||
}
|
||||
|
||||
void gui_init(void) {
|
||||
MwRect rc;
|
||||
int w, h;
|
||||
|
|
@ -146,6 +150,7 @@ void gui_init(void) {
|
|||
resize(window, NULL, NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
|
||||
MwTimeSleep(50);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ void gui_loop(void);
|
|||
|
||||
/* dir.c */
|
||||
void dir_scan(const char* dir);
|
||||
void dir_tick(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue