ui: close modal on pressing escape (not everywhere)

This commit is contained in:
2026-01-23 13:50:26 +02:00
parent 50952f324d
commit b81211c764
12 changed files with 29 additions and 56 deletions
+3 -1
View File
@@ -73,6 +73,7 @@ void init_nc() {
keypad(stdscr, TRUE);
noecho();
curs_set(false);
set_escdelay(50);
if (!has_colors()) {
printf("Your terminal does not support color\n");
@@ -137,7 +138,8 @@ void app_refresh(app_t *app) {
}
void app_draw_modal(app_t *app) {
if (app->modal.needs_destroy) {
if (app->modal.needs_destroy ||
(app->query_args->state == S_WAIT_SERVER && app->modal.is_initiated)) {
destroy_dialogue(&(app->modal), app);
}
if (!app->modal.is_initiated) {
+1 -1
View File
@@ -30,7 +30,7 @@ void asa_modal_dialogue_callback(callback_args_t *args) {
case 0:
get_ip_port(app->params, in_ip->value, in_port->value);
connect_to_server(app);
destroy_dialogue(d, app);
d->needs_destroy = true;
app->query_args->state = S_WAIT_SERVER;
break;
case 1:
+1 -1
View File
@@ -37,7 +37,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
app->params->pass[in_pass->value_len] = 0;
write(app->params->sd, app->params->uname, in_name->value_len);
app->query_args->state = S_WAIT_SERVER;
destroy_dialogue(d, app);
d->needs_destroy = true;
print_bars(app);
break;
case 1:
+1 -1
View File
@@ -26,7 +26,7 @@ void login_modal_option_cb(callback_args_t *args) {
case 0:
break;
case 1:
destroy_dialogue(d, app);
d->needs_destroy = true;
app->query_args->state = S_ASK_LOGIN_USER;
break;
}
+1 -1
View File
@@ -24,7 +24,7 @@ void init_notification_modal_cb(callback_args_t *args) {
dialogue_default_callback(&d_args);
app->query_args->state = WAIT_CLIENT;
destroy_dialogue(d, app);
d->needs_destroy = true;
}
dialogue_t *init_notification_modal(app_t *app) {
+1 -1
View File
@@ -25,7 +25,7 @@ void server_message_modal_cb(callback_args_t *args) {
if (response > -1) {
switch (response) {
case 0:
destroy_dialogue(d, app);
d->needs_destroy = true;
/* TODO: macros */
free(app->query_args->server_message.text);
app->query_args->server_message.text = NULL;
+14 -13
View File
@@ -1,8 +1,8 @@
#include "../../file_processor.h"
#include "../app.h"
#include "../widget/dialogue.h"
#include "../widget/fs_file_list.h"
#include "../widget/group.h"
#include "../../file_processor.h"
#include <ncurses.h>
#include <stdint.h>
#include <string.h>
@@ -19,18 +19,19 @@ void upload_dialogue_modal_cb(callback_args_t *args) {
dialogue_default_callback(&d_args);
ui_fs_file_list_t *fui =
(ui_fs_file_list_t *)d->g_content->elements[0].element;
if (response > -1) {
switch (response) {
case 0:
app->query_args->state = S_WAIT_SERVER;
destroy_dialogue(d, app);
break;
case 1:
file_upload_open(fui->d_path, fui->current->name, app->query_args);
destroy_dialogue(d, app);
app->query_args->state = S_UPLOAD_PARAMS;
break;
}
switch (response) {
case 0:
app->query_args->state = S_WAIT_SERVER;
d->needs_destroy = true;
break;
case 1:
file_upload_open(fui->d_path, fui->current->name, app->query_args);
d->needs_destroy = true;
app->query_args->state = S_UPLOAD_PARAMS;
break;
case -2:
d->needs_destroy = true;
app->query_args->state = WAIT_CLIENT;
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ void upload_props_dialogue_modal_cb(callback_args_t *args) {
app->query_args->file->description =
malloc(desc_input->value_len + 9); /* reserve space for \n:END:\n */
strcpy(app->query_args->file->description, desc_input->value);
destroy_dialogue(d, app);
d->needs_destroy = true;
app->query_args->state = S_UPLOAD_REQUESTED;
write(app->query_args->sd, query, query_len);
break;
+4 -2
View File
@@ -75,6 +75,9 @@ void dialogue_default_callback(callback_args_t *args) {
}
*resp_value = -1;
break;
case '\33': /* Esc key */
*resp_value = -2;
break;
case KEY_RIGHT:
if (d->active.type == g_content) {
if (d->g_content->elements[d->active.id - d->g_content->first_id].type ==
@@ -188,7 +191,6 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
widget_t *w = (widget_t *)dialogue->g_content->elements[i].element;
dialogue->active.id = w->id;
return;
}
}
}
@@ -201,7 +203,6 @@ void dialogue_init_active_id(dialogue_t *dialogue) {
widget_t *w = (widget_t *)dialogue->g_action->elements[i].element;
dialogue->active.id = w->id;
return;
}
}
}
@@ -350,6 +351,7 @@ void destroy_dialogue(dialogue_t *d, void *_app) {
delwin(d->win);
d->win = NULL;
d->is_initiated = 0;
d->needs_destroy = false;
app->active_win_type = aw_left;
app->active_win = app->left_win;
app->active_callback = file_list_cb;