UI: separates app module, fixes in file lists
This commit is contained in:
+13
-14
@@ -1,7 +1,12 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "app.h"
|
||||
#include "file_list.h"
|
||||
#include "../app.h"
|
||||
#include "../file_processor.h"
|
||||
#include "../fs.h"
|
||||
#include "../server.h"
|
||||
#include "main_window.h"
|
||||
#include <bstrlib.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
#include <stdbool.h>
|
||||
@@ -11,16 +16,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "main_window.h"
|
||||
#include "file_list.h"
|
||||
#include "../file_processor.h"
|
||||
#include "../fs.h"
|
||||
#include "../server.h"
|
||||
|
||||
void w_fl_reset(w_ui_file_list_t *fl_ui);
|
||||
|
||||
static void w_fl_cb(w_cb_args_t *args) {
|
||||
w_app_t *app = args->app;
|
||||
app_t *app = args->app;
|
||||
w_ui_file_list_t *fui = app->query_args->main_ui->ui;
|
||||
int32_t key = *((int32_t *)args->data);
|
||||
char q_prefix[128];
|
||||
@@ -117,7 +117,7 @@ static void w_fl_cb(w_cb_args_t *args) {
|
||||
}
|
||||
|
||||
static void w_fl_cb_refresh(void *data) {
|
||||
w_app_t *app = (w_app_t *)data;
|
||||
app_t *app = (app_t *)data;
|
||||
if (app->main_ui.type != mw_fl_server) {
|
||||
return;
|
||||
}
|
||||
@@ -133,20 +133,19 @@ static struct action_key action_keys[] = {
|
||||
{.key = "F9", .title = "Quit", .code = KEY_F(9)},
|
||||
};
|
||||
|
||||
static int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args) {
|
||||
static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) {
|
||||
int32_t c;
|
||||
w_ui_file_list_t *fui = (w_ui_file_list_t *)app->query_args->main_ui->ui;
|
||||
c = wgetch(app->win);
|
||||
switch (c) {
|
||||
case KEY_F(9):
|
||||
w_app_destroy(app, 0);
|
||||
app_destroy(app, 0);
|
||||
return OK;
|
||||
case 'U':
|
||||
case 'u':
|
||||
if (!app->modal.is_initiated && !fui->active_search) {
|
||||
/* app->query_args->state = S_UPLOAD_FILE_SELECT; */
|
||||
main_window_set(app, mw_fl_local);
|
||||
main_window_draw(app);
|
||||
d_args->element = app->main_ui.ui;
|
||||
break;
|
||||
}
|
||||
@@ -165,14 +164,14 @@ static int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void *w_fl_init(w_app_t *app) {
|
||||
void *w_fl_init(app_t *app) {
|
||||
w_ui_file_list_t *fui = malloc(sizeof(w_ui_file_list_t));
|
||||
app->main_ui.ui = fui;
|
||||
app->main_ui.type = mw_fl_server;
|
||||
app->main_ui.cb_refresh = w_fl_cb_refresh;
|
||||
app->main_ui.b_keys = action_keys;
|
||||
app->main_ui.b_keys_len = 4;
|
||||
app->main_ui.cb_b_press = (w_cb_press_t) process_user_input;
|
||||
app->main_ui.cb_b_press = (w_cb_press_t)process_user_input;
|
||||
app->active_callback = w_fl_cb;
|
||||
w_init(&(fui->w), NULL, &(app->win), "");
|
||||
WINDOW *win_parent = app->win;
|
||||
@@ -245,7 +244,7 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
||||
}
|
||||
|
||||
if (fui->activate_last) {
|
||||
fui->current_idx = fui->current_count - 1;
|
||||
fui->current_idx = fui->max_lines - 1;
|
||||
fui->activate_last = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifndef W_FILE_LIST_H
|
||||
#define W_FILE_LIST_H
|
||||
|
||||
#include "app.h"
|
||||
#include "../app.h"
|
||||
#include <bstrlib.h>
|
||||
#include <stdint.h>
|
||||
#include <widget_core.h>
|
||||
@@ -27,7 +27,7 @@ typedef struct {
|
||||
} w_ui_file_list_t;
|
||||
|
||||
void w_fl_draw(w_ui_file_list_t *fl_ui);
|
||||
void *w_fl_init(w_app_t *app);
|
||||
void *w_fl_init(app_t *app);
|
||||
void w_fl_reset(w_ui_file_list_t *fl_ui);
|
||||
void w_fl_destroy(w_ui_file_list_t **fui);
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ w_lfl_ui_t *w_lfl_init(WINDOW **win, w_t *w_parent) {
|
||||
}
|
||||
|
||||
static void w_lfl_cb_refresh(void *data) {
|
||||
w_app_t *app = (w_app_t *)data;
|
||||
app_t *app = (app_t *)data;
|
||||
if (app->main_ui.type != mw_fl_local) {
|
||||
return;
|
||||
}
|
||||
@@ -290,22 +290,21 @@ static struct action_key action_keys[] = {
|
||||
{.key = "F9", .title = "Quit", .code = KEY_F(9)},
|
||||
};
|
||||
|
||||
static int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args) {
|
||||
static int32_t process_user_input(app_t *app, w_cb_args_t *d_args) {
|
||||
int32_t c;
|
||||
w_lfl_ui_t *fui = (w_lfl_ui_t *)app->query_args->main_ui->ui;
|
||||
c = wgetch(app->win);
|
||||
switch (c) {
|
||||
case KEY_F(9):
|
||||
w_app_destroy(app, 0);
|
||||
app_destroy(app, 0);
|
||||
return OK;
|
||||
case 'D':
|
||||
case 'd':
|
||||
case '\33': /* ESC key */
|
||||
if (!app->modal.is_initiated) {
|
||||
main_window_set(app, mw_fl_server);
|
||||
main_window_draw(app);
|
||||
server_send_string(app->query_args, "file list %u %u\n", fui->max_lines,
|
||||
server_send_string(app->query_args, "file list %u %u\n", fui->max_lines-1,
|
||||
1);
|
||||
main_window_set(app, mw_fl_server);
|
||||
d_args->element = app->main_ui.ui;
|
||||
break;
|
||||
}
|
||||
@@ -317,7 +316,7 @@ static int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
w_lfl_ui_t *w_lfl_init_win(w_app_t *app) {
|
||||
w_lfl_ui_t *w_lfl_init_win(app_t *app) {
|
||||
w_lfl_ui_t *fui = malloc(sizeof(w_lfl_ui_t));
|
||||
app->main_ui.ui = fui;
|
||||
app->main_ui.type = mw_fl_local;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifndef W_LFL_H /* LOCAL FILE LIST */
|
||||
#define W_LFL_H
|
||||
|
||||
#include "app.h"
|
||||
#include "../app.h"
|
||||
#include <widget_core.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
#include <stdint.h>
|
||||
@@ -37,6 +37,6 @@ void w_lfl_draw(w_lfl_ui_t *fl_ui);
|
||||
void w_lfl_destroy(w_lfl_ui_t **fui);
|
||||
void w_lfl_reset(w_lfl_ui_t *fl_ui);
|
||||
w_lfl_ui_t *w_lfl_init(WINDOW **win, w_t *w_parent);
|
||||
w_lfl_ui_t *w_lfl_init_win(w_app_t *app);
|
||||
w_lfl_ui_t *w_lfl_init_win(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -2,10 +2,10 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "main_window.h"
|
||||
#include "fs_file_list.h"
|
||||
#include "file_list.h"
|
||||
#include "fs_file_list.h"
|
||||
|
||||
void main_window_set(w_app_t *app, enum main_window_type type) {
|
||||
void main_window_set(app_t *app, enum main_window_type type) {
|
||||
if (app->main_ui.ui != NULL) {
|
||||
main_window_destroy(app);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ void main_window_set(w_app_t *app, enum main_window_type type) {
|
||||
}
|
||||
}
|
||||
|
||||
void main_window_draw(w_app_t *app) {
|
||||
void main_window_draw(app_t *app) {
|
||||
switch (app->main_ui.type) {
|
||||
case mw_fl_server:
|
||||
w_fl_draw((w_ui_file_list_t *)app->main_ui.ui);
|
||||
@@ -36,16 +36,17 @@ void main_window_draw(w_app_t *app) {
|
||||
case mw_f_desc:
|
||||
break;
|
||||
}
|
||||
w_app_draw_bbar(app);
|
||||
app_draw_bbar(app);
|
||||
}
|
||||
|
||||
void main_window_destroy(w_app_t *app) {
|
||||
void main_window_destroy(app_t *app) {
|
||||
switch (app->main_ui.type) {
|
||||
case mw_fl_server:
|
||||
w_fl_destroy((w_ui_file_list_t **)&(app->main_ui.ui));
|
||||
break;
|
||||
case mw_fl_local:
|
||||
w_lfl_destroy((w_lfl_ui_t **)&(app->main_ui.ui));
|
||||
break;
|
||||
case mw_f_desc:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#ifndef MAIN_WINDOW_H
|
||||
#define MAIN_WINDOW_H
|
||||
|
||||
#include <widget.h>
|
||||
#include "../app.h"
|
||||
|
||||
void main_window_set(w_app_t *app, enum main_window_type type);
|
||||
void main_window_draw(w_app_t *app);
|
||||
void main_window_destroy(w_app_t *app);
|
||||
void main_window_set(app_t *app, enum main_window_type type);
|
||||
void main_window_draw(app_t *app);
|
||||
void main_window_destroy(app_t *app);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user