diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 4 | ||||
-rw-r--r-- | src/gui/gui-bar-item.c | 4 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 2 | ||||
-rw-r--r-- | src/gui/gui-input.c | 146 | ||||
-rw-r--r-- | src/gui/gui-input.h | 2 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 2 | ||||
-rw-r--r-- | src/gui/gui-window.c | 2 | ||||
-rw-r--r-- | src/plugins/aspell/weechat-aspell.c | 2 |
8 files changed, 95 insertions, 69 deletions
diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index 04bd9df8f..269926f41 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -304,7 +304,7 @@ gui_keyboard_flush () key_str, -1); if (gui_current_window->buffer->completion) gui_completion_stop (gui_current_window->buffer->completion, 0); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } /* incremental text search in buffer */ @@ -397,7 +397,7 @@ gui_keyboard_read_cb (void *data, int fd) else if (cancel_paste) gui_keyboard_paste_cancel (); else if (text_added_to_buffer) - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } else { diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 150c7af43..5a1019897 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -665,7 +665,7 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item, /* execute modifier with basic string (without cursor tag) */ ptr_input = hook_modifier_exec (NULL, - "weechat_input_text_display", + "input_text_display", str_buffer, (window->buffer->input_buffer) ? window->buffer->input_buffer : ""); @@ -712,7 +712,7 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item, /* execute modifier with cursor in string */ ptr_input2 = hook_modifier_exec (NULL, - "weechat_input_text_display_with_cursor", + "input_text_display_with_cursor", str_buffer, (ptr_input) ? ptr_input : ""); if (ptr_input) diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 27c363442..142d99abb 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -944,7 +944,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, { gui_input_delete_line (buffer); gui_input_insert_string (buffer, value, 0); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (buffer); } else if (string_strcasecmp (property, "input_get_unknown_commands") == 0) { diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 3284a2c82..e423caea4 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -47,6 +47,54 @@ char *gui_input_clipboard = NULL; /* clipboard content */ /* + * gui_input_optimize_size: optimize input buffer size by adding + * or deleting data block (predefined size) + */ + +void +gui_input_optimize_size (struct t_gui_buffer *buffer) +{ + int optimal_size; + + if (buffer->input) + { + optimal_size = ((buffer->input_buffer_size / GUI_BUFFER_INPUT_BLOCK_SIZE) * + GUI_BUFFER_INPUT_BLOCK_SIZE) + GUI_BUFFER_INPUT_BLOCK_SIZE; + if (buffer->input_buffer_alloc != optimal_size) + { + buffer->input_buffer_alloc = optimal_size; + buffer->input_buffer = realloc (buffer->input_buffer, optimal_size); + } + } +} + +/* + * gui_input_replace_input: replace full input by another string, trying to + * keep cursor position is new string is long enough + */ + +void +gui_input_replace_input (struct t_gui_buffer *buffer, const char *new_input) +{ + int size, length; + + size = strlen (new_input); + length = utf8_strlen (new_input); + + /* compute new buffer size */ + buffer->input_buffer_size = size; + buffer->input_buffer_length = length; + gui_input_optimize_size (buffer); + + /* copy new string to input */ + strcpy (buffer->input_buffer, new_input); + + /* move cursor to the end of new input if it is now after the end */ + if (buffer->input_buffer_pos > buffer->input_buffer_length) + buffer->input_buffer_pos = buffer->input_buffer_length; +} + +/* * gui_input_paste_pending_signal: send signal "input_paste_pending" */ @@ -67,12 +115,30 @@ gui_input_prompt_changed_signal () } /* - * gui_input_text_changed_signal: send signal "input_text_changed" + * gui_input_text_changed_modifier_and_signal: send modifier and signal + * "input_text_changed" */ void -gui_input_text_changed_signal () +gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer) { + char str_buffer[128], *new_input; + + /* send modifier, and change input if needed */ + snprintf (str_buffer, sizeof (str_buffer), + "0x%lx", (long unsigned int)buffer); + new_input = hook_modifier_exec (NULL, + "input_text_content", + str_buffer, + (buffer->input_buffer) ? + buffer->input_buffer : ""); + if (new_input && (strcmp (new_input, buffer->input_buffer) != 0)) + { + /* input has been changed by modifier, use it */ + gui_input_replace_input (buffer, new_input); + } + + /* send signal */ hook_signal_send ("input_text_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); } @@ -97,28 +163,6 @@ gui_input_search_signal () } /* - * gui_input_optimize_size: optimize input buffer size by adding - * or deleting data block (predefined size) - */ - -void -gui_input_optimize_size (struct t_gui_buffer *buffer) -{ - int optimal_size; - - if (buffer->input) - { - optimal_size = ((buffer->input_buffer_size / GUI_BUFFER_INPUT_BLOCK_SIZE) * - GUI_BUFFER_INPUT_BLOCK_SIZE) + GUI_BUFFER_INPUT_BLOCK_SIZE; - if (buffer->input_buffer_alloc != optimal_size) - { - buffer->input_buffer_alloc = optimal_size; - buffer->input_buffer = realloc (buffer->input_buffer, optimal_size); - } - } -} - -/* * gui_input_move: move data in input buffer */ @@ -147,14 +191,9 @@ gui_input_insert_string (struct t_gui_buffer *buffer, const char *string, { int pos_start, size, length; char *ptr_start; - char *buffer_before_insert, *string2; if (buffer->input) { - buffer_before_insert = - (buffer->input_buffer) ? - strdup (buffer->input_buffer) : strdup (""); - if (pos == -1) pos = buffer->input_buffer_pos; @@ -179,19 +218,6 @@ gui_input_insert_string (struct t_gui_buffer *buffer, const char *string, buffer->input_buffer_pos += length; - string2 = malloc (size + 2); - if (string2) - { - snprintf (string2, size + 2, "*%s", string); - /* TODO: execute keyboard hooks */ - /*(void) plugin_keyboard_handler_exec (string2, - buffer_before_insert, - buffer->input_buffer);*/ - free (string2); - } - if (buffer_before_insert) - free (buffer_before_insert); - return length; } return 0; @@ -233,7 +259,7 @@ gui_input_clipboard_paste () gui_input_clipboard, -1); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -270,7 +296,7 @@ gui_input_return () gui_completion_stop (gui_current_window->buffer->completion, 1); gui_current_window->buffer->ptr_history = NULL; gui_input_optimize_size (gui_current_window->buffer); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); input_data (gui_current_window->buffer, command); free (command); } @@ -379,7 +405,7 @@ gui_input_complete (struct t_gui_buffer *buffer) buffer->completion->position++; } } - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (buffer); } } @@ -400,7 +426,7 @@ gui_input_complete_next () utf8_real_pos (gui_current_window->buffer->input_buffer, gui_current_window->buffer->input_buffer_pos)); gui_input_complete (gui_current_window->buffer); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -421,7 +447,7 @@ gui_input_complete_previous () utf8_real_pos (gui_current_window->buffer->input_buffer, gui_current_window->buffer->input_buffer_pos)); gui_input_complete (gui_current_window->buffer); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -473,7 +499,7 @@ gui_input_delete_previous_char () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -504,7 +530,7 @@ gui_input_delete_next_char () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -563,7 +589,7 @@ gui_input_delete_previous_word () gui_current_window->buffer->input_buffer_pos -= length_deleted; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -602,7 +628,7 @@ gui_input_delete_next_word () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -638,7 +664,7 @@ gui_input_delete_beginning_of_line () gui_current_window->buffer->input_buffer_pos = 0; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -670,7 +696,7 @@ gui_input_delete_end_of_line (const char *args) gui_current_window->buffer->input_buffer_length = utf8_strlen (gui_current_window->buffer->input_buffer); gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -689,7 +715,7 @@ gui_input_delete_line () gui_current_window->buffer->input_buffer_pos = 0; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } @@ -730,7 +756,7 @@ gui_input_transpose_chars () gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -951,7 +977,7 @@ gui_input_history_previous () strcpy (gui_current_window->buffer->input_buffer, gui_current_window->buffer->ptr_history->text); } - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } else { @@ -1016,7 +1042,7 @@ gui_input_history_next () gui_input_optimize_size (gui_current_window->buffer); } } - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } else { @@ -1058,7 +1084,7 @@ gui_input_history_global_previous () gui_current_window->buffer->input_buffer_1st_display = 0; strcpy (gui_current_window->buffer->input_buffer, history_global_ptr->text); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -1098,7 +1124,7 @@ gui_input_history_global_next () strcpy (gui_current_window->buffer->input_buffer, history_global_ptr->text); } - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } } } @@ -1261,7 +1287,7 @@ gui_input_insert (const char *args) { args2 = string_convert_hex_chars (args); gui_input_insert_string (gui_current_window->buffer, (args2) ? args2 : args, -1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); if (args2) free (args2); } diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index 554d075c5..5edceddd7 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -29,7 +29,7 @@ extern char *gui_input_clipboard; /* input functions */ extern void gui_input_paste_pending_signal (); -extern void gui_input_text_changed_signal (); +extern void gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer); extern void gui_input_move (struct t_gui_buffer *buffer, char *target, const char *source, int size); extern int gui_input_insert_string (struct t_gui_buffer *buffer, diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 77cfb4b48..f14aa14ae 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -115,7 +115,7 @@ gui_keyboard_grab_end () gui_input_insert_string (gui_current_window->buffer, expanded_key, -1); if (gui_current_window->buffer->completion) gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } free (expanded_key); } diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 321ccbd78..4b22f8520 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -906,7 +906,7 @@ gui_window_search_stop (struct t_gui_window *window) { gui_input_insert_string (window->buffer, window->buffer->text_search_input, -1); - gui_input_text_changed_signal (); + gui_input_text_changed_modifier_and_signal (window->buffer); free (window->buffer->text_search_input); window->buffer->text_search_input = NULL; } diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 3c582002d..dc6f1a2f9 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -975,7 +975,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) &weechat_aspell_buffer_switch_cb, NULL); /* callback for spell checking input text */ - weechat_hook_modifier ("weechat_input_text_display", + weechat_hook_modifier ("input_text_display", &weechat_aspell_modifier_cb, NULL); weechat_aspell_create_spellers (weechat_current_buffer ()); |