From: Richard Russon Date: Sun, 25 Aug 2019 22:42:37 +0000 (+0100) Subject: menu: use enum for menu type X-Git-Tag: 2019-10-25~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca6743c0573d3b14b3797896ed661691bd004e9c;p=neomutt menu: use enum for menu type - Use `enum MenuType` rather than `int` - Rename `Menu.menu` to `Menu.type` - Light tidying --- diff --git a/globals.h b/globals.h index b7ea86d4d..567fafa76 100644 --- a/globals.h +++ b/globals.h @@ -27,6 +27,7 @@ #include #include #include "mutt/mutt.h" +#include "keymap.h" #include "where.h" #ifdef MAIN_C @@ -83,7 +84,7 @@ WHERE SIG_ATOMIC_VOLATILE_T SigAlrm; ///< true after SIGALRM is received WHERE SIG_ATOMIC_VOLATILE_T SigInt; ///< true after SIGINT is received WHERE SIG_ATOMIC_VOLATILE_T SigWinch; ///< true after SIGWINCH is received -WHERE int CurrentMenu; ///< Current Menu, e.g. #MENU_PAGER +WHERE enum MenuType CurrentMenu; ///< Current Menu, e.g. #MENU_PAGER WHERE struct AliasList Aliases INITVAL(TAILQ_HEAD_INITIALIZER(Aliases)); ///< List of all the user's email aliases diff --git a/help.c b/help.c index 9321b0615..b0f0a6c34 100644 --- a/help.c +++ b/help.c @@ -52,11 +52,11 @@ static const char *HelpStrings[] = { /** * help_lookup_function - Find a keybinding for an operation * @param op Operation, e.g. OP_DELETE - * @param menu Current Menu + * @param menu Current Menu, e.g. #MENU_PAGER * @retval ptr Key binding * @retval NULL If none */ -static const struct Binding *help_lookup_function(int op, int menu) +static const struct Binding *help_lookup_function(int op, enum MenuType menu) { const struct Binding *map = NULL; @@ -84,12 +84,12 @@ static const struct Binding *help_lookup_function(int op, int menu) * @param buf Buffer for the result * @param buflen Length of buffer * @param txt Text part, e.g. "delete" - * @param menu Current Menu + * @param menu Current Menu, e.g. #MENU_PAGER * @param op Operation, e.g. OP_DELETE * * This will return something like: "d:delete" */ -void mutt_make_help(char *buf, size_t buflen, const char *txt, int menu, int op) +void mutt_make_help(char *buf, size_t buflen, const char *txt, enum MenuType menu, int op) { char tmp[128]; @@ -108,11 +108,12 @@ void mutt_make_help(char *buf, size_t buflen, const char *txt, int menu, int op) * mutt_compile_help - Create the text for the help menu * @param buf Buffer for the result * @param buflen Length of buffer - * @param menu Current Menu + * @param menu Current Menu, e.g. #MENU_PAGER * @param items Map of functions to display in the help bar * @retval ptr Buffer containing result */ -char *mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items) +char *mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, + const struct Mapping *items) { char *pbuf = buf; @@ -368,9 +369,9 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c /** * dump_menu - Write all the key bindings to a file * @param fp File to write to - * @param menu Current Menu + * @param menu Current Menu, e.g. #MENU_PAGER */ -static void dump_menu(FILE *fp, int menu) +static void dump_menu(FILE *fp, enum MenuType menu) { struct Keymap *map = NULL; const struct Binding *b = NULL; @@ -435,7 +436,7 @@ static void dump_unbound(FILE *fp, const struct Binding *funcs, * mutt_help - Display the help menu * @param menu Current Menu */ -void mutt_help(int menu) +void mutt_help(enum MenuType menu) { char t[PATH_MAX]; char buf[128]; diff --git a/index.c b/index.c index 2591e7249..6ff9375b6 100644 --- a/index.c +++ b/index.c @@ -688,7 +688,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, mutt_sleep(0); - /* Note that menu->menu may be MENU_PAGER if the change folder + /* Note that menu->type may be MENU_PAGER if the change folder * operation originated from the pager. * * However, exec commands currently use CurrentMenu to determine what @@ -1203,7 +1203,7 @@ int mutt_index_menu(void) if (op >= 0) mutt_curs_set(0); - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) { index_custom_redraw(menu); @@ -1494,7 +1494,7 @@ int mutt_index_menu(void) /* Similar to OP_MAIN_ENTIRE_THREAD, keep displaying the old message, but * update the index */ - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { menu->current = e_oldcur->vnum; menu->redraw = REDRAW_STATUS | REDRAW_INDEX; @@ -1529,7 +1529,7 @@ int mutt_index_menu(void) mutt_error(_("No deleted messages found in the thread")); /* Similar to OP_MAIN_ENTIRE_THREAD, keep displaying the old message, but * update the index */ - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -1570,7 +1570,7 @@ int mutt_index_menu(void) menu->current = e->vnum; } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -1770,7 +1770,7 @@ int mutt_index_menu(void) resort_index(menu); OptSearchInvalid = true; } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -1942,7 +1942,7 @@ int mutt_index_menu(void) ctx_free(&Context); /* if we were in the pager, redisplay the message */ - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2018,7 +2018,7 @@ int mutt_index_menu(void) mutt_set_vnum(Context); } } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2111,7 +2111,7 @@ int mutt_index_menu(void) CUR_EMAIL->quasi_deleted = !still_queried; Context->mailbox->changed = true; } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2295,7 +2295,7 @@ int mutt_index_menu(void) if (mutt_buffer_enter_fname(cp, folderbuf, true) == -1) { - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; cont = true; @@ -2370,9 +2370,9 @@ int mutt_index_menu(void) Context->mailbox->emails[Context->mailbox->v2r[menu->current]]->index; /* If we are returning to the pager via an index menu redirection, we - * need to reset the menu->menu. Otherwise mutt_menu_pop_current() will + * need to reset the menu->type. Otherwise mutt_menu_pop_current() will * set CurrentMenu incorrectly when we return back to the index menu. */ - menu->menu = MENU_MAIN; + menu->type = MENU_MAIN; op = mutt_display_message(Context->mailbox, CUR_EMAIL); if (op < 0) @@ -2384,20 +2384,20 @@ int mutt_index_menu(void) /* This is used to redirect a single operation back here afterwards. If * mutt_display_message() returns 0, then the menu and pager state will * be cleaned up after this switch statement. */ - menu->menu = MENU_PAGER; + menu->type = MENU_PAGER; menu->oldcurrent = menu->current; update_index(menu, Context, MUTT_NEW_MAIL, Context->mailbox->msg_count, hint); continue; case OP_EXIT: close = op; - if ((menu->menu == MENU_MAIN) && attach_msg) + if ((menu->type == MENU_MAIN) && attach_msg) { done = true; break; } - if ((menu->menu == MENU_MAIN) && + if ((menu->type == MENU_MAIN) && (query_quadoption(C_Quit, _("Exit NeoMutt without saving?")) == MUTT_YES)) { if (Context) @@ -2432,7 +2432,7 @@ int mutt_index_menu(void) Context->mailbox->changed = true; mutt_message(_("Thread broken")); - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2481,7 +2481,7 @@ int mutt_index_menu(void) emaillist_clear(&el); } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2496,7 +2496,7 @@ int mutt_index_menu(void) break; mutt_edit_content_type(CUR_EMAIL, CUR_EMAIL->content, NULL); /* if we were in the pager, redisplay the message */ - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2510,7 +2510,7 @@ int mutt_index_menu(void) break; if (menu->current >= (Context->mailbox->vcount - 1)) { - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) mutt_message(_("You are on the last message")); break; } @@ -2518,10 +2518,10 @@ int mutt_index_menu(void) if (menu->current == -1) { menu->current = menu->oldcurrent; - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) mutt_error(_("No undeleted messages")); } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2535,12 +2535,12 @@ int mutt_index_menu(void) break; if (menu->current >= (Context->mailbox->vcount - 1)) { - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) mutt_message(_("You are on the last message")); break; } menu->current++; - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2561,10 +2561,10 @@ int mutt_index_menu(void) if (menu->current == -1) { menu->current = menu->oldcurrent; - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) mutt_error(_("No undeleted messages")); } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2578,12 +2578,12 @@ int mutt_index_menu(void) break; if (menu->current < 1) { - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) mutt_message(_("You are on the first message")); break; } menu->current--; - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2741,7 +2741,7 @@ int mutt_index_menu(void) mutt_message(_("Search wrapped to bottom")); } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2840,7 +2840,7 @@ int mutt_index_menu(void) break; if (mx_toggle_write(Context->mailbox) == 0) { - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2884,7 +2884,7 @@ int mutt_index_menu(void) else mutt_error(_("You are on the first thread")); } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -2903,7 +2903,7 @@ int mutt_index_menu(void) { menu->current = menu->oldcurrent; } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -3051,7 +3051,7 @@ int mutt_index_menu(void) menu->current = menu->oldcurrent; menu->redraw |= REDRAW_CURRENT; } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -3296,7 +3296,7 @@ int mutt_index_menu(void) emaillist_clear(&el); } - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -3368,7 +3368,7 @@ int mutt_index_menu(void) { menu->current = menu->oldcurrent; } - else if (menu->menu == MENU_PAGER) + else if (menu->type == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; @@ -3639,7 +3639,7 @@ int mutt_index_menu(void) #endif default: - if (menu->menu == MENU_MAIN) + if (menu->type == MENU_MAIN) km_error_key(MENU_MAIN); } @@ -3648,10 +3648,10 @@ int mutt_index_menu(void) nm_db_debug_check(Context->mailbox); #endif - if (menu->menu == MENU_PAGER) + if (menu->type == MENU_PAGER) { mutt_clear_pager_position(); - menu->menu = MENU_MAIN; + menu->type = MENU_MAIN; menu->redraw = REDRAW_FULL; } diff --git a/init.c b/init.c index fe3b26983..e02423e57 100644 --- a/init.c +++ b/init.c @@ -1192,7 +1192,7 @@ warn: */ static bool is_function(const char *name) { - for (int i = 0; i < MENU_MAX; i++) + for (enum MenuType i = 0; i < MENU_MAX; i++) { const struct Binding *b = km_get_table(Menus[i].value); if (!b) diff --git a/keymap.c b/keymap.c index 361143c42..72fcfa5b1 100644 --- a/keymap.c +++ b/keymap.c @@ -284,7 +284,7 @@ static size_t parsekeys(const char *str, keycode_t *d, size_t max) * Insert a key sequence into the specified map. * The map is sorted by ASCII value (lowest to highest) */ -static enum CommandResult km_bind_err(const char *s, int menu, int op, +static enum CommandResult km_bind_err(const char *s, enum MenuType menu, int op, char *macro, char *desc, struct Buffer *err) { enum CommandResult rc = MUTT_CMD_SUCCESS; @@ -389,7 +389,7 @@ static enum CommandResult km_bind_err(const char *s, int menu, int op, * @param desc Description of macro (OPTIONAL) * @retval #CommandResult Result e.g. #MUTT_CMD_SUCCESS */ -enum CommandResult km_bind(char *s, int menu, int op, char *macro, char *desc) +enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc) { return km_bind_err(s, menu, op, macro, desc, NULL); } @@ -402,7 +402,8 @@ enum CommandResult km_bind(char *s, int menu, int op, char *macro, char *desc) * @param err Buffer for error message * @retval #CommandResult Result e.g. #MUTT_CMD_SUCCESS */ -static enum CommandResult km_bindkey_err(const char *s, int menu, int op, struct Buffer *err) +static enum CommandResult km_bindkey_err(const char *s, enum MenuType menu, + int op, struct Buffer *err) { return km_bind_err(s, menu, op, NULL, NULL, err); } @@ -414,7 +415,7 @@ static enum CommandResult km_bindkey_err(const char *s, int menu, int op, struct * @param op Operation, e.g. OP_DELETE * @retval #CommandResult Result e.g. #MUTT_CMD_SUCCESS */ -static enum CommandResult km_bindkey(const char *s, int menu, int op) +static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op) { return km_bindkey_err(s, menu, op, NULL); } @@ -510,9 +511,9 @@ static void generic_tokenize_push_string(char *s, void (*generic_push)(int, int) /* See if it is a valid command * skip the '<' and the '>' when comparing */ - for (i = 0; Menus[i].name; i++) + for (enum MenuType j = 0; Menus[j].name; j++) { - const struct Binding *binding = km_get_table(Menus[i].value); + const struct Binding *binding = km_get_table(Menus[j].value); if (binding) { op = get_op(binding, pp + 1, l - 2); @@ -541,7 +542,7 @@ static void generic_tokenize_push_string(char *s, void (*generic_push)(int, int) * @param lastkey Last key pressed (to return to input queue) * @retval num Operation, e.g. OP_DELETE */ -static int retry_generic(int menu, keycode_t *keys, int keyslen, int lastkey) +static int retry_generic(enum MenuType menu, keycode_t *keys, int keyslen, int lastkey) { if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER)) { @@ -567,7 +568,7 @@ static int retry_generic(int menu, keycode_t *keys, int keyslen, int lastkey) * @retval -1 Error occurred while reading input * @retval -2 A timeout or sigwinch occurred */ -int km_dokey(int menu) +int km_dokey(enum MenuType menu) { struct KeyEvent tmp; struct Keymap *map = Keymaps[menu]; @@ -723,7 +724,7 @@ int km_dokey(int menu) * @param map Key bindings * @param menu Menu id, e.g. #MENU_PAGER */ -static void create_bindings(const struct Binding *map, int menu) +static void create_bindings(const struct Binding *map, enum MenuType menu) { for (int i = 0; map[i].name; i++) if (map[i].seq) @@ -804,7 +805,7 @@ int km_expand_key(char *s, size_t len, struct Keymap *map) * @param func Function, e.g. OP_DELETE * @retval ptr Keymap for the function */ -struct Keymap *km_find_func(int menu, int func) +struct Keymap *km_find_func(enum MenuType menu, int func) { struct Keymap *map = Keymaps[menu]; @@ -1047,7 +1048,7 @@ void km_init(void) * km_error_key - Handle an unbound key sequence * @param menu Menu id, e.g. #MENU_PAGER */ -void km_error_key(int menu) +void km_error_key(enum MenuType menu) { char buf[128]; int p, op; @@ -1119,20 +1120,20 @@ enum CommandResult mutt_parse_push(struct Buffer *buf, struct Buffer *s, /** * parse_keymap - Parse a user-config key binding - * @param menu Array for results - * @param s Buffer containing config string - * @param maxmenus Total number of menus - * @param nummenus Number of menus this config applies to - * @param err Buffer for error messages - * @param bind If true 'bind', otherwise 'macro' + * @param menu Array for results + * @param s Buffer containing config string + * @param max_menus Total number of menus + * @param num_menus Number of menus this config applies to + * @param err Buffer for error messages + * @param bind If true 'bind', otherwise 'macro' * @retval ptr Key string for the binding * * Expects to see: ,,... * * @note Caller needs to free the returned string */ -static char *parse_keymap(int *menu, struct Buffer *s, int maxmenus, - int *nummenus, struct Buffer *err, bool bind) +static char *parse_keymap(enum MenuType *menu, struct Buffer *s, int max_menus, + int *num_menus, struct Buffer *err, bool bind) { struct Buffer buf; int i = 0; @@ -1145,7 +1146,7 @@ static char *parse_keymap(int *menu, struct Buffer *s, int maxmenus, char *p = buf.data; if (MoreArgs(s)) { - while (i < maxmenus) + while (i < max_menus) { q = strchr(p, ','); if (q) @@ -1163,7 +1164,7 @@ static char *parse_keymap(int *menu, struct Buffer *s, int maxmenus, else break; } - *nummenus = i; + *num_menus = i; /* key sequence */ mutt_extract_token(&buf, s, MUTT_TOKEN_NO_FLAGS); @@ -1192,7 +1193,7 @@ error: * @param err Buffer for error message * @retval #CommandResult Result e.g. #MUTT_CMD_SUCCESS */ -static enum CommandResult try_bind(char *key, int menu, char *func, +static enum CommandResult try_bind(char *key, enum MenuType menu, char *func, const struct Binding *bindings, struct Buffer *err) { for (int i = 0; bindings[i].name; i++) @@ -1215,7 +1216,7 @@ static enum CommandResult try_bind(char *key, int menu, char *func, * @param menu Menu id, e.g. #MENU_EDITOR * @retval ptr Array of keybindings */ -const struct Binding *km_get_table(int menu) +const struct Binding *km_get_table(enum MenuType menu) { switch (menu) { @@ -1255,8 +1256,9 @@ const struct Binding *km_get_table(int menu) return OpPost; case MENU_QUERY: return OpQuery; + default: + return NULL; } - return NULL; } /** @@ -1268,10 +1270,11 @@ enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { const struct Binding *bindings = NULL; - int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus; + enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1]; + int num_menus = 0; enum CommandResult rc = MUTT_CMD_SUCCESS; - char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true); + char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true); if (!key) return MUTT_CMD_ERROR; @@ -1284,14 +1287,14 @@ enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, } else if (mutt_str_strcasecmp("noop", buf->data) == 0) { - for (int i = 0; i < nummenus; i++) + for (int i = 0; i < num_menus; i++) { km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */ } } else { - for (int i = 0; i < nummenus; i++) + for (int i = 0; i < num_menus; i++) { /* The pager and editor menus don't use the generic map, * however for other menus try generic first. */ @@ -1325,7 +1328,7 @@ enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, * * Expects to see: [,] */ -static void *parse_menu(int *menu, char *s, struct Buffer *err) +static void *parse_menu(bool *menu, char *s, struct Buffer *err) { char *menu_names_dup = mutt_str_strdup(s); char *marker = menu_names_dup; @@ -1407,15 +1410,15 @@ static void km_unbind_all(struct Keymap **map, unsigned long mode) enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { - int menu[MENU_MAX] = { 0 }; + bool menu[MENU_MAX] = { 0 }; bool all_keys = false; char *key = NULL; mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS); if (mutt_str_strcmp(buf->data, "*") == 0) { - for (int i = 0; i < MENU_MAX; i++) - menu[i] = 1; + for (enum MenuType i = 0; i < MENU_MAX; i++) + menu[i] = true; } else parse_menu(menu, buf->data, err); @@ -1436,9 +1439,9 @@ enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, return MUTT_CMD_ERROR; } - for (int i = 0; i < MENU_MAX; i++) + for (enum MenuType i = 0; i < MENU_MAX; i++) { - if (menu[i] != 1) + if (!menu[i]) continue; if (all_keys) { @@ -1472,11 +1475,12 @@ enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { - int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus; + enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1]; + int num_menus = 0; enum CommandResult rc = MUTT_CMD_ERROR; char *seq = NULL; - char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false); + char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false); if (!key) return MUTT_CMD_ERROR; @@ -1499,7 +1503,7 @@ enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, } else { - for (int i = 0; i < nummenus; i++) + for (int i = 0; i < num_menus; i++) { rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data); } @@ -1509,7 +1513,7 @@ enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, } else { - for (int i = 0; i < nummenus; i++) + for (int i = 0; i < num_menus; i++) { rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL); } diff --git a/keymap.h b/keymap.h index 9e06cb2e7..fd59f74d6 100644 --- a/keymap.h +++ b/keymap.h @@ -36,9 +36,6 @@ /* type for key storage, the rest of neomutt works fine with int type */ typedef short keycode_t; -enum CommandResult km_bind(char *s, int menu, int op, char *macro, char *desc); -int km_dokey(int menu); - void init_extended_keys(void); /** @@ -57,12 +54,6 @@ struct Keymap keycode_t *keys; /**< key sequence */ }; -int km_expand_key(char *s, size_t len, struct Keymap *map); -struct Keymap *km_find_func(int menu, int func); -void km_init(void); -void km_error_key(int menu); -void mutt_what_key(void); - /** * enum MenuType - Types of GUI selections */ @@ -93,6 +84,15 @@ enum MenuType MENU_MAX, }; +int km_expand_key(char *s, size_t len, struct Keymap *map); +struct Keymap *km_find_func(enum MenuType menu, int func); +void km_init(void); +void km_error_key(enum MenuType menu); +void mutt_what_key(void); + +enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc); +int km_dokey(enum MenuType menu); + extern struct Keymap *Keymaps[]; ///< Array of Keymap keybindings, one for each Menu extern int LastKey; ///< Last real key pressed, recorded by dokey() @@ -109,7 +109,7 @@ struct Binding const char *seq; /**< default key binding */ }; -const struct Binding *km_get_table(int menu); +const struct Binding *km_get_table(enum MenuType menu); const char *mutt_get_func(const struct Binding *bindings, int op); extern const struct Binding OpGeneric[]; diff --git a/menu.c b/menu.c index 158727c40..74a092147 100644 --- a/menu.c +++ b/menu.c @@ -980,7 +980,7 @@ struct Menu *mutt_menu_new(enum MenuType type) if (type >= MENU_MAX) type = MENU_GENERIC; - menu->menu = type; + menu->type = type; menu->current = 0; menu->top = 0; menu->offset = 0; @@ -1056,7 +1056,7 @@ void mutt_menu_push_current(struct Menu *menu) } MenuStack[MenuStackCount++] = menu; - CurrentMenu = menu->menu; + CurrentMenu = menu->type; } /** @@ -1079,7 +1079,7 @@ void mutt_menu_pop_current(struct Menu *menu) prev_menu = get_current_menu(); if (prev_menu) { - CurrentMenu = prev_menu->menu; + CurrentMenu = prev_menu->type; prev_menu->redraw = REDRAW_FULL; } else @@ -1113,26 +1113,26 @@ void mutt_menu_set_current_redraw_full(void) /** * mutt_menu_set_redraw - Set redraw flags on a menu - * @param menu_type Menu type, e.g. #MENU_ALIAS - * @param redraw Flags, e.g. #REDRAW_INDEX + * @param menu Menu type, e.g. #MENU_ALIAS + * @param redraw Flags, e.g. #REDRAW_INDEX * * This is ignored if it's not the current menu. */ -void mutt_menu_set_redraw(int menu_type, MuttRedrawFlags redraw) +void mutt_menu_set_redraw(enum MenuType menu, MuttRedrawFlags redraw) { - if (CurrentMenu == menu_type) + if (CurrentMenu == menu) mutt_menu_set_current_redraw(redraw); } /** * mutt_menu_set_redraw_full - Flag a menu to be fully redrawn - * @param menu_type Menu type, e.g. #MENU_ALIAS + * @param menu Menu type, e.g. #MENU_ALIAS * * This is ignored if it's not the current menu. */ -void mutt_menu_set_redraw_full(int menu_type) +void mutt_menu_set_redraw_full(enum MenuType menu) { - if (CurrentMenu == menu_type) + if (CurrentMenu == menu) mutt_menu_set_current_redraw_full(); } @@ -1168,7 +1168,7 @@ static int menu_search(struct Menu *menu, int op) regex_t re; char buf[128]; char *search_buf = - ((menu->menu >= 0) && (menu->menu < MENU_MAX)) ? SearchBuffers[menu->menu] : NULL; + ((menu->type >= 0) && (menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL; if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE))) { @@ -1182,10 +1182,10 @@ static int menu_search(struct Menu *menu, int op) { return -1; } - if ((menu->menu >= 0) && (menu->menu < MENU_MAX)) + if ((menu->type >= 0) && (menu->type < MENU_MAX)) { - mutt_str_replace(&SearchBuffers[menu->menu], buf); - search_buf = SearchBuffers[menu->menu]; + mutt_str_replace(&SearchBuffers[menu->type], buf); + search_buf = SearchBuffers[menu->type]; } menu->search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? MUTT_SEARCH_DOWN : MUTT_SEARCH_UP; @@ -1403,7 +1403,7 @@ int mutt_menu_loop(struct Menu *menu) if (menu->dialog && (menu_dialog_dokey(menu, &i) == 0)) return i; - i = km_dokey(menu->menu); + i = km_dokey(menu->type); if ((i == OP_TAG_PREFIX) || (i == OP_TAG_PREFIX_COND)) { if (menu->tagprefix) @@ -1580,12 +1580,12 @@ int mutt_menu_loop(struct Menu *menu) break; case OP_HELP: - mutt_help(menu->menu); + mutt_help(menu->type); menu->redraw = REDRAW_FULL; break; case OP_NULL: - km_error_key(menu->menu); + km_error_key(menu->type); break; case OP_END_COND: diff --git a/mutt.h b/mutt.h index e9846beb1..63431d0db 100644 --- a/mutt.h +++ b/mutt.h @@ -33,6 +33,7 @@ #include "config/lib.h" #include "email/lib.h" #include "hook.h" +#include "keymap.h" #include "mutt_commands.h" struct Buffer; @@ -137,7 +138,7 @@ struct AttachMatch #define EXEC_SHELL "/bin/sh" -char *mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items); +char *mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items); int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags); void mutt_free_opts(void); diff --git a/mutt_menu.h b/mutt_menu.h index cc6ae72b4..4f5223647 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -81,15 +81,15 @@ enum TreeChar */ struct Menu { - char *title; /**< the title of this menu */ - char *help; /**< quickref for the current menu */ - void *data; /**< extra data for the current menu */ - int current; /**< current entry */ - int max; /**< the number of entries in the menu */ - MuttRedrawFlags redraw; /**< when to redraw the screen */ - int menu; /**< menu definition for keymap entries. */ - int offset; /**< row offset within the window to start the index */ - int pagelen; /**< number of entries per screen */ + char *title; ///< Title of this menu + char *help; ///< Quickref for the current menu + void *data; ///< Extra data for the current menu + int current; ///< Current entry + int max; ///< Number of entries in the menu + MuttRedrawFlags redraw; ///< When to redraw the screen + enum MenuType type; ///< Menu definition for keymap entries + int offset; ///< Row offset within the window to start the index + int pagelen; ///< Number of entries per screen bool tagprefix : 1; bool is_mailbox_list : 1; struct MuttWindow *indexwin; @@ -101,16 +101,16 @@ struct Menu * In dialog mode menubar is hidden and prompt keys are checked before * normal menu movement keys. This can cause problems with scrolling, if * prompt keys override movement keys. */ - char **dialog; /**< dialog lines themselves */ - int dsize; /**< number of allocated dialog lines */ - char *prompt; /**< prompt for user, similar to mutt_multi_choice */ - char *keys; /**< keys used in the prompt */ + char **dialog; ///< Dialog lines themselves + int dsize; ///< Number of allocated dialog lines + char *prompt; ///< Prompt for user, similar to mutt_multi_choice + char *keys; ///< Keys used in the prompt /* the following are used only by mutt_menu_loop() */ - int top; /**< entry that is the top of the current page */ - int oldcurrent; /**< for driver use only */ - int search_dir; /**< direction of search */ - int tagged; /**< number of tagged entries */ + int top; ///< Entry that is the top of the current page + int oldcurrent; ///< For driver use only + int search_dir; ///< Direction of search + int tagged; ///< Number of tagged entries /** * menu_make_entry - Format a item for a menu @@ -119,7 +119,7 @@ struct Menu * @param[in] menu Menu containing items * @param[in] line Menu line number */ - void (*menu_make_entry) (char *buf, size_t buflen, struct Menu *menu, int line); + void (*menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line); /** * menu_search - Search a menu for a item matching a regex * @param menu Menu to search @@ -128,7 +128,7 @@ struct Menu * @retval 0 Success * @retval >0 Error, e.g. REG_NOMATCH */ - int (*menu_search) (struct Menu *menu, regex_t *rx, int line); + int (*menu_search)(struct Menu *menu, regex_t *rx, int line); /** * menu_tag - Tag some menu items * @param menu Menu to tag @@ -136,14 +136,14 @@ struct Menu * @param act Action: 0 untag, 1 tag, -1 toggle * @retval num Net change in number of tagged attachments */ - int (*menu_tag) (struct Menu *menu, int sel, int act); + int (*menu_tag)(struct Menu *menu, int sel, int act); /** * menu_color - Calculate the colour for a line of the menu * @param line Menu line number * @retval >0 Colour pair in an integer * @retval 0 No colour */ - int (*menu_color) (int line); + int (*menu_color)(int line); /** * menu_custom_redraw - Redraw the menu * @param menu Menu to redraw @@ -186,8 +186,8 @@ void mutt_menu_pop_current(struct Menu *menu); void mutt_menu_push_current(struct Menu *menu); void mutt_menu_set_current_redraw_full(void); void mutt_menu_set_current_redraw(MuttRedrawFlags redraw); -void mutt_menu_set_redraw_full(int menu_type); -void mutt_menu_set_redraw(int menu_type, MuttRedrawFlags redraw); +void mutt_menu_set_redraw_full(enum MenuType menu); +void mutt_menu_set_redraw(enum MenuType menu, MuttRedrawFlags redraw); int mutt_menu_observer(struct NotifyCallback *nc); diff --git a/protos.h b/protos.h index 997fbfa4a..9ad5b65bb 100644 --- a/protos.h +++ b/protos.h @@ -30,6 +30,7 @@ #include #include #include "mutt.h" +#include "keymap.h" #include "ncrypt/ncrypt.h" struct Context; @@ -62,8 +63,8 @@ int mutt_ev_message(struct Mailbox *m, struct EmailList *el, enum EvMessage acti int mutt_system(const char *cmd); int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize); -void mutt_help(int menu); -void mutt_make_help(char *d, size_t dlen, const char *txt, int menu, int op); +void mutt_help(enum MenuType menu); +void mutt_make_help(char *d, size_t dlen, const char *txt, enum MenuType menu, int op); void mutt_set_flag_update(struct Mailbox *m, struct Email *e, int flag, bool bf, bool upd_mbox); #define mutt_set_flag(m, e, flag, bf) mutt_set_flag_update(m, e, flag, bf, true) void mutt_signal_init(void);