summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-07-05 15:36:42 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-07-05 15:36:42 +0200
commit3bea55b2f0759541b0d8930396eb4fc1f7d62ecc (patch)
tree08d5886e45a114e02e7a8aa9b30708466d102970 /src/core
parent5250b68d0a1d9871b9d89ff1253290372a747cf6 (diff)
downloadweechat-3bea55b2f0759541b0d8930396eb4fc1f7d62ecc.zip
core: add context "search" for keys (to define keys used during search in buffer with ctrl+"r")
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c520
-rw-r--r--src/core/wee-completion.c110
-rw-r--r--src/core/wee-config.c81
-rw-r--r--src/core/wee-debug.c4
-rw-r--r--src/core/weechat.c40
5 files changed, 525 insertions, 230 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index a47450d84..24c886190 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -59,7 +59,7 @@
#include "../gui/gui-history.h"
#include "../gui/gui-hotlist.h"
#include "../gui/gui-input.h"
-#include "../gui/gui-keyboard.h"
+#include "../gui/gui-key.h"
#include "../gui/gui-layout.h"
#include "../gui/gui-main.h"
#include "../gui/gui-window.h"
@@ -2123,6 +2123,14 @@ COMMAND_CALLBACK(input)
gui_input_complete_previous (buffer);
else if (string_strcasecmp (argv[1], "search_text") == 0)
gui_input_search_text (buffer);
+ else if (string_strcasecmp (argv[1], "search_previous") == 0)
+ gui_input_search_previous (buffer);
+ else if (string_strcasecmp (argv[1], "search_next") == 0)
+ gui_input_search_next (buffer);
+ else if (string_strcasecmp (argv[1], "search_switch_case") == 0)
+ gui_input_search_switch_case (buffer);
+ else if (string_strcasecmp (argv[1], "search_stop") == 0)
+ gui_input_search_stop (buffer);
else if (string_strcasecmp (argv[1], "delete_previous_char") == 0)
gui_input_delete_previous_char (buffer);
else if (string_strcasecmp (argv[1], "delete_next_char") == 0)
@@ -2208,7 +2216,7 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key)
char str_spaces[20 + 1];
int length_screen, num_spaces;
- expanded_name = gui_keyboard_get_expanded_name (key->key);
+ expanded_name = gui_key_get_expanded_name (key->key);
str_spaces[0] = '\0';
length_screen = utf8_strlen_screen ((expanded_name) ?
@@ -2255,17 +2263,20 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key)
void
command_key_display_list (const char *message_no_key,
const char *message_keys,
+ int context,
struct t_gui_key *keys,
int keys_count)
{
struct t_gui_key *ptr_key;
if (keys_count == 0)
- gui_chat_printf (NULL, message_no_key);
+ gui_chat_printf (NULL, message_no_key,
+ gui_key_context_string[context]);
else
{
gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, message_keys, keys_count);
+ gui_chat_printf (NULL, message_keys,
+ keys_count, gui_key_context_string[context]);
for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key)
{
command_key_display (ptr_key, NULL);
@@ -2279,17 +2290,17 @@ command_key_display_list (const char *message_no_key,
*/
void
-command_key_display_listdiff ()
+command_key_display_listdiff (int context)
{
struct t_gui_key *ptr_key, *ptr_default_key;
int count_added, count_deleted;
/* list keys added or redefined */
count_added = 0;
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
{
- ptr_default_key = gui_keyboard_search (gui_default_keys,
- ptr_key->key);
+ ptr_default_key = gui_key_search (gui_default_keys[context],
+ ptr_key->key);
if (!ptr_default_key
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
{
@@ -2299,12 +2310,15 @@ command_key_display_listdiff ()
if (count_added > 0)
{
gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, _("Key bindings added or redefined (%d):"),
- count_added);
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
- {
- ptr_default_key = gui_keyboard_search (gui_default_keys,
- ptr_key->key);
+ gui_chat_printf (NULL,
+ _("Key bindings added or redefined (%d) for "
+ "context \"%s\":"),
+ count_added,
+ _(gui_key_context_string[context]));
+ for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
+ {
+ ptr_default_key = gui_key_search (gui_default_keys[context],
+ ptr_key->key);
if (!ptr_default_key
|| (strcmp (ptr_default_key->command, ptr_key->command) != 0))
{
@@ -2315,21 +2329,24 @@ command_key_display_listdiff ()
/* list keys deleted */
count_deleted = 0;
- for (ptr_default_key = gui_default_keys; ptr_default_key;
+ for (ptr_default_key = gui_default_keys[context]; ptr_default_key;
ptr_default_key = ptr_default_key->next_key)
{
- ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
+ ptr_key = gui_key_search (gui_keys[context], ptr_default_key->key);
if (!ptr_key)
count_deleted++;
- }
+ }
if (count_deleted > 0)
{
gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, _("Key bindings deleted (%d):"), count_deleted);
- for (ptr_default_key = gui_default_keys; ptr_default_key;
+ gui_chat_printf (NULL,
+ _("Key bindings deleted (%d) for context \"%s\":"),
+ count_deleted,
+ _(gui_key_context_string[context]));
+ for (ptr_default_key = gui_default_keys[context]; ptr_default_key;
ptr_default_key = ptr_default_key->next_key)
{
- ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
+ ptr_key = gui_key_search (gui_keys[context], ptr_default_key->key);
if (!ptr_key)
{
command_key_display (ptr_default_key, NULL);
@@ -2341,10 +2358,104 @@ command_key_display_listdiff ()
if ((count_added == 0) && (count_deleted == 0))
{
gui_chat_printf (NULL,
- _("No key binding added, redefined or removed"));
+ _("No key binding added, redefined or removed "
+ "for context \"%s\""),
+ _(gui_key_context_string[context]));
}
}
-
+
+/*
+ * command_key_reset: reset a key for a given context
+ */
+
+int
+command_key_reset (int context, const char *key)
+{
+ char *internal_code;
+ struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key;
+
+ internal_code = gui_key_get_internal_code (key);
+ if (!internal_code)
+ return WEECHAT_RC_ERROR;
+
+ ptr_key = gui_key_search (gui_keys[context],
+ internal_code);
+ ptr_default_key = gui_key_search (gui_default_keys[context],
+ internal_code);
+ free (internal_code);
+
+ if (ptr_key || ptr_default_key)
+ {
+ if (ptr_key && ptr_default_key)
+ {
+ if (strcmp (ptr_key->command, ptr_default_key->command) != 0)
+ {
+ gui_key_verbose = 1;
+ ptr_new_key = gui_key_bind (NULL, context, key,
+ ptr_default_key->command);
+ gui_key_verbose = 0;
+ if (!ptr_new_key)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to bind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ key);
+ return WEECHAT_RC_OK;
+ }
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("Key \"%s\" has already default "
+ "value"),
+ key);
+ }
+ }
+ else if (ptr_key)
+ {
+ /* no default key, so just unbind key */
+ if (gui_key_unbind (NULL, context, key, 1))
+ {
+ gui_chat_printf (NULL,
+ _("Key \"%s\" unbound (context: \"%s\")"),
+ key,
+ gui_key_context_string[context]);
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to unbind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ key);
+ return WEECHAT_RC_OK;
+ }
+ }
+ else
+ {
+ /* no key, but default key exists */
+ gui_key_verbose = 1;
+ ptr_new_key = gui_key_bind (NULL, context, key,
+ ptr_default_key->command);
+ gui_key_verbose = 0;
+ if (!ptr_new_key)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to bind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ key);
+ return WEECHAT_RC_OK;
+ }
+ }
+ }
+ else
+ {
+ gui_chat_printf (NULL, _("%sKey \"%s\" not found"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ key);
+ }
+ return WEECHAT_RC_OK;
+}
+
/*
* command_key: bind/unbind keys
*/
@@ -2352,8 +2463,8 @@ command_key_display_listdiff ()
COMMAND_CALLBACK(key)
{
char *internal_code;
- struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key;
- int old_keys_count, keys_added;
+ struct t_gui_key *ptr_new_key;
+ int old_keys_count, keys_added, i, context;
/* make C compiler happy */
(void) data;
@@ -2362,39 +2473,68 @@ COMMAND_CALLBACK(key)
/* display all key bindings (current keys) */
if ((argc == 1) || (string_strcasecmp (argv[1], "list") == 0))
{
- command_key_display_list (_("No key binding defined"),
- _("Key bindings (%d):"),
- gui_keys,
- gui_keys_count);
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if ((argc < 3)
+ || (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
+ {
+ command_key_display_list (_("No key binding defined for "
+ "context \"%s\""),
+ _("Key bindings (%d) for "
+ "context \"%s\":"),
+ i, gui_keys[i], gui_keys_count[i]);
+ }
+ }
return WEECHAT_RC_OK;
}
/* display redefined or key bindings added */
if (string_strcasecmp (argv[1], "listdiff") == 0)
{
- command_key_display_listdiff ();
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if ((argc < 3)
+ || (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
+ {
+ command_key_display_listdiff (i);
+ }
+ }
return WEECHAT_RC_OK;
}
/* display default key bindings */
if (string_strcasecmp (argv[1], "listdefault") == 0)
{
- command_key_display_list (_("No default key binding"),
- _("Default key bindings (%d):"),
- gui_default_keys,
- gui_default_keys_count);
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if ((argc < 3)
+ || (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
+ {
+ command_key_display_list (_("No default key binding for "
+ "context \"%s\""),
+ _("Default key bindings (%d) for "
+ "context \"%s\":"),
+ i,
+ gui_default_keys[i],
+ gui_default_keys_count[i]);
+ }
+ }
return WEECHAT_RC_OK;
}
/* bind a key (or display binding) */
if (string_strcasecmp (argv[1], "bind") == 0)
{
+ COMMAND_MIN_ARGS(3, "key bind");
+
+ /* display a key binding */
if (argc == 3)
{
ptr_new_key = NULL;
- internal_code = gui_keyboard_get_internal_code (argv[2]);
+ internal_code = gui_key_get_internal_code (argv[2]);
if (internal_code)
- ptr_new_key = gui_keyboard_search (gui_keys, internal_code);
+ ptr_new_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT],
+ internal_code);
if (ptr_new_key)
{
gui_chat_printf (NULL, "");
@@ -2411,12 +2551,11 @@ COMMAND_CALLBACK(key)
return WEECHAT_RC_OK;
}
- COMMAND_MIN_ARGS(4, "key bind");
-
/* bind new key */
- gui_keyboard_verbose = 1;
- ptr_new_key = gui_keyboard_bind (NULL, argv[2], argv_eol[3]);
- gui_keyboard_verbose = 0;
+ gui_key_verbose = 1;
+ ptr_new_key = gui_key_bind (NULL, GUI_KEY_CONTEXT_DEFAULT,
+ argv[2], argv_eol[3]);
+ gui_key_verbose = 0;
if (!ptr_new_key)
{
gui_chat_printf (NULL,
@@ -2428,25 +2567,115 @@ COMMAND_CALLBACK(key)
return WEECHAT_RC_OK;
}
- /* unbind a key */
- if (string_strcasecmp (argv[1], "unbind") == 0)
+ /* bind a key for given context (or display binding) */
+ if (string_strcasecmp (argv[1], "bindctxt") == 0)
{
- if (argc >= 3)
+ COMMAND_MIN_ARGS(4, "key bindctxt");
+
+ /* search context */
+ context = gui_key_search_context (argv[2]);
+ if (context < 0)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: context \"%s\" not found"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[2]);
+ return WEECHAT_RC_OK;
+ }
+
+ /* display a key binding */
+ if (argc == 4)
{
- if (gui_keyboard_unbind (NULL, argv[2], 1))
+ ptr_new_key = NULL;
+ internal_code = gui_key_get_internal_code (argv[2]);
+ if (internal_code)
+ ptr_new_key = gui_key_search (gui_keys[context],
+ internal_code);
+ if (ptr_new_key)
{
- gui_chat_printf (NULL,
- _("Key \"%s\" unbound"),
- argv[2]);
+ gui_chat_printf (NULL, "");
+ gui_chat_printf (NULL, _("Key:"));
+ command_key_display (ptr_new_key, NULL);
}
else
{
gui_chat_printf (NULL,
- _("%sError: unable to unbind key \"%s\""),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[2]);
- return WEECHAT_RC_OK;
+ _("No key found"));
}
+ if (internal_code)
+ free (internal_code);
+ return WEECHAT_RC_OK;
+ }
+
+ /* bind new key */
+ gui_key_verbose = 1;
+ ptr_new_key = gui_key_bind (NULL, context,
+ argv[3], argv_eol[4]);
+ gui_key_verbose = 0;
+ if (!ptr_new_key)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to bind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[3]);
+ return WEECHAT_RC_OK;
+ }
+ return WEECHAT_RC_OK;
+ }
+
+ /* unbind a key */
+ if (string_strcasecmp (argv[1], "unbind") == 0)
+ {
+ COMMAND_MIN_ARGS(3, "key unbind");
+
+ if (gui_key_unbind (NULL, GUI_KEY_CONTEXT_DEFAULT, argv[2], 1))
+ {
+ gui_chat_printf (NULL,
+ _("Key \"%s\" unbound (context: \"%s\")"),
+ argv[2],
+ gui_key_context_string[GUI_KEY_CONTEXT_DEFAULT]);
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to unbind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[2]);
+ return WEECHAT_RC_OK;
+ }
+ return WEECHAT_RC_OK;
+ }
+
+ /* unbind a key for a given context */
+ if (string_strcasecmp (argv[1], "unbindctxt") == 0)
+ {
+ COMMAND_MIN_ARGS(4, "key unbindctxt");
+
+ /* search context */
+ context = gui_key_search_context (argv[2]);
+ if (context < 0)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: context \"%s\" not found"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[2]);
+ return WEECHAT_RC_OK;
+ }
+
+ if (gui_key_unbind (NULL, context, argv[3], 1))
+ {
+ gui_chat_printf (NULL,
+ _("Key \"%s\" unbound (context: \"%s\")"),
+ argv[3],
+ gui_key_context_string[context]);
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%sError: unable to unbind key \"%s\""),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[3]);
+ return WEECHAT_RC_OK;
}
return WEECHAT_RC_OK;
}
@@ -2454,86 +2683,28 @@ COMMAND_CALLBACK(key)
/* reset a key to default binding */
if (string_strcasecmp (argv[1], "reset") == 0)
{
- if (argc >= 3)
+ COMMAND_MIN_ARGS(3, "key reset");
+
+ return command_key_reset (GUI_KEY_CONTEXT_DEFAULT, argv[2]);
+ }
+
+ /* reset a key to default binding for a given context */
+ if (string_strcasecmp (argv[1], "resetctxt") == 0)
+ {
+ COMMAND_MIN_ARGS(4, "key reset");
+
+ /* search context */
+ context = gui_key_search_context (argv[2]);
+ if (context < 0)
{
- internal_code = gui_keyboard_get_internal_code (argv[2]);
- if (!internal_code)
- return WEECHAT_RC_ERROR;
-
- ptr_key = gui_keyboard_search (gui_keys, internal_code);
- ptr_default_key = gui_keyboard_search (gui_default_keys, internal_code);
- free (internal_code);
-
- if (ptr_key || ptr_default_key)
- {
- if (ptr_key && ptr_default_key)
- {
- if (strcmp (ptr_key->command, ptr_default_key->command) != 0)
- {
- gui_keyboard_verbose = 1;
- ptr_new_key = gui_keyboard_bind (NULL, argv[2],
- ptr_default_key->command);
- gui_keyboard_verbose = 0;
- if (!ptr_new_key)
- {
- gui_chat_printf (NULL,
- _("%sError: unable to bind key \"%s\""),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[2]);
- return WEECHAT_RC_OK;
- }
- }
- else
- {
- gui_chat_printf (NULL,
- _("Key \"%s\" has already default "
- "value"),
- argv[2]);
- }
- }
- else if (ptr_key)
- {
- /* no default key, so just unbind key */
- if (gui_keyboard_unbind (NULL, argv[2], 1))
- {
- gui_chat_printf (NULL,
- _("Key \"%s\" unbound"),
- argv[2]);
- }
- else
- {
- gui_chat_printf (NULL,
- _("%sError: unable to unbind key \"%s\""),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[2]);
- return WEECHAT_RC_OK;
- }
- }
- else
- {
- /* no key, but default key exists */
- gui_keyboard_verbose = 1;
- ptr_new_key = gui_keyboard_bind (NULL, argv[2],
- ptr_default_key->command);
- gui_keyboard_verbose = 0;
- if (!ptr_new_key)
- {
- gui_chat_printf (NULL,
- _("%sError: unable to bind key \"%s\""),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[2]);
- return WEECHAT_RC_OK;
- }
- }
- }
- else
- {
- gui_chat_printf (NULL, _("%sKey \"%s\" not found"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
- argv[2]);
- }
+ gui_chat_printf (NULL,
+ _("%sError: context \"%s\" not found"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ argv[2]);
+ return WEECHAT_RC_OK;
}
- return WEECHAT_RC_OK;
+
+ return command_key_reset (context, argv[3]);
}
/* reset ALL keys (only with "-yes", for security reason) */
@@ -2541,10 +2712,20 @@ COMMAND_CALLBACK(key)
{
if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0))
{
- gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count);
- gui_keyboard_default_bindings ();
- gui_chat_printf (NULL,
- _("Default key bindings restored"));
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if ((argc < 4)
+ || (string_strcasecmp (argv[3], gui_key_context_string[i]) == 0))
+ {
+ gui_key_free_all (&gui_keys[i], &last_gui_key[i],
+ &gui_keys_count[i]);
+ gui_key_default_bindings (i);
+ gui_chat_printf (NULL,
+ _("Default key bindings restored for "
+ "context \"%s\""),
+ gui_key_context_string[i]);
+ }
+ }
}
else
{
@@ -2560,15 +2741,24 @@ COMMAND_CALLBACK(key)
/* add missing keys */
if (string_strcasecmp (argv[1], "missing") == 0)
{
- old_keys_count = gui_keys_count;
- gui_keyboard_verbose = 1;
- gui_keyboard_default_bindings ();
- gui_keyboard_verbose = 0;
- keys_added = (gui_keys_count > old_keys_count) ?
- gui_keys_count - old_keys_count : 0;
- gui_chat_printf (NULL,
- NG_("%d new key added", "%d new keys added", keys_added),
- keys_added);
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if ((argc < 3)
+ || (string_strcasecmp (argv[2], gui_key_context_string[i]) == 0))
+ {
+ old_keys_count = gui_keys_count[i];
+ gui_key_verbose = 1;
+ gui_key_default_bindings (i);
+ gui_key_verbose = 0;
+ keys_added = (gui_keys_count[i] > old_keys_count) ?
+ gui_keys_count[i] - old_keys_count : 0;
+ gui_chat_printf (NULL,
+ NG_("%d new key added", "%d new keys added "
+ "(context: \"%s\")", keys_added),
+ keys_added,
+ gui_key_context_string[i]);
+ }
+ }
return WEECHAT_RC_OK;
}
@@ -4980,6 +5170,10 @@ command_init ()
" complete_previous: complete word with previous "
"completion\n"
" search_text: search text in buffer\n"
+ " search_switch_case: switch exact case for search\n"
+ " search_previous: search previous line\n"
+ " search_next: search next line\n"
+ " search_stop: stop search\n"
" delete_previous_char: delete previous char\n"
" delete_next_char: delete next char\n"
" delete_previous_word: delete previous word\n"
@@ -5027,6 +5221,7 @@ command_init ()
" insert: insert text in command line\n\n"
"This command is used by key bindings or plugins."),
"return|complete_next|complete_previous|search_text|"
+ "search_switch_case|search_previous|search_next|search_stop|"
"delete_previous_char|delete_next_char|"
"delete_previous_word|delete_next_word|"
"delete_beginning_of_line|delete_end_of_line|"
@@ -5043,21 +5238,33 @@ command_init ()
&command_input, NULL);
hook_command (NULL, "key",
N_("bind/unbind keys"),
- N_("list|listdefault|listdiff"
+ N_("list|listdefault|listdiff [<context>]"
" || bind <key> [<command> [<args>]]"
+ " || bindctxt <context> <key> [<command> [<args>]]"
" || unbind <key>"
+ " || unbindctxt <context> <key>"
" || reset <key>"
- " || resetall -yes"
- " || missing"),
+ " || resetctxt <context> <key>"
+ " || resetall -yes [<context>]"
+ " || missing [<context>]"),
N_(" list: list all current keys (without argument, "
"this list is displayed)\n"
"listdefault: list default keys\n"
" listdiff: list differences between current and "
- "default keys (keys added, redefined or deleted)\n"
+ "default keys (keys added, redefined or deleted)\n"
+ " context: name of context (\"default\" or "
+ "\"search\")\n"
" bind: bind a command to a key or display command "
- "bound to key\n"
- " unbind: remove a key binding\n"
- " reset: reset a key to default binding\n"
+ "bound to key (for context \"default\")\n"
+ " bindctxt: bind a command to a key or display command "
+ "bound to key, for given context\n"
+ " unbind: remove a key binding (for context "
+ "\"default\")\n"
+ " unbindctxt: remove a key binding for given context\n"
+ " reset: reset a key to default binding (for "
+ "context \"default\")\n"
+ " resetctxt: reset a key to default binding, for given "
+ "context\n"
" resetall: restore bindings to the default values and "
"delete ALL personal bindings (use carefully!)\n"
" missing: add missing keys (using default bindings), "
@@ -5071,15 +5278,20 @@ command_init ()
" key alt-r to jump to #weechat IRC channel:\n"
" /key bind meta-r /buffer #weechat\n"
" restore default binding for key alt-r:\n"
- " /key reset meta-r"),
- "list"
- " || listdefault"
- " || listdiff"
+ " /key reset meta-r\n"
+ " key \"tab\" to stop search in buffer:\n"
+ " /key bindctxt search ctrl-I /input search_stop"),
+ "list %(keys_contexts)"
+ " || listdefault %(keys_contexts)"
+ " || listdiff %(keys_contexts)"
" || bind %(keys_codes) %(commands)"
+ " || bindctxt %(keys_contexts) %(keys_codes) %(commands)"
" || unbind %(keys_codes)"
+ " || unbindctxt %(keys_contexts) %(keys_codes)"
" || reset %(keys_codes_for_reset)"
+ " || resetctxt %(keys_contexts) %(keys_codes_for_reset)"
" || resetall"
- " || missing",
+ " || missing %(keys_contexts)",
&command_key, NULL);
hook_command (NULL, "layout",
N_("save/apply/reset layout for buffers and windows"),
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index 5298fd0cf..49cdf9a91 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -48,7 +48,7 @@
#include "../gui/gui-buffer.h"
#include "../gui/gui-color.h"
#include "../gui/gui-filter.h"
-#include "../gui/gui-keyboard.h"
+#include "../gui/gui-key.h"
#include "../gui/gui-nicklist.h"
@@ -1106,6 +1106,32 @@ completion_list_add_proxies_options_cb (void *data,
}
/*
+ * completion_list_add_keys_contexts_cb: add keys contexts to completion list
+ */
+
+int
+completion_list_add_keys_contexts_cb (void *data,
+ const char *completion_item,
+ struct t_gui_buffer *buffer,
+ struct t_gui_completion *completion)
+{
+ int i;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) completion_item;
+ (void) buffer;
+
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ gui_completion_list_add (completion, gui_key_context_string[i],
+ 0, WEECHAT_LIST_POS_END);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* completion_list_add_keys_codes_cb: add keys to completion list
*/
@@ -1115,6 +1141,7 @@ completion_list_add_keys_codes_cb (void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
+ int i;
struct t_gui_key *ptr_key;
char *expanded_name;
@@ -1122,15 +1149,18 @@ completion_list_add_keys_codes_cb (void *data,
(void) data;
(void) completion_item;
(void) buffer;
-
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
{
- expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
- gui_completion_list_add (completion,
- (expanded_name) ? expanded_name : ptr_key->key,
- 0, WEECHAT_LIST_POS_SORT);
- if (expanded_name)
- free (expanded_name);
+ for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
+ {
+ expanded_name = gui_key_get_expanded_name (ptr_key->key);
+ gui_completion_list_add (completion,
+ (expanded_name) ? expanded_name : ptr_key->key,
+ 0, WEECHAT_LIST_POS_SORT);
+ if (expanded_name)
+ free (expanded_name);
+ }
}
return WEECHAT_RC_OK;
@@ -1148,6 +1178,7 @@ completion_list_add_keys_codes_for_reset_cb (void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
+ int i;
struct t_gui_key *ptr_key, *ptr_default_key;
char *expanded_name;
@@ -1155,36 +1186,39 @@ completion_list_add_keys_codes_for_reset_cb (void *data,
(void) data;
(void) completion_item;
(void) buffer;
-
- /* keys added or redefined */
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
{
- ptr_default_key = gui_keyboard_search (gui_default_keys, ptr_key->key);
- if (!ptr_default_key
- || (strcmp (ptr_default_key->command, ptr_key->command) != 0))
+ /* keys added or redefined */
+ for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
{
- expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
- gui_completion_list_add (completion,
- (expanded_name) ? expanded_name : ptr_key->key,
- 0, WEECHAT_LIST_POS_SORT);
- if (expanded_name)
- free (expanded_name);
+ ptr_default_key = gui_key_search (gui_default_keys[i], ptr_key->key);
+ if (!ptr_default_key
+ || (strcmp (ptr_default_key->command, ptr_key->command) != 0))
+ {
+ expanded_name = gui_key_get_expanded_name (ptr_key->key);
+ gui_completion_list_add (completion,
+ (expanded_name) ? expanded_name : ptr_key->key,
+ 0, WEECHAT_LIST_POS_SORT);
+ if (expanded_name)
+ free (expanded_name);
+ }
}
- }
-
- /* keys deleted */
- for (ptr_default_key = gui_default_keys; ptr_default_key;
- ptr_default_key = ptr_default_key->next_key)
- {
- ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key);
- if (!ptr_key)
+
+ /* keys deleted */
+ for (ptr_default_key = gui_default_keys[i]; ptr_default_key;
+ ptr_default_key = ptr_default_key->next_key)
{
- expanded_name = gui_keyboard_get_expanded_name (ptr_default_key->key);
- gui_completion_list_add (completion,
- (expanded_name) ? expanded_name : ptr_default_key->key,
- 0, WEECHAT_LIST_POS_SORT);
- if (expanded_name)
- free (expanded_name);
+ ptr_key = gui_key_search (gui_keys[i], ptr_default_key->key);
+ if (!ptr_key)
+ {
+ expanded_name = gui_key_get_expanded_name (ptr_default_key->key);
+ gui_completion_list_add (completion,
+ (expanded_name) ? expanded_name : ptr_default_key->key,
+ 0, WEECHAT_LIST_POS_SORT);
+ if (expanded_name)
+ free (expanded_name);
+ }
}
}
@@ -1264,10 +1298,16 @@ completion_init ()
hook_completion (NULL, "bars_options",
N_("options for bars"),
&completion_list_add_bars_options_cb, NULL);
+ hook_completion (NULL, "keys_contexts",
+ /* TRANSLATORS: "key" means "key on the keyboard" */
+ N_("key contexts"),
+ &completion_list_add_keys_contexts_cb, NULL);
hook_completion (NULL, "keys_codes",
+ /* TRANSLATORS: "key" means "key on the keyboard" */
N_("key codes"),
&completion_list_add_keys_codes_cb, NULL);
hook_completion (NULL, "keys_codes_for_reset",
+ /* TRANSLATORS: "key" means "key on the keyboard" */
N_("key codes that can be reset (keys added, redefined "
"or removed)"),
&completion_list_add_keys_codes_for_reset_cb, NULL);
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index 94f0af776..da8de105b 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -52,7 +52,7 @@
#include "../gui/gui-color.h"
#include "../gui/gui-filter.h"
#include "../gui/gui-hotlist.h"
-#include "../gui/gui-keyboard.h"
+#include "../gui/gui-key.h"
#include "../gui/gui-layout.h"
#include "../gui/gui-line.h"
#include "../gui/gui-main.h"
@@ -581,6 +581,8 @@ config_day_change_timer_cb (void *data, int remaining_calls)
void
config_weechat_init_after_read ()
{
+ int i;
+
gui_buffer_notify_set_all ();
proxy_use_temp_proxies ();
@@ -601,8 +603,11 @@ config_weechat_init_after_read ()
}
/* if no key was found config file, then we use default bindings */
- if (!gui_keys)
- gui_keyboard_default_bindings ();
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ if (!gui_keys[i])
+ gui_key_default_bindings (i);
+ }
}
/*
@@ -616,13 +621,17 @@ config_weechat_init_after_read ()
int
config_weechat_reload_cb (void *data, struct t_config_file *config_file)
{
- int rc;
+ int i, rc;
/* make C compiler happy */
(void) data;
/* remove all keys */
- gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count);
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
+ {
+ gui_key_free_all (&gui_keys[i], &last_gui_key[i],
+ &gui_keys_count[i]);
+ }
/* remove all proxies */
proxy_free_all ();
@@ -1425,22 +1434,33 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name, const char *value)
{
+ int context;
+ char *pos;
+
/* make C compiler happy */
(void) data;
(void) config_file;
- (void) section;
if (option_name)
{
+ context = GUI_KEY_CONTEXT_DEFAULT;
+ pos = strchr (section->name, '_');
+ if (pos)
+ {
+ context = gui_key_search_context (pos + 1);
+ if (context < 0)
+ context = GUI_KEY_CONTEXT_DEFAULT;
+ }
+
if (value && value[0])
{
/* bind key (overwrite any binding with same key) */
- gui_keyboard_bind (NULL, option_name, value);
+ gui_key_bind (NULL, context, option_name, value);
}
else
{
/* unbind key if no value given */
- gui_keyboard_unbind (NULL, option_name, 1);
+ gui_key_unbind (NULL, context, option_name, 1);
}
}
@@ -1456,18 +1476,26 @@ config_weechat_key_write_cb (void *data, struct t_config_file *config_file,
const char *section_name)
{
struct t_gui_key *ptr_key;
- char *expanded_name;
- int rc;
+ char *pos, *expanded_name;
+ int rc, context;
/* make C compiler happy */
(void) data;
if (!config_file_write_line (config_file, section_name, NULL))
return WEECHAT_CONFIG_WRITE_ERROR;
-
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+
+ context = GUI_KEY_CONTEXT_DEFAULT;
+ pos = strchr (section_name, '_');
+ if (pos)
+ {
+ context = gui_key_search_context (pos + 1);
+ if (context < 0)
+ context = GUI_KEY_CONTEXT_DEFAULT;
+ }
+ for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key)
{
- expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
+ expanded_name = gui_key_get_expanded_name (ptr_key->key);
if (expanded_name)
{
rc = config_file_write_line (config_file,
@@ -1493,6 +1521,8 @@ int
config_weechat_init_options ()
{
struct t_config_section *ptr_section;
+ int i;
+ char section_name[128];
weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_NAME,
&config_weechat_reload_cb, NULL);
@@ -2507,16 +2537,23 @@ config_weechat_init_options ()
}
/* keys */
- ptr_section = config_file_new_section (weechat_config_file, "key",
- 0, 0,
- &config_weechat_key_read_cb, NULL,
- &config_weechat_key_write_cb, NULL,
- &config_weechat_key_write_cb, NULL,
- NULL, NULL, NULL, NULL);
- if (!ptr_section)
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
{
- config_file_free (weechat_config_file);
- return 0;
+ snprintf (section_name, sizeof (section_name),
+ "key%s%s",
+ (i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
+ (i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
+ ptr_section = config_file_new_section (weechat_config_file, section_name,
+ 0, 0,
+ &config_weechat_key_read_cb, NULL,
+ &config_weechat_key_write_cb, NULL,
+ &config_weechat_key_write_cb, NULL,
+ NULL, NULL, NULL, NULL);
+ if (!ptr_section)
+ {
+ config_file_free (weechat_config_file);
+ return 0;
+ }
}
return 1;
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c
index b79c4c43d..14eabec89 100644
--- a/src/core/wee-debug.c
+++ b/src/core/wee-debug.c
@@ -49,7 +49,7 @@
#include "../gui/gui-chat.h"
#include "../gui/gui-filter.h"
#include "../gui/gui-hotlist.h"
-#include "../gui/gui-keyboard.h"
+#include "../gui/gui-key.h"
#include "../gui/gui-layout.h"
#include "../gui/gui-main.h"
#include "../gui/gui-window.h"
@@ -92,7 +92,7 @@ debug_dump (int crash)
gui_window_print_log ();
gui_buffer_print_log ();
gui_layout_print_log ();
- gui_keyboard_print_log (NULL);
+ gui_key_print_log (NULL);
gui_filter_print_log ();
gui_bar_print_log ();
gui_bar_item_print_log ();
diff --git a/src/core/weechat.c b/src/core/weechat.c
index 26fe4f6d9..aebfda775 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -72,7 +72,7 @@
#include "../gui/gui-completion.h"
#include "../gui/gui-layout.h"
#include "../gui/gui-main.h"
-#include "../gui/gui-keyboard.h"
+#include "../gui/gui-key.h"
#include "../plugins/plugin.h"
@@ -164,22 +164,28 @@ weechat_display_keys ()
{
struct t_gui_key *ptr_key;
char *expanded_name;
-
- gui_keyboard_default_bindings ();
- string_iconv_fprintf (stdout,
- /* TRANSLATORS: "%s" is "weechat" */
- _("%s default keys:\n"),
- PACKAGE_NAME);
- string_iconv_fprintf (stdout, "\n");
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ int i;
+
+ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
{
- expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
+ gui_key_default_bindings (i);
string_iconv_fprintf (stdout,
- "* %s => %s\n",
- (expanded_name) ? expanded_name : ptr_key->key,
- ptr_key->command);
- if (expanded_name)
- free (expanded_name);
+ /* TRANSLATORS: first "%s" is "weechat" */
+ _("%s default keys (context: \"%s\"):\n"),
+ (gui_key_context_string[i] && gui_key_context_string[i][0]) ?
+ _(gui_key_context_string[i]) : "",
+ PACKAGE_NAME);
+ string_iconv_fprintf (stdout, "\n");
+ for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key)
+ {
+ expanded_name = gui_key_get_expanded_name (ptr_key->key);
+ string_iconv_fprintf (stdout,
+ "* %s => %s\n",
+ (expanded_name) ? expanded_name : ptr_key->key,
+ ptr_key->command);
+ if (expanded_name)
+ free (expanded_name);
+ }
}
}
@@ -418,7 +424,7 @@ main (int argc, char *argv[])
gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */
command_init (); /* initialize WeeChat commands */
completion_init (); /* add core completion hooks */
- gui_keyboard_init (); /* init keyboard */
+ gui_key_init (); /* init keys */
if (!config_weechat_init ()) /* init options with default values */
exit (EXIT_FAILURE);
weechat_parse_args (argc, argv); /* parse command line args */
@@ -451,7 +457,7 @@ main (int argc, char *argv[])
gui_main_end (1); /* shut down WeeChat GUI */
proxy_free_all (); /* free all proxies */
config_file_free_all (); /* free all configuration files */
- gui_keyboard_end (); /* end keyboard */
+ gui_key_end (); /* remove all keys */
unhook_all (); /* remove all hooks */
hdata_end (); /* end hdata */
weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */