Remove recognized keys check

All keys known by ncurses can be bound. Thus the check for not
recognized keys in custom_keys_config() becomes superfluous.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2017-10-24 21:55:44 +02:00 committed by Lukas Fleischer
parent c0644d5aaf
commit 2b8d4e983f

View File

@ -929,7 +929,7 @@ void custom_keys_config(void)
{ {
struct scrollwin kwin; struct scrollwin kwin;
int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed; int selrow, selelm, firstrow, lastrow, nbrowelm, nbdisplayed;
int ch, used, not_recognized; int ch;
const char *keystr; const char *keystr;
WINDOW *grabwin; WINDOW *grabwin;
const int LINESPERKEY = 2; const int LINESPERKEY = 2;
@ -988,47 +988,23 @@ void custom_keys_config(void)
case KEY_ADD_ITEM: case KEY_ADD_ITEM:
#define WINROW 10 #define WINROW 10
#define WINCOL 50 #define WINCOL 50
do { for (;;) {
used = 0;
grabwin = grabwin =
popup(WINROW, WINCOL, popup(WINROW, WINCOL,
(row - WINROW) / 2, (row - WINROW) / 2,
(col - WINCOL) / 2, (col - WINCOL) / 2,
_("Press the key you want to assign to:"), _("Press the key you want to assign to:"),
keys_get_label(selrow), 0); keys_get_label(selrow), 0);
ch = keys_wgetch(grabwin); ch = keys_wgetch(grabwin);
enum key action = keys_get_action(ch);
/* Check if this is a ncurses pseudo key accepted by calcurse. */ /* Is the key already used by this action? */
if (ch >= KEY_MIN && ch <= KEY_MAX && !( if (action == selrow) {
ch == KEY_UP || ch == KEY_DOWN ||
ch == KEY_LEFT || ch == KEY_RIGHT ||
ch == KEY_HOME || ch == KEY_END)) {
not_recognized = 1;
WARN_MSG(_("The key '%s' is not accepted by calcurse. "
"Choose another one."), keyname(ch));
werase(kwin.inner);
nbrowelm =
print_keys_bindings(kwin.inner,
selrow,
selelm,
LINESPERKEY);
wins_scrollwin_display(&kwin);
continue;
} else {
not_recognized = 0;
}
/* Is the binding used by this action already? If so, just end the reassignment */
if (selrow == keys_get_action(ch)) {
delwin(grabwin); delwin(grabwin);
break; break;
} }
/* Is the key used by another action? */
used = keys_assign_binding(ch, selrow); if (keys_assign_binding(ch, selrow)) {
if (used) {
enum key action;
action = keys_get_action(ch);
char *keystr = keys_int2str(ch); char *keystr = keys_int2str(ch);
WARN_MSG(_("The key '%s' is already used for %s. " WARN_MSG(_("The key '%s' is already used for %s. "
"Choose another one."), "Choose another one."),
@ -1042,13 +1018,13 @@ void custom_keys_config(void)
selelm, selelm,
LINESPERKEY); LINESPERKEY);
wins_scrollwin_display(&kwin); wins_scrollwin_display(&kwin);
} else { continue;
nbrowelm++;
selelm = nbrowelm - 1;
} }
nbrowelm++;
selelm = nbrowelm - 1;
delwin(grabwin); delwin(grabwin);
break;
} }
while (used || not_recognized);
#undef WINROW #undef WINROW
#undef WINCOL #undef WINCOL
break; break;