diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-28 22:32:10 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-29 12:41:23 +0100 |
commit | a9289cbdc149a424995af7cae6a0fed8d8308fc4 (patch) | |
tree | 84bb75a5f5f49ef581db8a3d3faf15e8e98312e2 | |
parent | 0d8a6679b37b5fcf816f84b6a9e3c8d61967b7f9 (diff) | |
download | weechat-a9289cbdc149a424995af7cae6a0fed8d8308fc4.zip |
core: compute first internal code and expanded name before adding key (issue #1875)
-rw-r--r-- | src/gui/gui-key.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 6ca95b23f..ed6a3667d 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -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; } |