From a0d5fceb2457210056752bff3864ed3fb5d18d94 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Tue, 5 May 2026 16:53:22 +0300 Subject: [PATCH] ui: fixes main_window and modal behavior --- TODO.md | 1 + src/app.c | 7 +++---- src/windows/fs_file_list.c | 26 +++++++++++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index ce16e2e..b52bcb6 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ # TODO: ## Current: +- [ ] Check callback functions in dialogues - [ ] Check registration / enter server name again - [ ] Get rid of unsigned integers - [ ] Separate common structures in the common.h diff --git a/src/app.c b/src/app.c index ab0102d..d78a32a 100644 --- a/src/app.c +++ b/src/app.c @@ -14,7 +14,7 @@ void ac_file(WINDOW *win, int is_action_w); -app_t *app_init() { +app_t *app_init(void) { /* get values from terminal size */ int32_t y_max, x_max; getmaxyx(stdscr, y_max, x_max); @@ -51,7 +51,7 @@ app_t *app_init() { return _app; } -void app_init_nc() { +void app_init_nc(void) { initscr(); cbreak(); keypad(stdscr, TRUE); @@ -157,8 +157,7 @@ void app_refresh(app_t *app) { if (app->modal.is_initiated != 0) { wnoutrefresh(app->modal.win); } - } - if (app->main_ui.cb_refresh != NULL) { + } else if (app->main_ui.cb_refresh != NULL) { app->main_ui.cb_refresh(app); } doupdate(); diff --git a/src/windows/fs_file_list.c b/src/windows/fs_file_list.c index 15846d4..73b3d14 100644 --- a/src/windows/fs_file_list.c +++ b/src/windows/fs_file_list.c @@ -16,6 +16,7 @@ #include #include +#include "../file_processor.h" #include "../fs.h" #include "../server.h" #include "alert.h" @@ -67,7 +68,7 @@ static void fl_add(w_lfl_item_t **f_start, w_lfl_item_t **f_current, } } -static void fl_clear(w_lfl_item_t **start, w_lfl_item_t **arg_current) { +static void lfl_clear(w_lfl_item_t **start, w_lfl_item_t **arg_current) { if (*start == NULL) return; w_lfl_item_t *next, *current; @@ -100,7 +101,7 @@ static int get_files_from_fs(w_lfl_ui_t *fui, char *path) { return 1; if (fui->d_path != NULL) { free(fui->d_path); - fl_clear(&(fui->start), &(fui->current)); + lfl_clear(&(fui->start), &(fui->current)); } fui->d_path = malloc(strlen(path) + 1); strcpy(fui->d_path, path); @@ -219,7 +220,7 @@ static void page_next(w_lfl_ui_t *fui) { for (; count >= 0; count--) { n_page_item = n_page_item->next; } - fui->cur_page++; + fui->cur_page++; fui->page_start = n_page_item; fui->current_idx = 0; fui->current = n_page_item; @@ -235,7 +236,8 @@ static void page_previous(w_lfl_ui_t *fui) { n_page_item = n_page_item->prev; } fui->cur_page--; - fui->current = fui->page_start->prev; /* the last element of the previous page */ + fui->current = + fui->page_start->prev; /* the last element of the previous page */ fui->page_start = n_page_item; fui->current_idx = fui->max_lines; } @@ -245,6 +247,7 @@ static void w_lfl_cb(w_cb_args_t *args) { w_lfl_ui_t *fui = args->element; int32_t key = *((int32_t *)args->data); bool is_cur_p = 0; /* current page */ + app_t *app = (app_t *)args->app; switch (key) { case KEY_DOWN: is_cur_p = (fui->current_idx % fui->max_lines || fui->current_idx == 0); @@ -257,7 +260,8 @@ static void w_lfl_cb(w_cb_args_t *args) { } else { /* is_cur_p */ page_next(fui); } - } else break; /* fui->current->next != NULL */ + } else + break; /* fui->current->next != NULL */ w_lfl_draw(fui); break; case KEY_UP: @@ -268,7 +272,8 @@ static void w_lfl_cb(w_cb_args_t *args) { } else { page_previous(fui); } - } else break; + } else + break; w_lfl_draw(fui); break; case KEY_NPAGE: @@ -339,6 +344,13 @@ static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) { app->active_callback(d_args); break; } + /* case: file upload */ + if (d_args->resp_data.code == cbrp_val && + d_args->resp_data.val.type == val_num && + d_args->resp_data.val.val.num == 1) { + file_upload_open(fui->d_path, fui->current->name, app->query_args); + app->query_args->state = S_UPLOAD_PARAMS; + } return OK; } @@ -458,7 +470,7 @@ void w_lfl_draw(w_lfl_ui_t *fui) { void w_lfl_destroy(w_lfl_ui_t **fui) { w_lfl_ui_t *f = *fui; - fl_clear(&(f->start), &(f->current)); + lfl_clear(&(f->start), &(f->current)); free(*fui); *fui = NULL; } \ No newline at end of file