From 919a40f5612b5b2ce91284de337da17d6161edad Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 18 Jul 2014 10:25:54 +0200 Subject: 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 --- src/calcurse.h | 11 +++++++++-- src/custom.c | 59 +++++++++++++++++++++++++--------------------------------- src/keys.c | 47 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 75 insertions(+), 42 deletions(-) diff --git a/src/calcurse.h b/src/calcurse.h index d6dfda2..e593ff0 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -463,7 +463,15 @@ enum key { KEY_LOWER_PRIORITY, 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) @@ -678,7 +686,6 @@ unsigned config_save(void); void custom_init_attr(void); void custom_apply_attr(WINDOW *, int); void custom_remove_attr(WINDOW *, int); -void custom_config_bar(void); void custom_layout_config(void); void custom_sidebar_config(void); void custom_color_config(void); diff --git a/src/custom.c b/src/custom.c index f4cbfab..08daa44 100644 --- a/src/custom.c +++ b/src/custom.c @@ -93,35 +93,6 @@ void custom_remove_attr(WINDOW * win, int 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 int bindings[] = { @@ -1036,13 +1007,27 @@ void custom_keys_config(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 = _("Sorry, colors are not supported by your terminal\n" "(Press [ENTER] to continue)"); int ch; 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') { switch (ch) { case 'C': @@ -1081,10 +1066,16 @@ void custom_config_main(void) custom_sidebar_config(); break; default: - continue; + break; } - wins_update(FLAG_ALL); - wins_erase_status_bar(); - 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(); } } diff --git a/src/keys.c b/src/keys.c index 34e6c10..6d4c6f9 100644 --- a/src/keys.c +++ b/src/keys.c @@ -443,16 +443,51 @@ keys_display_bindings_bar(WINDOW * win, int *bindings, int count, else binding_key = KEY_GENERIC_OTHER_CMD; - strncpy(key, keys_action_firstkey(binding_key), - KEYS_KEYLEN); - key[KEYS_KEYLEN] = '\0'; - fmtkey = keys_format_label(key, KEYS_KEYLEN); + const char *label; + + if (binding_key < NBKEYS) { + strncpy(key, keys_action_firstkey(binding_key), + KEYS_KEYLEN); + key[KEYS_KEYLEN] = '\0'; + 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); + fmtkey = keys_format_label(key, KEYS_KEYLEN); mvwaddstr(win, key_pos_y, key_pos_x, fmtkey); custom_remove_attr(win, ATTR_HIGHEST); - mvwaddstr(win, label_pos_y, label_pos_x, - gettext(keydef[binding_key].sb_label)); + mvwaddstr(win, label_pos_y, label_pos_x, label); } wnoutrefresh(win); } -- cgit v1.2.3-54-g00ecf