ui: key press callbacks (not finished)
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
# TODO:
|
# TODO:
|
||||||
|
|
||||||
## Current:
|
## Current:
|
||||||
- [ ] Sorting in file list
|
- [ ] Separate common structures in the common.h
|
||||||
|
- [ ] Bottom panel attach to the windows
|
||||||
|
- [ ] Testing
|
||||||
|
- [ ] Sorting in the file list
|
||||||
- [ ] File upload multiline description (window)
|
- [ ] File upload multiline description (window)
|
||||||
- [ ] More intuitive navigation between nested groups (by pressing left and right buttons)
|
- [ ] More intuitive navigation between nested groups (by pressing left and right buttons)
|
||||||
- [ ] Cancel upload/download
|
- [ ] Cancel upload/download
|
||||||
|
|||||||
@@ -3,9 +3,26 @@
|
|||||||
|
|
||||||
#ifndef COMMON_H
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t cur_y, cur_x;
|
uint32_t cur_y, cur_x;
|
||||||
uint32_t max_y, max_x;
|
uint32_t max_y, max_x;
|
||||||
} coordinates_t;
|
} coordinates_t;
|
||||||
|
|
||||||
|
#define MAIN_UI_RESET(app) \
|
||||||
|
app->main_ui.ui = NULL; \
|
||||||
|
app->main_ui.cb_refresh = NULL; \
|
||||||
|
app->main_ui.cb_b_press = NULL; \
|
||||||
|
app->main_ui.b_keys = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
struct action_key {
|
||||||
|
char *const key;
|
||||||
|
char *const title;
|
||||||
|
int const code;
|
||||||
|
int (*callback)(void *app, void *d_args);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+2
-51
@@ -17,16 +17,14 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "file_list.h"
|
#include "file_list.h"
|
||||||
#include "fs_file_list.h"
|
#include "main_window.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
||||||
uint32_t m_id = 0;
|
uint32_t m_id = 0;
|
||||||
|
|
||||||
int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args);
|
int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args);
|
||||||
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);
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
w_app_t *app;
|
w_app_t *app;
|
||||||
@@ -104,50 +102,3 @@ int32_t process_user_input(w_app_t *app, w_cb_args_t *d_args) {
|
|||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_window_set(w_app_t *app, enum main_window_type type) {
|
|
||||||
if (app->main_ui.ui != NULL) {
|
|
||||||
main_window_destroy(app);
|
|
||||||
}
|
|
||||||
app->main_ui.type = type;
|
|
||||||
switch (type) {
|
|
||||||
case mw_fl_server:
|
|
||||||
app->main_ui.ui = w_fl_init(app);
|
|
||||||
app->active_callback = w_fl_cb;
|
|
||||||
break;
|
|
||||||
case mw_fl_local:
|
|
||||||
app->main_ui.ui = w_lfl_init_win(app);
|
|
||||||
app->active_callback = w_lfl_cb;
|
|
||||||
break;
|
|
||||||
case mw_f_desc:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main_window_draw(w_app_t *app) {
|
|
||||||
switch (app->main_ui.type) {
|
|
||||||
case mw_fl_server:
|
|
||||||
w_fl_draw((w_ui_file_list_t *)app->main_ui.ui);
|
|
||||||
break;
|
|
||||||
case mw_fl_local:
|
|
||||||
w_lfl_draw((w_lfl_ui_t *)app->main_ui.ui);
|
|
||||||
break;
|
|
||||||
case mw_f_desc:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main_window_destroy(w_app_t *app) {
|
|
||||||
switch (app->main_ui.type) {
|
|
||||||
case mw_fl_server:
|
|
||||||
w_fl_destroy((w_ui_file_list_t **)&(app->main_ui.ui));
|
|
||||||
app->main_ui.cb_refresh = NULL;
|
|
||||||
break;
|
|
||||||
case mw_fl_local:
|
|
||||||
/* TODO: delete fs_file_list */
|
|
||||||
case mw_f_desc:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -91,7 +92,9 @@ enum main_window_type {
|
|||||||
typedef struct main_window {
|
typedef struct main_window {
|
||||||
enum main_window_type type;
|
enum main_window_type type;
|
||||||
void *ui; /* structure which describes window UI */
|
void *ui; /* structure which describes window UI */
|
||||||
|
int32_t (*cb_b_press) (void *app, void *args); /* callback on button press */
|
||||||
void (*cb_refresh) (void *app); /* refresh callback */
|
void (*cb_refresh) (void *app); /* refresh callback */
|
||||||
|
struct action_key *b_keys;
|
||||||
} main_window_t;
|
} main_window_t;
|
||||||
|
|
||||||
typedef struct query_args {
|
typedef struct query_args {
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include "main_window.h"
|
||||||
|
#include "fs_file_list.h"
|
||||||
|
|
||||||
|
void main_window_set(w_app_t *app, enum main_window_type type) {
|
||||||
|
if (app->main_ui.ui != NULL) {
|
||||||
|
main_window_destroy(app);
|
||||||
|
}
|
||||||
|
app->main_ui.type = type;
|
||||||
|
switch (type) {
|
||||||
|
case mw_fl_server:
|
||||||
|
app->main_ui.ui = w_fl_init(app);
|
||||||
|
app->active_callback = w_fl_cb;
|
||||||
|
break;
|
||||||
|
case mw_fl_local:
|
||||||
|
app->main_ui.ui = w_lfl_init_win(app);
|
||||||
|
app->active_callback = w_lfl_cb;
|
||||||
|
break;
|
||||||
|
case mw_f_desc:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main_window_draw(w_app_t *app) {
|
||||||
|
switch (app->main_ui.type) {
|
||||||
|
case mw_fl_server:
|
||||||
|
w_fl_draw((w_ui_file_list_t *)app->main_ui.ui);
|
||||||
|
break;
|
||||||
|
case mw_fl_local:
|
||||||
|
w_lfl_draw((w_lfl_ui_t *)app->main_ui.ui);
|
||||||
|
break;
|
||||||
|
case mw_f_desc:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main_window_destroy(w_app_t *app) {
|
||||||
|
switch (app->main_ui.type) {
|
||||||
|
case mw_fl_server:
|
||||||
|
w_fl_destroy((w_ui_file_list_t **)&(app->main_ui.ui));
|
||||||
|
MAIN_UI_RESET(app);
|
||||||
|
break;
|
||||||
|
case mw_fl_local:
|
||||||
|
/* TODO: delete fs_file_list */
|
||||||
|
case mw_f_desc:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef MAIN_WINDOW_H
|
||||||
|
#define MAIN_WINDOW_H
|
||||||
|
|
||||||
|
#include <widget.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);
|
||||||
|
|
||||||
|
#endif
|
||||||
+1
-7
@@ -43,8 +43,7 @@ w_app_t *w_app_init() {
|
|||||||
w_app_draw_borders(_app);
|
w_app_draw_borders(_app);
|
||||||
|
|
||||||
/* NULL to main_ui */
|
/* NULL to main_ui */
|
||||||
_app->main_ui.ui = NULL;
|
MAIN_UI_RESET(_app);
|
||||||
_app->main_ui.cb_refresh = NULL;
|
|
||||||
|
|
||||||
keypad(_app->win, TRUE);
|
keypad(_app->win, TRUE);
|
||||||
|
|
||||||
@@ -83,11 +82,6 @@ void w_app_draw_borders(w_app_t *app) {
|
|||||||
box(app->win, 0, 0);
|
box(app->win, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct action_key {
|
|
||||||
char *const key;
|
|
||||||
char *const title;
|
|
||||||
};
|
|
||||||
|
|
||||||
int64_t print_bottom_menu_option(WINDOW *win, char *key, char *title, int64_t y,
|
int64_t print_bottom_menu_option(WINDOW *win, char *key, char *title, int64_t y,
|
||||||
int64_t x, int32_t size) {
|
int64_t x, int32_t size) {
|
||||||
int32_t key_len = 0;
|
int32_t key_len = 0;
|
||||||
|
|||||||
+43
-1
@@ -15,6 +15,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "../main_window.h"
|
||||||
|
|
||||||
void w_fl_reset(w_ui_file_list_t *fl_ui);
|
void w_fl_reset(w_ui_file_list_t *fl_ui);
|
||||||
|
|
||||||
@@ -125,11 +126,53 @@ static void w_fl_cb_refresh(void *data) {
|
|||||||
wnoutrefresh(fui->win_info);
|
wnoutrefresh(fui->win_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct action_key action_keys[] = {
|
||||||
|
{.key = "F1", .title = "Help", .code = KEY_F(1)},
|
||||||
|
{.key = "U", .title = "Upload", .code = 'u'},
|
||||||
|
{.key = "S", .title = "Search", .code = 's'},
|
||||||
|
{.key = "F9", .title = "Quit", .code = KEY_F(9)},
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t process_user_input(w_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);
|
||||||
|
return OK;
|
||||||
|
case 'U':
|
||||||
|
case 'u':
|
||||||
|
if (!app->modal.is_initiated && !fui->active_search &&
|
||||||
|
app->main_ui.type != mw_fl_local) {
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
case 's':
|
||||||
|
case 'S':
|
||||||
|
if (!app->modal.is_initiated && !fui->active_search) {
|
||||||
|
fui->active_search = true;
|
||||||
|
w_fl_draw(fui);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
d_args->data = (void *)&c;
|
||||||
|
app->active_callback(d_args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
w_ui_file_list_t *w_fl_init(w_app_t *app) {
|
w_ui_file_list_t *w_fl_init(w_app_t *app) {
|
||||||
w_ui_file_list_t *fui = malloc(sizeof(w_ui_file_list_t));
|
w_ui_file_list_t *fui = malloc(sizeof(w_ui_file_list_t));
|
||||||
app->main_ui.ui = fui;
|
app->main_ui.ui = fui;
|
||||||
app->main_ui.type = mw_fl_server;
|
app->main_ui.type = mw_fl_server;
|
||||||
app->main_ui.cb_refresh = w_fl_cb_refresh;
|
app->main_ui.cb_refresh = w_fl_cb_refresh;
|
||||||
|
app->main_ui.b_keys = action_keys;
|
||||||
|
app->main_ui.cb_b_press = process_user_input;
|
||||||
w_init(&(fui->w), NULL, &(app->win), "");
|
w_init(&(fui->w), NULL, &(app->win), "");
|
||||||
WINDOW *win_parent = app->win;
|
WINDOW *win_parent = app->win;
|
||||||
fui->current_idx = 0;
|
fui->current_idx = 0;
|
||||||
@@ -158,7 +201,6 @@ w_ui_file_list_t *w_fl_init(w_app_t *app) {
|
|||||||
fui->win_info =
|
fui->win_info =
|
||||||
newwin(app->coordinates.max_y - 4, right_w_x, 2, left_w_x + 1);
|
newwin(app->coordinates.max_y - 4, right_w_x, 2, left_w_x + 1);
|
||||||
fui->max_lines = getmaxy(fui->win_list) - 3; /* 2+1 (bottom info line) */
|
fui->max_lines = getmaxy(fui->win_list) - 3; /* 2+1 (bottom info line) */
|
||||||
|
|
||||||
return fui;
|
return fui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ typedef struct {
|
|||||||
void *active_el;
|
void *active_el;
|
||||||
} w_cb_args_t;
|
} w_cb_args_t;
|
||||||
|
|
||||||
|
typedef void (*w_cb_t)(w_cb_args_t *args);
|
||||||
|
|
||||||
typedef struct w_t {
|
typedef struct w_t {
|
||||||
int64_t id;
|
int64_t id;
|
||||||
char title[DIALOGUE_TITLE];
|
char title[DIALOGUE_TITLE];
|
||||||
@@ -93,11 +95,9 @@ typedef struct w_t {
|
|||||||
} ps; /* position (relative to the window) */
|
} ps; /* position (relative to the window) */
|
||||||
WINDOW *const *parent_win;
|
WINDOW *const *parent_win;
|
||||||
struct w_t *w_parent;
|
struct w_t *w_parent;
|
||||||
void (*callback)(w_cb_args_t *args);
|
w_cb_t callback;
|
||||||
} w_t;
|
} w_t;
|
||||||
|
|
||||||
typedef void (*w_cb_t)(w_cb_args_t *args);
|
|
||||||
|
|
||||||
enum w_pmt_attrs {
|
enum w_pmt_attrs {
|
||||||
PMT_POS_CENTER = 01,
|
PMT_POS_CENTER = 01,
|
||||||
PMT_ALIGN_CENTER = 03,
|
PMT_ALIGN_CENTER = 03,
|
||||||
|
|||||||
Reference in New Issue
Block a user