commit c5af9d18a76c2ee352daabd0f315ba65f6892977
parent bd128ed3a63cfc84aa38a42b26768c994d02fe44
Author: bsandro <[email protected]>
Date: Mon, 2 Sep 2024 20:48:38 +0300
Tiny improvements for the file browser window (still incomplete)
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/gui/main.c b/gui/main.c
@@ -229,14 +229,14 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
if (filelist==NULL) {
//@todo sort directories before files in list
table->itemCount = scandir(dir_name, &filelist, NULL, alphasort);
- printf("populate dir %s with %d items\n", dir_name, table->itemCount);
+ printf("populated dir %s with %d items\n", dir_name, table->itemCount);
}
- if (msg == UI_MSG_TABLE_GET_ITEM) {
+ if (msg==UI_MSG_TABLE_GET_ITEM) {
UITableGetItem *m = (UITableGetItem *)dp;
m->isSelected = selected==m->index;
bool is_dir = filelist[m->index]->d_type==DT_DIR;
return snprintf(m->buffer, m->bufferBytes, is_dir?"[%s]":"%s", filelist[m->index]->d_name);
- } else if (msg == UI_MSG_CLICKED) {
+ } else if (msg==UI_MSG_CLICKED) {
int hit = UITableHitTest(table, element->window->cursorX, element->window->cursorY);
if (selected==hit) {
if (hit!=-1) {
@@ -252,6 +252,7 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
printf("new dir: %s\n", element->cp);
//@todo cleanup filelist!
filelist = NULL;
+ selected = -1;
}
}
} else {
@@ -260,6 +261,10 @@ int TableEvent(UIElement *element, UIMessage msg, int di, void *dp) {
UIElementRepaint(element, NULL);
}
}
+ } else if (msg==UI_MSG_DESTROY) {
+ printf("destroy table\n");
+ filelist = NULL;
+ selected = -1;
}
return 0;
}
@@ -304,7 +309,7 @@ void ShowModalWindow(UIWindow *parent, const char *def_dir, const char *def_file
UITable *table = UITableCreate(&panel_out->e, UI_ELEMENT_V_FILL, "Directory");
table->itemCount = 1; // at least '..' element
- table->e.cp = ".";
+ table->e.cp = "."; // initial directory
table->e.messageUser = TableEvent;
UITableResizeColumns(table);
} else {