1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Merge pull request #859 from ailin-nemui/delkeys

make default keybinds deletable
This commit is contained in:
ailin-nemui 2018-03-19 16:23:27 +01:00 committed by GitHub
commit 6ffbd0ab54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 6 deletions

View File

@ -6,7 +6,8 @@
%9Parameters:%9
-list: Displays a list of all the bindable commands.
-delete: Removes the binding,
-delete: Removes the binding.
-reset: Reset a key to its default binding.
A name of the binding and the command to perform; if no parameter is given,
the list of bindings will be displayed.

View File

@ -156,6 +156,7 @@ static void keyconfig_save(const char *id, const char *key, const char *data)
static void keyconfig_clear(const char *key)
{
CONFIG_NODE *node;
KEY_REC *rec;
g_return_if_fail(key != NULL);
@ -165,6 +166,11 @@ static void keyconfig_clear(const char *key)
iconfig_node_remove(iconfig_node_traverse("(keyboard", FALSE),
node);
}
if ((rec = g_hash_table_lookup(default_keys, key)) != NULL) {
node = iconfig_node_traverse("(keyboard", TRUE);
node = iconfig_node_section(node, NULL, NODE_TYPE_BLOCK);
iconfig_node_set_str(node, "key", key);
}
}
KEYINFO_REC *key_info_find(const char *id)
@ -569,13 +575,38 @@ void key_configure_remove(const char *key)
g_return_if_fail(key != NULL);
keyconfig_clear(key);
rec = g_hash_table_lookup(keys, key);
if (rec == NULL) return;
keyconfig_clear(key);
key_configure_destroy(rec);
}
/* Reset key to default */
void key_configure_reset(const char *key)
{
KEY_REC *rec;
CONFIG_NODE *node;
g_return_if_fail(key != NULL);
node = key_config_find(key);
if (node != NULL) {
iconfig_node_remove(iconfig_node_traverse("(keyboard", FALSE), node);
}
if ((rec = g_hash_table_lookup(default_keys, key)) != NULL) {
key_configure_create(rec->info->id, rec->key, rec->data);
} else {
rec = g_hash_table_lookup(keys, key);
if (rec == NULL)
return;
key_configure_destroy(rec);
}
}
static int key_emit_signal(KEYBOARD_REC *keyboard, KEY_REC *key)
{
int consumed;
@ -739,7 +770,9 @@ static void cmd_show_keys(const char *searchkey, int full)
for (key = rec->keys; key != NULL; key = key->next) {
KEY_REC *rec = key->data;
if ((len == 0 || g_ascii_strncasecmp(rec->key, searchkey, len) == 0) &&
if ((len == 0 ||
(full ? strncmp(rec->key, searchkey, len) == 0 :
g_ascii_strncasecmp(rec->key, searchkey, len) == 0)) &&
(!full || rec->key[len] == '\0')) {
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_BIND_LIST,
rec->key, rec->info->id, rec->data == NULL ? "" : rec->data);
@ -750,7 +783,7 @@ static void cmd_show_keys(const char *searchkey, int full)
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_BIND_FOOTER);
}
/* SYNTAX: BIND [-list] [-delete] [<key> [<command> [<data>]]] */
/* SYNTAX: BIND [-list] [-delete | -reset] [<key> [<command> [<data>]]] */
static void cmd_bind(const char *data)
{
GHashTable *optlist;
@ -780,6 +813,12 @@ static void cmd_bind(const char *data)
key_configure_remove(key);
cmd_params_free(free_arg);
return;
} else if (*key != '\0' && g_hash_table_lookup(optlist, "reset")) {
/* reset key */
key_configure_reset(key);
cmd_show_keys(key, TRUE);
cmd_params_free(free_arg);
return;
}
if (*id == '\0') {
@ -878,8 +917,13 @@ static void key_config_read(CONFIG_NODE *node)
id = config_node_get_str(node, "id", NULL);
data = config_node_get_str(node, "data", NULL);
if (key != NULL && id != NULL)
if (key != NULL && id != NULL) {
key_configure_create(id, key, data);
} else if (key != NULL && id == NULL && data == NULL) {
KEY_REC *rec = g_hash_table_lookup(keys, key);
if (rec != NULL)
key_configure_destroy(rec);
}
}
static void read_keyboard_config(void)
@ -938,7 +982,7 @@ void keyboard_init(void)
signal_add("complete command bind", (SIGNAL_FUNC) sig_complete_bind);
command_bind("bind", NULL, (SIGNAL_FUNC) cmd_bind);
command_set_options("bind", "delete list");
command_set_options("bind", "delete reset list");
}
void keyboard_deinit(void)