ui: fixes main_window and modal behavior

This commit is contained in:
2026-05-05 16:53:22 +03:00
parent a1e391c718
commit a0d5fceb24
3 changed files with 23 additions and 11 deletions
+1
View File
@@ -1,6 +1,7 @@
# TODO: # TODO:
## Current: ## Current:
- [ ] Check callback functions in dialogues
- [ ] Check registration / enter server name again - [ ] Check registration / enter server name again
- [ ] Get rid of unsigned integers - [ ] Get rid of unsigned integers
- [ ] Separate common structures in the common.h - [ ] Separate common structures in the common.h
+3 -4
View File
@@ -14,7 +14,7 @@
void ac_file(WINDOW *win, int is_action_w); void ac_file(WINDOW *win, int is_action_w);
app_t *app_init() { app_t *app_init(void) {
/* get values from terminal size */ /* get values from terminal size */
int32_t y_max, x_max; int32_t y_max, x_max;
getmaxyx(stdscr, y_max, x_max); getmaxyx(stdscr, y_max, x_max);
@@ -51,7 +51,7 @@ app_t *app_init() {
return _app; return _app;
} }
void app_init_nc() { void app_init_nc(void) {
initscr(); initscr();
cbreak(); cbreak();
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
@@ -157,8 +157,7 @@ void app_refresh(app_t *app) {
if (app->modal.is_initiated != 0) { if (app->modal.is_initiated != 0) {
wnoutrefresh(app->modal.win); wnoutrefresh(app->modal.win);
} }
} } else if (app->main_ui.cb_refresh != NULL) {
if (app->main_ui.cb_refresh != NULL) {
app->main_ui.cb_refresh(app); app->main_ui.cb_refresh(app);
} }
doupdate(); doupdate();
+18 -6
View File
@@ -16,6 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <utils.h> #include <utils.h>
#include "../file_processor.h"
#include "../fs.h" #include "../fs.h"
#include "../server.h" #include "../server.h"
#include "alert.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) if (*start == NULL)
return; return;
w_lfl_item_t *next, *current; 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; return 1;
if (fui->d_path != NULL) { if (fui->d_path != NULL) {
free(fui->d_path); free(fui->d_path);
fl_clear(&(fui->start), &(fui->current)); lfl_clear(&(fui->start), &(fui->current));
} }
fui->d_path = malloc(strlen(path) + 1); fui->d_path = malloc(strlen(path) + 1);
strcpy(fui->d_path, path); strcpy(fui->d_path, path);
@@ -235,7 +236,8 @@ static void page_previous(w_lfl_ui_t *fui) {
n_page_item = n_page_item->prev; n_page_item = n_page_item->prev;
} }
fui->cur_page--; 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->page_start = n_page_item;
fui->current_idx = fui->max_lines; 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; w_lfl_ui_t *fui = args->element;
int32_t key = *((int32_t *)args->data); int32_t key = *((int32_t *)args->data);
bool is_cur_p = 0; /* current page */ bool is_cur_p = 0; /* current page */
app_t *app = (app_t *)args->app;
switch (key) { switch (key) {
case KEY_DOWN: case KEY_DOWN:
is_cur_p = (fui->current_idx % fui->max_lines || fui->current_idx == 0); 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 */ } else { /* is_cur_p */
page_next(fui); page_next(fui);
} }
} else break; /* fui->current->next != NULL */ } else
break; /* fui->current->next != NULL */
w_lfl_draw(fui); w_lfl_draw(fui);
break; break;
case KEY_UP: case KEY_UP:
@@ -268,7 +272,8 @@ static void w_lfl_cb(w_cb_args_t *args) {
} else { } else {
page_previous(fui); page_previous(fui);
} }
} else break; } else
break;
w_lfl_draw(fui); w_lfl_draw(fui);
break; break;
case KEY_NPAGE: 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); app->active_callback(d_args);
break; 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; return OK;
} }
@@ -458,7 +470,7 @@ void w_lfl_draw(w_lfl_ui_t *fui) {
void w_lfl_destroy(w_lfl_ui_t **fui) { void w_lfl_destroy(w_lfl_ui_t **fui) {
w_lfl_ui_t *f = *fui; w_lfl_ui_t *f = *fui;
fl_clear(&(f->start), &(f->current)); lfl_clear(&(f->start), &(f->current));
free(*fui); free(*fui);
*fui = NULL; *fui = NULL;
} }