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

Implemented /BIND [<key> [<action> [<data>]]] command.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@435 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-07-08 22:31:11 +00:00 committed by cras
parent 7074381bea
commit 3164aecad0
5 changed files with 76 additions and 14 deletions

View File

@ -19,8 +19,10 @@
*/
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "commands.h"
#include "levels.h"
#include "lib-config/iconfig.h"
#include "settings.h"
@ -55,7 +57,7 @@ static void keyconfig_clear(const char *id, const char *key)
if (key == NULL)
iconfig_node_set_str(node, id, NULL);
else {
node = config_node_section(node, id, 0);
node = config_node_section(node, id, -1);
if (node != NULL) iconfig_node_set_str(node, key, NULL);
}
}
@ -261,6 +263,51 @@ static void read_keyboard_config(void)
}
}
static void cmd_show_keys(const char *searchkey)
{
GSList *info, *key;
int len;
len = searchkey == NULL ? 0 : strlen(searchkey);
for (info = keyinfos; info != NULL; info = info->next) {
KEYINFO_REC *rec = info->data;
for (key = rec->keys; key != NULL; key = key->next) {
KEY_REC *rec = key->data;
if (len == 0 || strncmp(rec->key, searchkey, len) == 0) {
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_BIND_KEY,
rec->key, rec->info->id, rec->data == NULL ? "" : rec->data);
}
}
}
}
static void cmd_bind(const char *data)
{
GHashTable *optlist;
char *key, *id, *keydata;
void *free_arg;
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS,
"bind", &optlist, &key, &id, &keydata))
return;
if (*key != '\0' && g_hash_table_lookup(optlist, "delete")) {
key_configure_remove(key);
} else if (*id == '\0') {
/* show some/all keys */
cmd_show_keys(key);
} else if (key_info_find(id) == NULL)
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_BIND_UNKNOWN_ID, id);
else {
key_configure_add(id, key, keydata);
cmd_show_keys(key);
}
cmd_params_free(free_arg);
}
void keyboard_init(void)
{
keys = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
@ -270,6 +317,9 @@ void keyboard_init(void)
read_keyboard_config();
signal_add("setup reread", (SIGNAL_FUNC) read_keyboard_config);
command_bind("bind", NULL, (SIGNAL_FUNC) cmd_bind);
command_set_options("bind", "delete");
}
void keyboard_deinit(void)
@ -279,4 +329,5 @@ void keyboard_deinit(void)
g_hash_table_destroy(keys);
signal_remove("setup reread", (SIGNAL_FUNC) read_keyboard_config);
command_unbind("bind", (SIGNAL_FUNC) cmd_bind);
}

View File

@ -14,7 +14,7 @@ typedef struct {
KEYINFO_REC *info;
char *key;
void *data;
char *data;
} KEY_REC;
extern GSList *keyinfos;

View File

@ -97,15 +97,13 @@ FORMAT_REC fecommon_core_formats[] = {
{ "module_unloaded", "Unloaded module %_$0", 1, { 0 } },
/* ---- */
{ NULL, "Misc", 0 },
{ NULL, "Commands", 0 },
{ "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
{ "perl_error", "Perl error: $0", 1, { 0 } },
{ "command_unknown", "Unknown command: $0", 1, { 0 } },
{ "command_ambiguous", "Ambiguous command: $0", 1, { 0 } },
{ "option_unknown", "Unknown option: $0", 1, { 0 } },
{ "option_ambiguous", "Ambiguous option: $0", 1, { 0 } },
{ "option_missing_arg", "Missing required argument for: $0", 1, { 0 } },
{ "command_unknown", "Unknown command: $0", 1, { 0 } },
{ "command_ambiguous", "Ambiguous command: $0", 1, { 0 } },
{ "not_enough_params", "Not enough parameters given", 0 },
{ "not_connected", "Not connected to IRC server yet", 0 },
{ "not_joined", "Not joined to any channels yet", 0 },
@ -113,5 +111,13 @@ FORMAT_REC fecommon_core_formats[] = {
{ "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 },
{ "not_good_idea", "Doing this is not a good idea. Add -YES if you really mean it", 0 },
/* ---- */
{ NULL, "Misc", 0 },
{ "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
{ "perl_error", "Perl error: $0", 1, { 0 } },
{ "bind_key", "$[10]0 $1 $2", 3, { 0, 0, 0 } },
{ "bind_unknown_id", "Unknown bind action: $0", 1, { 0 } },
{ NULL, NULL, 0 }
};

View File

@ -71,19 +71,24 @@ enum {
IRCTXT_FILL_7,
IRCTXT_NOT_TOGGLE,
IRCTXT_PERL_ERROR,
IRCTXT_COMMAND_UNKNOWN,
IRCTXT_COMMAND_AMBIGUOUS,
IRCTXT_OPTION_UNKNOWN,
IRCTXT_OPTION_AMBIGUOUS,
IRCTXT_OPTION_MISSING_ARG,
IRCTXT_COMMAND_UNKNOWN,
IRCTXT_COMMAND_AMBIGUOUS,
IRCTXT_NOT_ENOUGH_PARAMS,
IRCTXT_NOT_CONNECTED,
IRCTXT_NOT_JOINED,
IRCTXT_CHAN_NOT_FOUND,
IRCTXT_CHAN_NOT_SYNCED,
IRCTXT_NOT_GOOD_IDEA
IRCTXT_NOT_GOOD_IDEA,
IRCTXT_FILL_8,
IRCTXT_NOT_TOGGLE,
IRCTXT_PERL_ERROR,
IRCTXT_BIND_KEY,
IRCTXT_BIND_UNKNOWN_ID
};

View File

@ -454,7 +454,7 @@ void gui_readline_init(void)
for (n = 0; changekeys[n] != '\0'; n++) {
key = g_strdup_printf("ALT-%c", changekeys[n]);
ltoa(data, n+1);
key_bind("change window", "Change window", key, data, (SIGNAL_FUNC) sig_change_window);
key_bind("window change", "Change window", key, data, (SIGNAL_FUNC) sig_change_window);
g_free(key);
}
@ -479,7 +479,7 @@ void gui_readline_deinit(void)
key_unbind("next page", (SIGNAL_FUNC) sig_next_page);
key_unbind("special char", (SIGNAL_FUNC) sig_addchar);
key_unbind("change window", (SIGNAL_FUNC) sig_change_window);
key_unbind("window change", (SIGNAL_FUNC) sig_change_window);
signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);