1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 22:06:38 +02:00

core: compute first internal code and expanded name before adding key (issue #1875)

This commit is contained in:
Sébastien Helleu
2023-01-28 22:32:10 +01:00
parent 0d8a6679b3
commit a9289cbdc1
+18 -12
View File
@@ -643,18 +643,27 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
const char *command)
{
struct t_gui_key *new_key;
char *expanded_name;
char *internal_code, *expanded_name;
if (!key || !command)
return NULL;
internal_code = gui_key_get_internal_code (key);
if (!internal_code)
return NULL;
expanded_name = gui_key_get_expanded_name (internal_code);
if (!expanded_name)
{
free (internal_code);
return NULL;
}
new_key = malloc (sizeof (*new_key));
if (!new_key)
return NULL;
new_key->key = gui_key_get_internal_code (key);
if (!new_key->key)
new_key->key = strdup (key);
new_key->key = internal_code;
new_key->command = strdup (command);
gui_key_set_areas (new_key);
gui_key_set_score (new_key);
@@ -671,25 +680,22 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
&gui_keys_count[context], new_key);
}
expanded_name = gui_key_get_expanded_name (new_key->key);
(void) hook_signal_send ("key_bind",
WEECHAT_HOOK_SIGNAL_STRING, expanded_name);
if (gui_key_verbose)
{
gui_chat_printf (NULL,
_("New key binding (context \"%s\"): "
"%s%s => %s%s"),
gui_key_context_string[context],
(expanded_name) ? expanded_name : new_key->key,
expanded_name,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
new_key->command);
}
if (expanded_name)
free (expanded_name);
(void) hook_signal_send ("key_bind",
WEECHAT_HOOK_SIGNAL_STRING, expanded_name);
free (expanded_name);
return new_key;
}