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:
commit
6ffbd0ab54
@ -6,7 +6,8 @@
|
|||||||
%9Parameters:%9
|
%9Parameters:%9
|
||||||
|
|
||||||
-list: Displays a list of all the bindable commands.
|
-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,
|
A name of the binding and the command to perform; if no parameter is given,
|
||||||
the list of bindings will be displayed.
|
the list of bindings will be displayed.
|
||||||
|
@ -156,6 +156,7 @@ static void keyconfig_save(const char *id, const char *key, const char *data)
|
|||||||
static void keyconfig_clear(const char *key)
|
static void keyconfig_clear(const char *key)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
|
KEY_REC *rec;
|
||||||
|
|
||||||
g_return_if_fail(key != NULL);
|
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),
|
iconfig_node_remove(iconfig_node_traverse("(keyboard", FALSE),
|
||||||
node);
|
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)
|
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);
|
g_return_if_fail(key != NULL);
|
||||||
|
|
||||||
|
keyconfig_clear(key);
|
||||||
|
|
||||||
rec = g_hash_table_lookup(keys, key);
|
rec = g_hash_table_lookup(keys, key);
|
||||||
if (rec == NULL) return;
|
if (rec == NULL) return;
|
||||||
|
|
||||||
keyconfig_clear(key);
|
|
||||||
key_configure_destroy(rec);
|
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)
|
static int key_emit_signal(KEYBOARD_REC *keyboard, KEY_REC *key)
|
||||||
{
|
{
|
||||||
int consumed;
|
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) {
|
for (key = rec->keys; key != NULL; key = key->next) {
|
||||||
KEY_REC *rec = key->data;
|
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')) {
|
(!full || rec->key[len] == '\0')) {
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_BIND_LIST,
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_BIND_LIST,
|
||||||
rec->key, rec->info->id, rec->data == NULL ? "" : rec->data);
|
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);
|
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)
|
static void cmd_bind(const char *data)
|
||||||
{
|
{
|
||||||
GHashTable *optlist;
|
GHashTable *optlist;
|
||||||
@ -780,6 +813,12 @@ static void cmd_bind(const char *data)
|
|||||||
key_configure_remove(key);
|
key_configure_remove(key);
|
||||||
cmd_params_free(free_arg);
|
cmd_params_free(free_arg);
|
||||||
return;
|
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') {
|
if (*id == '\0') {
|
||||||
@ -878,8 +917,13 @@ static void key_config_read(CONFIG_NODE *node)
|
|||||||
id = config_node_get_str(node, "id", NULL);
|
id = config_node_get_str(node, "id", NULL);
|
||||||
data = config_node_get_str(node, "data", 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);
|
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)
|
static void read_keyboard_config(void)
|
||||||
@ -938,7 +982,7 @@ void keyboard_init(void)
|
|||||||
signal_add("complete command bind", (SIGNAL_FUNC) sig_complete_bind);
|
signal_add("complete command bind", (SIGNAL_FUNC) sig_complete_bind);
|
||||||
|
|
||||||
command_bind("bind", NULL, (SIGNAL_FUNC) cmd_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)
|
void keyboard_deinit(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user