keyhandlers: return KEY_HANDLED/KEY_NOT_HANDLED

This commit is contained in:
Kaian 2016-02-20 19:28:42 +01:00
parent a935290cb1
commit b795b67334
13 changed files with 52 additions and 43 deletions

View File

@ -937,7 +937,7 @@ call_flow_handle_key(ui_t *ui, int key)
// Sanity check, this should not happen
if (!info)
return -1;
return KEY_NOT_HANDLED;
getmaxyx(info->flow_win, height, width);
@ -1074,7 +1074,7 @@ call_flow_handle_key(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
int
@ -1084,7 +1084,7 @@ call_flow_help(ui_t *ui)
int height, width;
// Create a new panel and show centered
height = 27;
height = 28;
width = 65;
help_win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

View File

@ -585,13 +585,12 @@ call_list_handle_key(ui_t *ui, int key)
// Handle quit from this screen unless requested
if (setting_enabled(SETTING_EXITPROMPT)) {
if (dialog_confirm("Confirm exit", "Are you sure you want to quit?", "Yes,No") == 0) {
return KEY_ESC;
} else {
return 0;
ui_destroy(ui);
}
} else {
return KEY_ESC;
ui_destroy(ui);
}
return KEY_HANDLED;
break;
default:
// Parse next action
@ -620,7 +619,7 @@ call_list_handle_key(ui_t *ui, int key)
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
int
@ -706,7 +705,7 @@ call_list_handle_form_key(ui_t *ui, int key)
filter_set(FILTER_CALL_LIST, strlen(dfilter) ? dfilter : NULL);
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
int

View File

@ -269,7 +269,7 @@ call_raw_handle_key(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
int

View File

@ -235,7 +235,8 @@ column_select_handle_key_menu(ui_t *ui, int key)
break;
case ACTION_CONFIRM:
column_select_update_columns(ui);
return 27;
ui_destroy(ui);
return KEY_HANDLED;
default:
// Parse next action
continue;
@ -249,7 +250,7 @@ column_select_handle_key_menu(ui_t *ui, int key)
draw_vscrollbar(info->menu_win, top_row(menu), item_count(menu) - 1, 0);
wnoutrefresh(info->menu_win);
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
int
@ -287,13 +288,16 @@ column_select_handle_key_form(ui_t *ui, int key)
switch(field_idx) {
case FLD_COLUMNS_ACCEPT:
column_select_update_columns(ui);
return 27;
ui_destroy(ui);
return KEY_HANDLED;
case FLD_COLUMNS_CANCEL:
return 27;
ui_destroy(ui);
return KEY_HANDLED;
case FLD_COLUMNS_SAVE:
column_select_update_columns(ui);
column_select_save_columns(ui);
return 27;
ui_destroy(ui);
return KEY_HANDLED;
}
break;
default:
@ -326,7 +330,7 @@ column_select_handle_key_form(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
void

View File

@ -260,16 +260,19 @@ filter_handle_key(ui_t *ui, int key)
}
break;
case FLD_FILTER_CANCEL:
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
case FLD_FILTER_FILTER:
filter_save_options(ui);
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
}
break;
case ACTION_CONFIRM:
if (field_idx != FLD_FILTER_CANCEL)
filter_save_options(ui);
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
default:
// Parse next action
continue;
@ -295,7 +298,7 @@ filter_handle_key(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
void

View File

@ -229,30 +229,28 @@ wait_for_input()
capture_lock();
// Handle received key
int key = c;
while (c != KEY_HANDLED) {
int hld = KEY_NOT_HANDLED;
while (hld != KEY_HANDLED) {
// Check if current panel has custom bindings for that key
c = ui_handle_key(ui, c);
hld = ui_handle_key(ui, c);
if (c == KEY_HANDLED) {
if (hld == KEY_HANDLED) {
// Panel handled this key
continue;
} else if (c == KEY_PROPAGATED) {
// restore the key value
c = key;
} else if (hld == KEY_PROPAGATED) {
// Destroy current panel
ui_destroy(ui);
// Try to handle this key with the previus panel
ui = ui_find_by_panel(panel_below(NULL));
} else {
// Key not handled by UI nor propagated. Use default handler
c = default_handle_key(ui, c);
hld = default_handle_key(ui, c);
}
}
capture_unlock();
}
return -1;
return 0;
}
int

View File

@ -49,10 +49,6 @@
#define DIALOG_MAX_WIDTH 100
#define DIALOG_MIN_WIDTH 40
//! Possible key handler results
#define KEY_HANDLED 0
#define KEY_PROPAGATED -1
/**
* Define existing panels
*/

View File

@ -225,7 +225,7 @@ msg_diff_draw_message(WINDOW *win, sip_msg_t *msg, char *highlight)
int
msg_diff_handle_key(ui_t *ui, int key)
{
return key;
return KEY_NOT_HANDLED;
}
int

View File

@ -124,7 +124,7 @@ ui_handle_key(ui_t *ui, int key)
return ui->handle_key(ui, key);
}
return 0;
return KEY_NOT_HANDLED;
}

View File

@ -40,6 +40,13 @@
#include <panel.h>
#include <form.h>
//! Possible key handler results
enum key_handler_ret {
KEY_HANDLED = 0,
KEY_NOT_HANDLED = -1,
KEY_PROPAGATED = -2
};
/**
* @brief Enum for available panel types
*

View File

@ -336,7 +336,8 @@ save_handle_key(ui_t *ui, int key)
if (field_idx != FLD_SAVE_CANCEL) {
return save_to_file(ui);
}
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
default:
// Parse next action
continue;
@ -362,7 +363,7 @@ save_handle_key(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
void

View File

@ -355,7 +355,8 @@ settings_handle_key(ui_t *ui, int key)
break;
case ACTION_CONFIRM:
ui_settings_update_settings(ui);
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
default:
// Parse next action
continue;
@ -383,12 +384,11 @@ settings_handle_key(ui_t *ui, int key)
break;
case ACTION_SELECT:
case ACTION_CONFIRM:
if (field_idx == BTN_SETTINGS_CANCEL)
return KEY_ESC;
if (field_idx == BTN_SETTINGS_SAVE)
ui_settings_save(ui);
ui_settings_update_settings(ui);
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
default:
continue;
}
@ -410,7 +410,7 @@ settings_handle_key(ui_t *ui, int key)
}
// Return if this panel has handled or not the key
return (action == ERR) ? key : 0;
return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
settings_entry_t *

View File

@ -197,5 +197,6 @@ stats_create(ui_t *ui)
int
stats_handle_key(ui_t *ui, int key)
{
return KEY_ESC;
ui_destroy(ui);
return KEY_HANDLED;
}