diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-03-24 19:54:31 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-03-24 19:54:31 +0100 |
commit | 96e6ae3fc31470db029ed99e3b55693f60a11067 (patch) | |
tree | 60b32a0808e0a5f9d325a9f56ef069d1bdf27e9b /src/gui | |
parent | b932f403a55672c2f9f7a3188fa6d0d829faa356 (diff) | |
download | weechat-96e6ae3fc31470db029ed99e3b55693f60a11067.zip |
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".
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 4 | ||||
-rw-r--r-- | src/gui/gui-bar-window.c | 2 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 20 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 1 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 59 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 95 | ||||
-rw-r--r-- | src/gui/gui-keyboard.h | 9 |
8 files changed, 153 insertions, 40 deletions
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 @@ -1295,6 +1295,61 @@ gui_completion_list_add_keys_codes_cb (void *data, } /* + * 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 (); |