1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

core: check new keys manually added with /set

This commit is contained in:
Sébastien Helleu
2023-03-11 23:44:44 +01:00
parent 042968b016
commit 3b8f9d4547
6 changed files with 57 additions and 39 deletions
+11 -34
View File
@@ -3917,33 +3917,6 @@ command_key_display_listdiff (int context)
}
}
/*
* Binds a key in the given context.
*/
void
command_key_bind (int context, const char *key, const char *command)
{
if (CONFIG_BOOLEAN(config_look_key_bind_safe)
&& (context != GUI_KEY_CONTEXT_MOUSE)
&& !gui_key_is_safe (context, key))
{
gui_chat_printf (NULL,
_("%sIt is not safe to bind key \"%s\" because "
"it does not start with a ctrl or meta code "
"(tip: use alt-k to find key codes); if you "
"want to bind this key anyway, turn off option "
"weechat.look.key_bind_safe"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
key);
return;
}
gui_key_verbose = 1;
(void) gui_key_bind (NULL, context, key, command);
gui_key_verbose = 0;
}
/*
* Resets a key in the given context.
*/
@@ -3964,8 +3937,8 @@ command_key_reset (int context, const char *key)
if (strcmp (ptr_key->command, ptr_default_key->command) != 0)
{
gui_key_verbose = 1;
(void) gui_key_bind (NULL, context, key,
ptr_default_key->command);
(void) gui_key_bind (NULL, context,
key, ptr_default_key->command, 1);
gui_key_verbose = 0;
}
else
@@ -3995,7 +3968,8 @@ command_key_reset (int context, const char *key)
{
/* no key, but default key exists */
gui_key_verbose = 1;
(void) gui_key_bind (NULL, context, key, ptr_default_key->command);
(void) gui_key_bind (NULL, context,
key, ptr_default_key->command, 1);
gui_key_verbose = 0;
}
}
@@ -4105,7 +4079,10 @@ COMMAND_CALLBACK(key)
return WEECHAT_RC_OK;
}
command_key_bind (GUI_KEY_CONTEXT_DEFAULT, argv[2], argv_eol[3]);
gui_key_verbose = 1;
(void) gui_key_bind (NULL, GUI_KEY_CONTEXT_DEFAULT,
argv[2], argv_eol[3], 1);
gui_key_verbose = 0;
return WEECHAT_RC_OK;
}
@@ -4144,7 +4121,9 @@ COMMAND_CALLBACK(key)
return WEECHAT_RC_OK;
}
command_key_bind (context, argv[3], argv_eol[4]);
gui_key_verbose = 1;
gui_key_bind (NULL, context, argv[3], argv_eol[4], 1);
gui_key_verbose = 0;
return WEECHAT_RC_OK;
}
@@ -6417,8 +6396,6 @@ COMMAND_CALLBACK(set)
_("Option changed: ") :
_("Option created: "));
}
else
gui_chat_printf (NULL, _("Option changed"));
break;
}
+18 -1
View File
@@ -333,6 +333,7 @@ struct t_config_option *config_signal_sigusr2;
/* other */
int config_loading = 0;
int config_length_nick_prefix_suffix = 0;
int config_length_prefix_same_nick = 0;
int config_length_prefix_same_nick_middle = 0;
@@ -1627,7 +1628,9 @@ config_weechat_reload_cb (const void *pointer, void *data,
/* remove all filters */
gui_filter_free_all ();
config_loading = 1;
rc = config_file_reload (config_file);
config_loading = 0;
config_weechat_init_after_read ();
@@ -2666,7 +2669,19 @@ config_weechat_key_create_option_cb (const void *pointer, void *data,
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
context = config_weechat_get_key_context (section);
(void) gui_key_bind (NULL, context, option_name, value);
if (config_loading)
{
/* don't check key when loading config */
(void) gui_key_bind (NULL, context, option_name, value, 0);
}
else
{
/* enable verbose and check key if option is manually created */
gui_key_verbose = 1;
(void) gui_key_bind (NULL, context, option_name, value, 1);
gui_key_verbose = 0;
}
return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
@@ -5052,7 +5067,9 @@ config_weechat_read ()
{
int rc;
config_loading = 1;
rc = config_file_read (weechat_config_file);
config_loading = 0;
config_weechat_init_after_read ();
+1 -1
View File
@@ -2378,7 +2378,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
}
else if (strncmp (property, "key_bind_", 9) == 0)
{
(void) gui_key_bind (buffer, 0, property + 9, value);
(void) gui_key_bind (buffer, 0, property + 9, value, 0);
}
else if (strncmp (property, "key_unbind_", 11) == 0)
{
+24 -1
View File
@@ -1542,6 +1542,8 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context,
* If buffer is not null, then key is specific to buffer otherwise it's general
* key (for most keys).
*
* If check_key == 1, the key is checked before being added.
*
* If key already exists, it is removed then added again with new value.
*
* Returns pointer to new key, NULL if error.
@@ -1549,11 +1551,32 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context,
struct t_gui_key *
gui_key_bind (struct t_gui_buffer *buffer, int context, const char *key,
const char *command)
const char *command, int check_key)
{
if (!key || !command)
return NULL;
if (check_key)
{
if (CONFIG_BOOLEAN(config_look_key_bind_safe)
&& (context != GUI_KEY_CONTEXT_MOUSE)
&& !gui_key_is_safe (context, key))
{
if (gui_key_verbose)
{
gui_chat_printf (
NULL,
_("%sIt is not safe to bind key \"%s\" because it does "
"not start with a ctrl or meta code (tip: use alt-k to "
"find key codes); if you want to bind this key anyway, "
"turn off option weechat.look.key_bind_safe"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
key);
}
return NULL;
}
}
gui_key_unbind (buffer, context, key);
return gui_key_new (buffer, context, key, command, 1);
+2 -2
View File
@@ -95,7 +95,6 @@ extern void gui_key_grab_init (int grab_raw_key, int grab_command,
extern int gui_key_expand (const char *key,
char **key_name, char **key_name_alias);
extern char *gui_key_legacy_to_alias (const char *key);
extern int gui_key_is_safe (int context, const char *key);
extern struct t_gui_key *gui_key_new (struct t_gui_buffer *buffer,
int context,
const char *key,
@@ -106,7 +105,8 @@ extern struct t_gui_key *gui_key_search (struct t_gui_key *keys,
extern struct t_gui_key *gui_key_bind (struct t_gui_buffer *buffer,
int context,
const char *key,
const char *command);
const char *command,
int check_key);
extern int gui_key_bind_plugin (const char *context, struct t_hashtable *keys);
extern int gui_key_unbind (struct t_gui_buffer *buffer, int context,
const char *key);
+1
View File
@@ -34,6 +34,7 @@ extern "C"
extern int gui_key_get_current_context ();
extern char *gui_key_legacy_internal_code (const char *key);
extern char *gui_key_fix (const char *key);
extern int gui_key_is_safe (int context, const char *key);
extern struct t_config_option *gui_key_new_option (int context,
const char *name,
const char *value);