mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
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.
This commit is contained in:
parent
921f12926f
commit
93ef5e02f5
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user