summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2009-04-07 18:22:09 +0200
committerSebastien Helleu <flashcode@flashtux.org>2009-04-07 18:22:09 +0200
commit8ac00cdac6ba3a2caf9a7b282701e3bb22c988de (patch)
treec83a769c48b7682df37ac2ab61e2fda75d75527b /src/core
parent3aeb24cf1dcfead638b14a8c855128ee7f7f45c2 (diff)
downloadweechat-8ac00cdac6ba3a2caf9a7b282701e3bb22c988de.zip
Some improvements on key bindings
List of changes: - do not automatically create default keys if they do not exist, when reading weechat.conf (let user do that if needed) - add "/key missing": add missing keys using default keys (do not update or remove user keys), - key "meta-s" moved from irc/jabber plugins to core - improved output of /key (display number of keys)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c78
-rw-r--r--src/core/wee-config.c67
-rw-r--r--src/core/weechat.c2
3 files changed, 81 insertions, 66 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index f9b3a6092..cd11607c3 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -1705,28 +1705,16 @@ command_input (void *data, struct t_gui_buffer *buffer,
*/
void
-command_key_display (struct t_gui_key *key, int new_key)
+command_key_display (struct t_gui_key *key)
{
char *expanded_name;
-
+
expanded_name = gui_keyboard_get_expanded_name (key->key);
- if (new_key)
- {
- gui_chat_printf (NULL,
- _("New key binding: %s%s => %s%s"),
- (expanded_name) ? expanded_name : key->key,
- GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
- GUI_COLOR(GUI_COLOR_CHAT),
- key->command);
- }
- else
- {
- gui_chat_printf (NULL, " %20s%s => %s%s",
- (expanded_name) ? expanded_name : key->key,
- GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
- GUI_COLOR(GUI_COLOR_CHAT),
- key->command);
- }
+ gui_chat_printf (NULL, " %20s%s => %s%s",
+ (expanded_name) ? expanded_name : key->key,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ key->command);
if (expanded_name)
free (expanded_name);
}
@@ -1741,6 +1729,7 @@ command_key (void *data, struct t_gui_buffer *buffer,
{
char *internal_code;
struct t_gui_key *ptr_key;
+ int old_keys_count, keys_added;
/* make C compiler happy */
(void) data;
@@ -1749,11 +1738,17 @@ command_key (void *data, struct t_gui_buffer *buffer,
/* display all key bindings */
if (argc == 1)
{
- gui_chat_printf (NULL, "");
- gui_chat_printf (NULL, _("Key bindings:"));
- for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ if (gui_keys_count == 0)
+ gui_chat_printf (NULL, _("No key binding defined"));
+ else
{
- command_key_display (ptr_key, 0);
+ gui_chat_printf (NULL, "");
+ gui_chat_printf (NULL, _("Key bindings (%d):"),
+ gui_keys_count);
+ for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
+ {
+ command_key_display (ptr_key);
+ }
}
return WEECHAT_RC_OK;
}
@@ -1764,7 +1759,7 @@ command_key (void *data, struct t_gui_buffer *buffer,
if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0))
{
gui_keyboard_free_all (&gui_keys, &last_gui_key);
- gui_keyboard_init ();
+ gui_keyboard_default_bindings ();
gui_chat_printf (NULL,
_("Default key bindings restored"));
}
@@ -1779,6 +1774,21 @@ command_key (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
+ /* 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);
+ return WEECHAT_RC_OK;
+ }
+
/* unbind a key */
if (string_strcasecmp (argv[1], "unbind") == 0)
{
@@ -1813,7 +1823,7 @@ command_key (void *data, struct t_gui_buffer *buffer,
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Key:"));
- command_key_display (ptr_key, 0);
+ command_key_display (ptr_key);
}
else
{
@@ -1824,14 +1834,12 @@ command_key (void *data, struct t_gui_buffer *buffer,
free (internal_code);
return WEECHAT_RC_OK;
}
-
+
/* bind new key */
+ gui_keyboard_verbose = 1;
ptr_key = gui_keyboard_bind (NULL, argv[1], argv_eol[2]);
- if (ptr_key)
- {
- command_key_display (ptr_key, 1);
- }
- else
+ gui_keyboard_verbose = 0;
+ if (!ptr_key)
{
gui_chat_printf (NULL,
_("%sError: unable to bind key \"%s\""),
@@ -3783,12 +3791,14 @@ command_init ()
&command_input, NULL);
hook_command (NULL, "key",
N_("bind/unbind keys"),
- N_("[key [command [args]]] | [unbind key] | [reset -yes]"),
+ N_("[key [command [args]]] | [unbind key] | [reset -yes] | "
+ "[missing]"),
N_(" key: display or bind this key to a command\n"
" unbind: unbind a key\n"
" reset: restore bindings to the default values and "
- "delete ALL personal bindings (use carefully!)"),
- "unbind|reset",
+ "delete ALL personal bindings (use carefully!)\n"
+ " missing: add missing keys (using default bindings)"),
+ "unbind|reset|missing",
&command_key, NULL);
hook_command (NULL, "layout",
N_("save/apply/reset layout for buffers and windows"),
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index 38c549663..5841516f0 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -395,15 +395,15 @@ config_change_day_change (void *data, struct t_config_option *option)
}
/*
- * config_weechat_reload: reload WeeChat configuration file
- * return one of these values:
- * WEECHAT_CONFIG_READ_OK
- * WEECHAT_CONFIG_READ_MEMORY_ERROR
- * WEECHAT_CONFIG_READ_FILE_NOT_FOUND
+ * config_weechat_reload_cb: reload WeeChat configuration file
+ * return one of these values:
+ * WEECHAT_CONFIG_READ_OK
+ * WEECHAT_CONFIG_READ_MEMORY_ERROR
+ * WEECHAT_CONFIG_READ_FILE_NOT_FOUND
*/
int
-config_weechat_reload (void *data, struct t_config_file *config_file)
+config_weechat_reload_cb (void *data, struct t_config_file *config_file)
{
int rc;
@@ -412,7 +412,6 @@ config_weechat_reload (void *data, struct t_config_file *config_file)
/* remove all keys */
gui_keyboard_free_all (&gui_keys, &last_gui_key);
- gui_keyboard_default_bindings ();
/* remove all proxies */
proxy_free_all ();
@@ -434,6 +433,9 @@ config_weechat_reload (void *data, struct t_config_file *config_file)
proxy_use_temp_proxies ();
gui_bar_use_temp_bars ();
gui_bar_create_default ();
+ /* if no key was found config file, then we use default bindings */
+ if (!gui_keys)
+ gui_keyboard_default_bindings ();
}
return rc;
@@ -476,12 +478,12 @@ config_weechat_debug_set_all ()
}
/*
- * config_weechat_debug_change: called when a debug option is changed
+ * config_weechat_debug_change_cb: called when a debug option is changed
*/
void
-config_weechat_debug_change (void *data,
- struct t_config_option *option)
+config_weechat_debug_change_cb (void *data,
+ struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
@@ -491,15 +493,15 @@ config_weechat_debug_change (void *data,
}
/*
- * config_weechat_debug_create_option: create option in "debug" section
+ * config_weechat_debug_create_option_cb: create option in "debug" section
*/
int
-config_weechat_debug_create_option (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name,
- const char *value)
+config_weechat_debug_create_option_cb (void *data,
+ struct t_config_file *config_file,
+ struct t_config_section *section,
+ const char *option_name,
+ const char *value)
{
struct t_config_option *ptr_option;
int rc;
@@ -532,7 +534,7 @@ config_weechat_debug_create_option (void *data,
option_name, "integer",
_("debug level for plugin (\"core\" for WeeChat core)"),
NULL, 0, 32, "0", value, 0, NULL, NULL,
- &config_weechat_debug_change, NULL,
+ &config_weechat_debug_change_cb, NULL,
NULL, NULL);
rc = (ptr_option) ?
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
@@ -549,14 +551,14 @@ config_weechat_debug_create_option (void *data,
}
/*
- * config_weechat_debug_delete_option: delete option in "debug" section
+ * config_weechat_debug_delete_option_cb: delete option in "debug" section
*/
int
-config_weechat_debug_delete_option (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- struct t_config_option *option)
+config_weechat_debug_delete_option_cb (void *data,
+ struct t_config_file *config_file,
+ struct t_config_section *section,
+ struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
@@ -577,11 +579,11 @@ config_weechat_debug_delete_option (void *data,
int
config_weechat_debug_set (const char *plugin_name, const char *value)
{
- return config_weechat_debug_create_option (NULL,
- weechat_config_file,
- weechat_config_section_debug,
- plugin_name,
- value);
+ return config_weechat_debug_create_option_cb (NULL,
+ weechat_config_file,
+ weechat_config_section_debug,
+ plugin_name,
+ value);
}
/*
@@ -994,7 +996,7 @@ config_weechat_init_options ()
struct t_config_section *ptr_section;
weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_NAME,
- &config_weechat_reload, NULL);
+ &config_weechat_reload_cb, NULL);
if (!weechat_config_file)
return 0;
@@ -1003,8 +1005,8 @@ config_weechat_init_options ()
1, 1,
NULL, NULL, NULL, NULL,
NULL, NULL,
- &config_weechat_debug_create_option, NULL,
- &config_weechat_debug_delete_option, NULL);
+ &config_weechat_debug_create_option_cb, NULL,
+ &config_weechat_debug_delete_option_cb, NULL);
if (!ptr_section)
{
config_file_free (weechat_config_file);
@@ -1863,8 +1865,11 @@ config_weechat_read ()
proxy_use_temp_proxies ();
gui_bar_use_temp_bars ();
gui_bar_create_default ();
+ /* if no key was found config file, then we use default bindings */
+ if (!gui_keys)
+ gui_keyboard_default_bindings ();
}
-
+
if (rc != WEECHAT_CONFIG_READ_OK)
{
gui_chat_printf (NULL,
diff --git a/src/core/weechat.c b/src/core/weechat.c
index fb4b48092..236f5c3db 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -388,7 +388,7 @@ main (int argc, char *argv[])
gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */
weechat_init_vars (); /* initialize some variables */
command_init (); /* initialize WeeChat commands */
- gui_keyboard_init (); /* init keyb. (default key bindings)*/
+ gui_keyboard_init (); /* init keyboard */
if (!config_weechat_init ()) /* init options with default values */
exit (EXIT_FAILURE);
weechat_parse_args (argc, argv); /* parse command line args */