Use wins_set_bindings() for the configuration menu
Make use of the general key binding context switching implementation for the configuration main menu. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
035faa883b
commit
919a40f561
@ -463,7 +463,15 @@ enum key {
|
|||||||
KEY_LOWER_PRIORITY,
|
KEY_LOWER_PRIORITY,
|
||||||
|
|
||||||
NBKEYS,
|
NBKEYS,
|
||||||
KEY_UNDEF
|
KEY_UNDEF,
|
||||||
|
|
||||||
|
/* Non-configurable, context sensitive key bindings. */
|
||||||
|
KEY_CONFIGMENU_GENERAL,
|
||||||
|
KEY_CONFIGMENU_LAYOUT,
|
||||||
|
KEY_CONFIGMENU_SIDEBAR,
|
||||||
|
KEY_CONFIGMENU_COLOR,
|
||||||
|
KEY_CONFIGMENU_NOTIFY,
|
||||||
|
KEY_CONFIGMENU_KEYS
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FLAG_CAL (1 << CAL)
|
#define FLAG_CAL (1 << CAL)
|
||||||
@ -678,7 +686,6 @@ unsigned config_save(void);
|
|||||||
void custom_init_attr(void);
|
void custom_init_attr(void);
|
||||||
void custom_apply_attr(WINDOW *, int);
|
void custom_apply_attr(WINDOW *, int);
|
||||||
void custom_remove_attr(WINDOW *, int);
|
void custom_remove_attr(WINDOW *, int);
|
||||||
void custom_config_bar(void);
|
|
||||||
void custom_layout_config(void);
|
void custom_layout_config(void);
|
||||||
void custom_sidebar_config(void);
|
void custom_sidebar_config(void);
|
||||||
void custom_color_config(void);
|
void custom_color_config(void);
|
||||||
|
59
src/custom.c
59
src/custom.c
@ -93,35 +93,6 @@ void custom_remove_attr(WINDOW * win, int attr_num)
|
|||||||
wattroff(win, attr.nocolor[attr_num]);
|
wattroff(win, attr.nocolor[attr_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draws the configuration bar */
|
|
||||||
void custom_config_bar(void)
|
|
||||||
{
|
|
||||||
const int SMLSPC = 2;
|
|
||||||
const int SPC = 15;
|
|
||||||
|
|
||||||
custom_apply_attr(win[STA].p, ATTR_HIGHEST);
|
|
||||||
mvwaddstr(win[STA].p, 0, 2, "Q");
|
|
||||||
mvwaddstr(win[STA].p, 1, 2, "G");
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + SPC, "L");
|
|
||||||
mvwaddstr(win[STA].p, 1, 2 + SPC, "S");
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + 2 * SPC, "C");
|
|
||||||
mvwaddstr(win[STA].p, 1, 2 + 2 * SPC, "N");
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + 3 * SPC, "K");
|
|
||||||
custom_remove_attr(win[STA].p, ATTR_HIGHEST);
|
|
||||||
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + SMLSPC, _("Exit"));
|
|
||||||
mvwaddstr(win[STA].p, 1, 2 + SMLSPC, _("General"));
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + SPC + SMLSPC, _("Layout"));
|
|
||||||
mvwaddstr(win[STA].p, 1, 2 + SPC + SMLSPC, _("Sidebar"));
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + 2 * SPC + SMLSPC, _("Color"));
|
|
||||||
mvwaddstr(win[STA].p, 1, 2 + 2 * SPC + SMLSPC, _("Notify"));
|
|
||||||
mvwaddstr(win[STA].p, 0, 2 + 3 * SPC + SMLSPC, _("Keys"));
|
|
||||||
|
|
||||||
wnoutrefresh(win[STA].p);
|
|
||||||
wmove(win[STA].p, 0, 0);
|
|
||||||
wins_doupdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void layout_selection_bar(void)
|
static void layout_selection_bar(void)
|
||||||
{
|
{
|
||||||
static int bindings[] = {
|
static int bindings[] = {
|
||||||
@ -1036,13 +1007,27 @@ void custom_keys_config(void)
|
|||||||
|
|
||||||
void custom_config_main(void)
|
void custom_config_main(void)
|
||||||
{
|
{
|
||||||
|
static int bindings[] = {
|
||||||
|
KEY_GENERIC_QUIT, KEY_CONFIGMENU_GENERAL,
|
||||||
|
KEY_CONFIGMENU_LAYOUT, KEY_CONFIGMENU_SIDEBAR,
|
||||||
|
KEY_CONFIGMENU_COLOR, KEY_CONFIGMENU_NOTIFY,
|
||||||
|
KEY_CONFIGMENU_KEYS
|
||||||
|
};
|
||||||
const char *no_color_support =
|
const char *no_color_support =
|
||||||
_("Sorry, colors are not supported by your terminal\n"
|
_("Sorry, colors are not supported by your terminal\n"
|
||||||
"(Press [ENTER] to continue)");
|
"(Press [ENTER] to continue)");
|
||||||
int ch;
|
int ch;
|
||||||
int old_layout;
|
int old_layout;
|
||||||
|
|
||||||
custom_config_bar();
|
wins_set_bindings(bindings, ARRAY_SIZE(bindings));
|
||||||
|
wins_update_border(FLAG_ALL);
|
||||||
|
wins_update_panels(FLAG_ALL);
|
||||||
|
wins_status_bar();
|
||||||
|
if (notify_bar())
|
||||||
|
notify_update_bar();
|
||||||
|
wmove(win[STA].p, 0, 0);
|
||||||
|
wins_doupdate();
|
||||||
|
|
||||||
while ((ch = wgetch(win[KEY].p)) != 'q') {
|
while ((ch = wgetch(win[KEY].p)) != 'q') {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'C':
|
case 'C':
|
||||||
@ -1081,10 +1066,16 @@ void custom_config_main(void)
|
|||||||
custom_sidebar_config();
|
custom_sidebar_config();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
wins_update(FLAG_ALL);
|
|
||||||
wins_erase_status_bar();
|
wins_set_bindings(bindings, ARRAY_SIZE(bindings));
|
||||||
custom_config_bar();
|
wins_update_border(FLAG_ALL);
|
||||||
|
wins_update_panels(FLAG_ALL);
|
||||||
|
wins_status_bar();
|
||||||
|
if (notify_bar())
|
||||||
|
notify_update_bar();
|
||||||
|
wmove(win[STA].p, 0, 0);
|
||||||
|
wins_doupdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/keys.c
41
src/keys.c
@ -443,16 +443,51 @@ keys_display_bindings_bar(WINDOW * win, int *bindings, int count,
|
|||||||
else
|
else
|
||||||
binding_key = KEY_GENERIC_OTHER_CMD;
|
binding_key = KEY_GENERIC_OTHER_CMD;
|
||||||
|
|
||||||
|
const char *label;
|
||||||
|
|
||||||
|
if (binding_key < NBKEYS) {
|
||||||
strncpy(key, keys_action_firstkey(binding_key),
|
strncpy(key, keys_action_firstkey(binding_key),
|
||||||
KEYS_KEYLEN);
|
KEYS_KEYLEN);
|
||||||
key[KEYS_KEYLEN] = '\0';
|
key[KEYS_KEYLEN] = '\0';
|
||||||
fmtkey = keys_format_label(key, KEYS_KEYLEN);
|
label = gettext(keydef[binding_key].sb_label);
|
||||||
|
} else {
|
||||||
|
switch (binding_key) {
|
||||||
|
case KEY_CONFIGMENU_GENERAL:
|
||||||
|
strcpy(key, "g");
|
||||||
|
label = _("General");
|
||||||
|
break;
|
||||||
|
case KEY_CONFIGMENU_LAYOUT:
|
||||||
|
strcpy(key, "l");
|
||||||
|
label = _("Layout");
|
||||||
|
break;
|
||||||
|
case KEY_CONFIGMENU_SIDEBAR:
|
||||||
|
strcpy(key, "s");
|
||||||
|
label = _("Sidebar");
|
||||||
|
break;
|
||||||
|
case KEY_CONFIGMENU_COLOR:
|
||||||
|
strcpy(key, "c");
|
||||||
|
label = _("Color");
|
||||||
|
break;
|
||||||
|
case KEY_CONFIGMENU_NOTIFY:
|
||||||
|
strcpy(key, "n");
|
||||||
|
label = _("Notify");
|
||||||
|
break;
|
||||||
|
case KEY_CONFIGMENU_KEYS:
|
||||||
|
strcpy(key, "k");
|
||||||
|
label = _("Keys");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
strcpy(key, "?");
|
||||||
|
label = _("Unknown");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
custom_apply_attr(win, ATTR_HIGHEST);
|
custom_apply_attr(win, ATTR_HIGHEST);
|
||||||
|
fmtkey = keys_format_label(key, KEYS_KEYLEN);
|
||||||
mvwaddstr(win, key_pos_y, key_pos_x, fmtkey);
|
mvwaddstr(win, key_pos_y, key_pos_x, fmtkey);
|
||||||
custom_remove_attr(win, ATTR_HIGHEST);
|
custom_remove_attr(win, ATTR_HIGHEST);
|
||||||
mvwaddstr(win, label_pos_y, label_pos_x,
|
mvwaddstr(win, label_pos_y, label_pos_x, label);
|
||||||
gettext(keydef[binding_key].sb_label));
|
|
||||||
}
|
}
|
||||||
wnoutrefresh(win);
|
wnoutrefresh(win);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user