From 96e6ae3fc31470db029ed99e3b55693f60a11067 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Wed, 24 Mar 2010 19:54:31 +0100 Subject: Add new options for command /key (listdefault, listdiff and reset), add examples in /help key Note: old option "reset" for /key has been renamed to "resetall". --- src/core/wee-command.c | 314 ++++++++++++++++++++++++++++++----- src/core/wee-config.c | 2 +- src/gui/curses/gui-curses-keyboard.c | 3 +- src/gui/curses/gui-curses-window.c | 4 +- src/gui/gui-bar-window.c | 2 +- src/gui/gui-buffer.c | 20 ++- src/gui/gui-buffer.h | 1 + src/gui/gui-completion.c | 59 +++++++ src/gui/gui-keyboard.c | 95 ++++++++--- src/gui/gui-keyboard.h | 9 +- src/plugins/irc/irc-command.c | 4 +- 11 files changed, 427 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index b37f359a1..c618cc4b5 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1374,7 +1374,7 @@ command_filter (void *data, struct t_gui_buffer *buffer, _("%sError: filter \"%s\" not found"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], argv[2]); - return WEECHAT_RC_ERROR; + return WEECHAT_RC_ERROR; } } return WEECHAT_RC_OK; @@ -1903,7 +1903,7 @@ command_input (void *data, struct t_gui_buffer *buffer, */ void -command_key_display (struct t_gui_key *key) +command_key_display (struct t_gui_key *key, struct t_gui_key *default_key) { char *expanded_name; char str_spaces[20 + 1]; @@ -1921,17 +1921,131 @@ command_key_display (struct t_gui_key *key) str_spaces[num_spaces] = '\0'; } - gui_chat_printf (NULL, " %s%s%s => %s%s", - str_spaces, - (expanded_name) ? expanded_name : key->key, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT), - key->command); + if (default_key) + { + gui_chat_printf (NULL, " %s%s%s => %s%s %s(%s%s %s%s)", + str_spaces, + (expanded_name) ? expanded_name : key->key, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + key->command, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + _("default command:"), + default_key->command, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + } + else + { + gui_chat_printf (NULL, " %s%s%s => %s%s", + str_spaces, + (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); } +/* + * command_key_display_list: display a list of keys + */ + +void +command_key_display_list (const char *message_no_key, + const char *message_keys, + 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); + else + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, message_keys, keys_count); + for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key) + { + command_key_display (ptr_key, NULL); + } + } +} + +/* + * command_key_display_listdiff: list differences between default and current + * keys (keys added, redefined or removed) + */ + +void +command_key_display_listdiff () +{ + 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) + { + 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)) + { + count_added++; + } + } + 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); + if (!ptr_default_key + || (strcmp (ptr_default_key->command, ptr_key->command) != 0)) + { + command_key_display (ptr_key, ptr_default_key); + } + } + } + + /* list keys deleted */ + count_deleted = 0; + 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) + 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; + ptr_default_key = ptr_default_key->next_key) + { + ptr_key = gui_keyboard_search (gui_keys, ptr_default_key->key); + if (!ptr_key) + { + command_key_display (ptr_default_key, NULL); + } + } + } + + /* display a message if all key bindings are default bindings */ + if ((count_added == 0) && (count_deleted == 0)) + { + gui_chat_printf (NULL, + _("No key binding added, redefined or removed")); + } +} + /* * command_key: bind/unbind keys */ @@ -1941,28 +2055,37 @@ command_key (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *internal_code; - struct t_gui_key *ptr_key; + struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key; int old_keys_count, keys_added; /* make C compiler happy */ (void) data; (void) buffer; - /* display all key bindings */ - if (argc == 1) + /* display all key bindings (current keys) */ + if ((argc == 1) || (string_strcasecmp (argv[1], "list") == 0)) { - if (gui_keys_count == 0) - gui_chat_printf (NULL, _("No key binding defined")); - else - { - 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); - } - } + command_key_display_list (_("No key binding defined"), + _("Key bindings (%d):"), + gui_keys, + gui_keys_count); + return WEECHAT_RC_OK; + } + + /* display redefined or key bindings added */ + if (string_strcasecmp (argv[1], "listdiff") == 0) + { + command_key_display_listdiff (); + 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); return WEECHAT_RC_OK; } @@ -1971,15 +2094,15 @@ command_key (void *data, struct t_gui_buffer *buffer, { if (argc == 3) { - ptr_key = NULL; + ptr_new_key = NULL; internal_code = gui_keyboard_get_internal_code (argv[2]); if (internal_code) - ptr_key = gui_keyboard_search (NULL, internal_code); - if (ptr_key) + ptr_new_key = gui_keyboard_search (gui_keys, internal_code); + if (ptr_new_key) { gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Key:")); - command_key_display (ptr_key); + command_key_display (ptr_new_key, NULL); } else { @@ -2003,9 +2126,9 @@ command_key (void *data, struct t_gui_buffer *buffer, /* bind new key */ gui_keyboard_verbose = 1; - ptr_key = gui_keyboard_bind (NULL, argv[2], argv_eol[3]); + ptr_new_key = gui_keyboard_bind (NULL, argv[2], argv_eol[3]); gui_keyboard_verbose = 0; - if (!ptr_key) + if (!ptr_new_key) { gui_chat_printf (NULL, _("%sError: unable to bind key \"%s\""), @@ -2039,12 +2162,97 @@ command_key (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } - /* reset keys (only with "-yes", for security reason) */ + /* reset a key to default binding */ if (string_strcasecmp (argv[1], "reset") == 0) + { + if (argc >= 3) + { + 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_ERROR; + } + } + 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_ERROR; + } + } + 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_ERROR; + } + } + } + else + { + gui_chat_printf (NULL, _("%sKey \"%s\" not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + } + } + return WEECHAT_RC_OK; + } + + /* reset ALL keys (only with "-yes", for security reason) */ + if (string_strcasecmp (argv[1], "resetall") == 0) { if ((argc >= 3) && (string_strcasecmp (argv[2], "-yes") == 0)) { - gui_keyboard_free_all (&gui_keys, &last_gui_key); + gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count); gui_keyboard_default_bindings (); gui_chat_printf (NULL, _("Default key bindings restored")); @@ -4182,7 +4390,8 @@ command_init () " unmerge: unmerge buffer from other buffers which have " "same number\n" " close: close buffer (number/range is optional)\n" - " list: list buffers (no parameter implies this list)\n" + " list: list buffers (without argument, this list is " + "displayed)\n" " notify: set notify level for current buffer: this " "level determines whether buffer will be added to " "hotlist or not:\n" @@ -4359,20 +4568,39 @@ command_init () &command_input, NULL); hook_command (NULL, "key", N_("bind/unbind keys"), - N_("[bind key [command [args]]] | [unbind key] | " - "[reset -yes] | [missing]"), - N_(" bind: bind a command to a key or display command " + N_("[list | listdefault | listdiff] | [bind key [command " + "[args]]] | [unbind key] | [reset key] | " + "[resetall -yes] | [missing]"), + 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" + " bind: bind a command to a key or display command " "bound to key\n" - " unbind: remove a key binding\n" - " reset: restore bindings to the default values and " + " unbind: remove a key binding\n" + " reset: reset a key to default binding\n" + " resetall: restore bindings to the default values and " "delete ALL personal bindings (use carefully!)\n" - "missing: add missing keys (using default bindings)\n\n" + " missing: add missing keys (using default bindings), " + "useful after installing new WeeChat version\n\n" "When binding a command to a key, it is recommended to " "use key alt+k (or Esc then k), and then press the key " - "to bind: this will insert key code in command line."), - "bind %(keys_codes) %(commands)" + "to bind: this will insert key code in command line.\n\n" + "Examples:\n" + " key alt-x to toggle nicklist bar:\n" + " /key bind meta-x /bar toggle nicklist\n" + " 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" + " || bind %(keys_codes) %(commands)" " || unbind %(keys_codes)" - " || reset" + " || reset %(keys_codes_for_reset)" + " || resetall" " || missing", &command_key, NULL); hook_command (NULL, "layout", @@ -4569,8 +4797,8 @@ command_init () "scroll_up | scroll_down | scroll_top | scroll_bottom | " "scroll_previous_highlight | scroll_next_highlight | " "zoom]"), - N_(" list: list opened windows (no parameter implies " - "this list)\n" + N_(" list: list opened windows (without argument, " + "this list is displayed)\n" " -1: jump to previous window\n" " +1: jump to next window\n" " b#: jump to next window displaying buffer number #\n" diff --git a/src/core/wee-config.c b/src/core/wee-config.c index d88e7402f..1b43c62cf 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -407,7 +407,7 @@ config_weechat_reload_cb (void *data, struct t_config_file *config_file) (void) data; /* remove all keys */ - gui_keyboard_free_all (&gui_keys, &last_gui_key); + gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count); /* remove all proxies */ proxy_free_all (); diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index 38ee9a999..115fea832 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -58,7 +58,8 @@ gui_keyboard_default_bind (const char *key, const char *command) internal_code = gui_keyboard_get_internal_code (key); - ptr_key = gui_keyboard_search (NULL, (internal_code) ? internal_code : key); + ptr_key = gui_keyboard_search (gui_keys, + (internal_code) ? internal_code : key); if (!ptr_key) { gui_keyboard_new (NULL, key, command); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 9489cfe60..d630c4ae7 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -1514,6 +1514,6 @@ void gui_window_objects_print_log (struct t_gui_window *window) { log_printf (" window specific objects for Curses:"); - log_printf (" win_chat. . . . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_chat); - log_printf (" win_separator . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_separator); + log_printf (" win_chat. . . . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_chat); + log_printf (" win_separator . . : 0x%lx", GUI_WINDOW_OBJECTS(window)->win_separator); } diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c index e18b7b616..97eed1f37 100644 --- a/src/gui/gui-bar-window.c +++ b/src/gui/gui-bar-window.c @@ -1134,7 +1134,7 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window) log_printf (""); log_printf (" [window bar (addr:0x%lx)]", bar_window); - log_printf (" bar. . . . . . . . . : 0x%lx ('%s')", + log_printf (" bar. . . . . . . . . . : 0x%lx ('%s')", bar_window->bar, (bar_window->bar) ? bar_window->bar->name : ""); log_printf (" x. . . . . . . . . . . : %d", bar_window->x); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index b1a08fdef..1f6c93402 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -474,6 +474,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, /* keys */ new_buffer->keys = NULL; new_buffer->last_key = NULL; + new_buffer->keys_count = 0; /* local variables */ new_buffer->local_variables = NULL; @@ -1103,7 +1104,10 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, else if (string_strncasecmp (property, "key_unbind_", 11) == 0) { if (strcmp (property + 11, "*") == 0) - gui_keyboard_free_all (&buffer->keys, &buffer->last_key); + { + gui_keyboard_free_all (&buffer->keys, &buffer->last_key, + &buffer->keys_count); + } else gui_keyboard_unbind (buffer, property + 11, 1); } @@ -1642,7 +1646,8 @@ gui_buffer_close (struct t_gui_buffer *buffer) free (buffer->highlight_tags); if (buffer->highlight_tags_array) string_free_split (buffer->highlight_tags_array); - gui_keyboard_free_all (&buffer->keys, &buffer->last_key); + gui_keyboard_free_all (&buffer->keys, &buffer->last_key, + &buffer->keys_count); gui_buffer_local_var_remove_all (buffer); /* remove buffer from buffers list */ @@ -2382,6 +2387,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, return 0; i++; } + if (!infolist_new_var_integer (ptr_item, "keys_count", buffer->keys_count)) + return 0; i = 0; for (ptr_local_var = buffer->local_variables; ptr_local_var; ptr_local_var = ptr_local_var->next_var) @@ -2541,6 +2548,7 @@ gui_buffer_print_log () log_printf (" highlight_tags_array . : 0x%lx", ptr_buffer->highlight_tags_array); log_printf (" keys . . . . . . . . . : 0x%lx", ptr_buffer->keys); log_printf (" last_key . . . . . . . : 0x%lx", ptr_buffer->last_key); + log_printf (" keys_count . . . . . . : %d", ptr_buffer->keys_count); log_printf (" local_variables. . . . : 0x%lx", ptr_buffer->local_variables); log_printf (" last_local_var . . . . : 0x%lx", ptr_buffer->last_local_var); log_printf (" prev_buffer. . . . . . : 0x%lx", ptr_buffer->prev_buffer); @@ -2549,16 +2557,14 @@ gui_buffer_print_log () if (ptr_buffer->keys) { log_printf (""); - log_printf (" => keys = 0x%lx, last_key = 0x%lx:", - ptr_buffer->keys, ptr_buffer->last_key); + log_printf (" => keys:"); gui_keyboard_print_log (ptr_buffer); } if (ptr_buffer->local_variables) { log_printf (""); - log_printf (" => local_variables = 0x%lx, last_local_var = 0x%lx:", - ptr_buffer->local_variables, ptr_buffer->last_local_var); + log_printf (" => local_variables:"); for (ptr_local_var = ptr_buffer->local_variables; ptr_local_var; ptr_local_var = ptr_local_var->next_var) { @@ -2571,7 +2577,7 @@ gui_buffer_print_log () } log_printf (""); - log_printf (" => nicklist_root (addr:0x%lx):", ptr_buffer->nicklist_root); + log_printf (" => nicklist:"); gui_nicklist_print_log (ptr_buffer->nicklist_root, 0); log_printf (""); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 4d6afa482..8a422b21f 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -156,6 +156,7 @@ struct t_gui_buffer /* keys associated to buffer */ struct t_gui_key *keys; /* keys specific to buffer */ struct t_gui_key *last_key; /* last key for buffer */ + int keys_count; /* number of keys in buffer */ /* local variables */ struct t_gui_buffer_local_var *local_variables; /* local variables */ diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index dd23cd0f7..2e23ca727 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -1294,6 +1294,61 @@ gui_completion_list_add_keys_codes_cb (void *data, return WEECHAT_RC_OK; } +/* + * gui_completion_list_add_keys_codes_for_reset_cb: add keys that can be reset + * (keys added, redefined or + * removed) to completion list + */ + +int +gui_completion_list_add_keys_codes_for_reset_cb (void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_gui_key *ptr_key, *ptr_default_key; + char *expanded_name; + + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + /* keys added or redefined */ + 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); + if (!ptr_default_key + || (strcmp (ptr_default_key->command, ptr_key->command) != 0)) + { + 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); + } + } + + /* 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) + { + 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); + } + } + + return WEECHAT_RC_OK; +} + /* * gui_completion_custom: custom completion by a plugin */ @@ -2215,4 +2270,8 @@ gui_completion_init () hook_completion (NULL, "keys_codes", N_("key codes"), &gui_completion_list_add_keys_codes_cb, NULL); + hook_completion (NULL, "keys_codes_for_reset", + N_("key codes that can be reset (keys added, redefined " + "or removed)"), + &gui_completion_list_add_keys_codes_for_reset_cb, NULL); } diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index a6f12f4ee..44a44d78d 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -45,11 +45,15 @@ #include "gui-window.h" -struct t_gui_key *gui_keys = NULL; /* key bindings */ -struct t_gui_key *last_gui_key = NULL; /* last key binding */ -int gui_keys_count = 0; /* number of defined keys */ +struct t_gui_key *gui_keys = NULL; /* key bindings */ +struct t_gui_key *last_gui_key = NULL; /* last key binding */ +struct t_gui_key *gui_default_keys = NULL; /* default key bindings */ +struct t_gui_key *last_gui_default_key = NULL; /* last default key binding */ -int gui_keyboard_verbose = 0; /* 1 to see some messages */ +int gui_keys_count = 0; /* number of defined keys */ +int gui_default_keys_count = 0; /* number of default keys */ + +int gui_keyboard_verbose = 0; /* 1 to see some messages */ char gui_key_combo_buffer[128]; /* buffer used for combos */ int gui_key_grab = 0; /* 1 if grab mode enabled (alt-k) */ @@ -68,7 +72,7 @@ time_t gui_keyboard_last_activity_time = 0; /* last activity time (key) */ /* - * gui_keyboard_init: init keyboard (create default key bindings) + * gui_keyboard_init: init keyboard */ void @@ -78,6 +82,15 @@ gui_keyboard_init () gui_key_grab = 0; gui_key_grab_count = 0; gui_keyboard_last_activity_time = time (NULL); + + /* create default keys and save them in a separate list */ + gui_keyboard_default_bindings (); + gui_default_keys = gui_keys; + last_gui_default_key = last_gui_key; + gui_default_keys_count = gui_keys_count; + gui_keys = NULL; + last_gui_key = NULL; + gui_keys_count = 0; } /* @@ -112,7 +125,7 @@ gui_keyboard_grab_end () gui_input_insert_string (gui_current_window->buffer, expanded_key, -1); if (gui_key_grab_command) { - ptr_key = gui_keyboard_search (NULL, gui_key_combo_buffer); + ptr_key = gui_keyboard_search (gui_keys, gui_key_combo_buffer); if (ptr_key) { gui_input_insert_string (gui_current_window->buffer, " ", -1); @@ -243,7 +256,9 @@ gui_keyboard_find_pos (struct t_gui_key *keys, struct t_gui_key *key) */ void -gui_keyboard_insert_sorted (struct t_gui_key **keys, struct t_gui_key **last_key, +gui_keyboard_insert_sorted (struct t_gui_key **keys, + struct t_gui_key **last_key, + int *keys_count, struct t_gui_key *key) { struct t_gui_key *pos_key; @@ -281,7 +296,7 @@ gui_keyboard_insert_sorted (struct t_gui_key **keys, struct t_gui_key **last_key *last_key = key; } - gui_keys_count++; + (*keys_count)++; } /* @@ -315,9 +330,15 @@ gui_keyboard_new (struct t_gui_buffer *buffer, const char *key, } if (buffer) - gui_keyboard_insert_sorted (&buffer->keys, &buffer->last_key, new_key); + { + gui_keyboard_insert_sorted (&buffer->keys, &buffer->last_key, + &buffer->keys_count, new_key); + } else - gui_keyboard_insert_sorted (&gui_keys, &last_gui_key, new_key); + { + gui_keyboard_insert_sorted (&gui_keys, &last_gui_key, + &gui_keys_count, new_key); + } expanded_name = gui_keyboard_get_expanded_name (new_key->key); @@ -347,12 +368,11 @@ gui_keyboard_new (struct t_gui_buffer *buffer, const char *key, */ struct t_gui_key * -gui_keyboard_search (struct t_gui_buffer *buffer, const char *key) +gui_keyboard_search (struct t_gui_key *keys, const char *key) { struct t_gui_key *ptr_key; - - for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key; - ptr_key = ptr_key->next_key) + + for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key) { if (strcmp (ptr_key->key, key) == 0) return ptr_key; @@ -445,13 +465,20 @@ gui_keyboard_unbind (struct t_gui_buffer *buffer, const char *key, internal_code = gui_keyboard_get_internal_code (key); - ptr_key = gui_keyboard_search (buffer, (internal_code) ? internal_code : key); + ptr_key = gui_keyboard_search ((buffer) ? buffer->keys : gui_keys, + (internal_code) ? internal_code : key); if (ptr_key) { if (buffer) - gui_keyboard_free (&buffer->keys, &buffer->last_key, ptr_key); + { + gui_keyboard_free (&buffer->keys, &buffer->last_key, + &buffer->keys_count, ptr_key); + } else - gui_keyboard_free (&gui_keys, &last_gui_key, ptr_key); + { + gui_keyboard_free (&gui_keys, &last_gui_key, + &gui_keys_count, ptr_key); + } } if (internal_code) @@ -553,7 +580,7 @@ gui_keyboard_pressed (const char *key_str) void gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key, - struct t_gui_key *key) + int *keys_count, struct t_gui_key *key) { /* free memory */ if (key->key) @@ -573,7 +600,7 @@ gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key, free (key); - gui_keys_count--; + (*keys_count)--; } /* @@ -581,11 +608,12 @@ gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key, */ void -gui_keyboard_free_all (struct t_gui_key **keys, struct t_gui_key **last_key) +gui_keyboard_free_all (struct t_gui_key **keys, struct t_gui_key **last_key, + int *keys_count) { while (*keys) { - gui_keyboard_free (keys, last_key, *keys); + gui_keyboard_free (keys, last_key, keys_count, *keys); } } @@ -714,7 +742,11 @@ gui_keyboard_end () free (gui_keyboard_buffer); /* free all keys */ - gui_keyboard_free_all (&gui_keys, &last_gui_key); + gui_keyboard_free_all (&gui_keys, &last_gui_key, &gui_keys_count); + + /* free all default keys */ + gui_keyboard_free_all (&gui_default_keys, &last_gui_default_key, + &gui_default_keys_count); } /* @@ -758,19 +790,28 @@ gui_keyboard_add_to_infolist (struct t_infolist *infolist, void gui_keyboard_print_log (struct t_gui_buffer *buffer) { - struct t_gui_key *ptr_key; + struct t_gui_key *ptr_keys, *ptr_last_key, *ptr_key; + int keys_count; char prefix[32]; + ptr_keys = (buffer) ? buffer->keys : gui_keys; + ptr_last_key = (buffer) ? buffer->last_key : last_gui_key; + keys_count = (buffer) ? buffer->keys_count : gui_keys_count; + snprintf (prefix, sizeof (prefix), "%s", (buffer) ? " " : ""); + log_printf ("%skeys . . . . . . . . : 0x%lx", prefix, ptr_keys); + log_printf ("%slast_key . . . . . . : 0x%lx", prefix, ptr_last_key); + log_printf ("%skeys_count . . . . . : %d", prefix, keys_count); + for (ptr_key = (buffer) ? buffer->keys : gui_keys; ptr_key; ptr_key = ptr_key->next_key) { log_printf (""); log_printf ("%s[key (addr:0x%lx)]", prefix, ptr_key); - log_printf ("%skey. . . . . . . . . : '%s'", prefix, ptr_key->key); - log_printf ("%scommand. . . . . . . : '%s'", prefix, ptr_key->command); - log_printf ("%sprev_key . . . . . . : 0x%lx", prefix, ptr_key->prev_key); - log_printf ("%snext_key . . . . . . : 0x%lx", prefix, ptr_key->next_key); + log_printf ("%s key. . . . . . . . : '%s'", prefix, ptr_key->key); + log_printf ("%s command. . . . . . : '%s'", prefix, ptr_key->command); + log_printf ("%s prev_key . . . . . : 0x%lx", prefix, ptr_key->prev_key); + log_printf ("%s next_key . . . . . : 0x%lx", prefix, ptr_key->next_key); } } diff --git a/src/gui/gui-keyboard.h b/src/gui/gui-keyboard.h index 7090d0e42..da8b857bd 100644 --- a/src/gui/gui-keyboard.h +++ b/src/gui/gui-keyboard.h @@ -36,7 +36,10 @@ struct t_gui_key extern struct t_gui_key *gui_keys; extern struct t_gui_key *last_gui_key; +extern struct t_gui_key *gui_default_keys; +extern struct t_gui_key *last_gui_default_key; extern int gui_keys_count; +extern int gui_default_keys_count; extern int gui_keyboard_verbose; extern char gui_key_combo_buffer[]; extern int gui_key_grab; @@ -56,7 +59,7 @@ extern char *gui_keyboard_get_expanded_name (const char *key); extern struct t_gui_key *gui_keyboard_new (struct t_gui_buffer *buffer, const char *key, const char *command); -extern struct t_gui_key *gui_keyboard_search (struct t_gui_buffer *buffer, +extern struct t_gui_key *gui_keyboard_search (struct t_gui_key *keys, const char *key); extern struct t_gui_key *gui_keyboard_bind (struct t_gui_buffer *buffer, const char *key, @@ -66,9 +69,11 @@ extern int gui_keyboard_unbind (struct t_gui_buffer *buffer, const char *key, extern int gui_keyboard_pressed (const char *key_str); extern void gui_keyboard_free (struct t_gui_key **keys, struct t_gui_key **last_key, + int *keys_count, struct t_gui_key *key); extern void gui_keyboard_free_all (struct t_gui_key **keys, - struct t_gui_key **last_key); + struct t_gui_key **last_key, + int *keys_count); extern void gui_keyboard_buffer_reset (); extern void gui_keyboard_buffer_add (unsigned char key); extern int gui_keyboard_get_paste_lines (); diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index d611bada4..76645b00e 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -4575,8 +4575,8 @@ irc_command_init () "[rename servername newservername] | " "[keep servername] | [del servername] | " "[deloutq] | [jump] | [raw]"), - N_(" list: list servers (no parameter implies " - "this list)\n" + N_(" list: list servers (without argument, " + "this list is displayed)\n" " listfull: list servers with detailed info for " "each server\n" " add: create a new server\n" -- cgit v1.2.3