From 93ef5e02f56768a296fdf46400a8ab181a1a6a1f Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 14:04:17 +0300 Subject: [PATCH] really_add_keybinding: Display the canonical name of the keystroke. Before really_add_keybinding() is called, check_keystroke() calls parse_keystroke(), which converts the modifier prefix to canonical form: for example, "alt+f9" becomes "Alt-f9". This commit makes really_add_keybinding() normally ignore that string and generate a brand new one, e.g. "Alt-F9" (note the upper-case F), for its "Keystroke already used" warning. Likewise, " " turns to "Space". After this commit, it should be possible to change parse_keystroke() to never write back into its input string. If really_add_keybinding() cannot generate the string for some reason (out of memory?), then it will use whatever parse_keystroke() has left in the buffer. The alternatives would be to omit the keystroke name from the warning or to reject the keybinding entirely; it isn't clear what the best solution is here, but the one I implemented is closest to the previous behaviour. --- src/config/dialogs.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config/dialogs.c b/src/config/dialogs.c index 0b4aa279..46b37b6e 100644 --- a/src/config/dialogs.c +++ b/src/config/dialogs.c @@ -817,26 +817,41 @@ really_add_keybinding(void *data, unsigned char *keystroke) struct kbdbind_add_hop *hop = data; action_id_T action_id; + /* check_keystroke() has parsed @keystroke to @hop->kbd. */ if (keybinding_exists(hop->keymap_id, &hop->kbd, &action_id) && action_id != ACT_MAIN_NONE) { struct kbdbind_add_hop *new_hop; + struct string canonical = NULL_STRING; /* Same keystroke for same action, just return. */ if (action_id == hop->action_id) return; + /* @*hop is on the memory_list of the input_dialog, + * which will be closed when this function returns. */ new_hop = new_hop_from(hop); if (!new_hop) return; /* out of mem */ + /* Try to convert the parsed keystroke back to a + * string, so that the "Keystroke already used" box + * displays the same canonical name as the keybinding + * manager does. If something goes wrong here, then + * canonical.length will probably be 0, in which case + * we'll use the original @keystroke string instead. */ + if (init_string(&canonical)) + add_keystroke_to_string(&canonical, &hop->kbd, 0); + msg_box(new_hop->term, getml(new_hop, NULL), MSGBOX_FREE_TEXT, N_("Keystroke already used"), ALIGN_CENTER, msg_text(new_hop->term, N_("The keystroke \"%s\" " "is currently used for \"%s\".\n" "Are you sure you want to replace it?"), - keystroke, get_action_name(hop->keymap_id, action_id)), + canonical.length ? canonical.source : keystroke, + get_action_name(hop->keymap_id, action_id)), new_hop, 2, N_("~Yes"), really_really_add_keybinding, B_ENTER, N_("~No"), NULL, B_ESC); + done_string(&canonical); /* safe even if init failed */ return; } -- 2.11.4.GIT