diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 86 | ||||
-rw-r--r-- | src/gui/gui-input.c | 664 | ||||
-rw-r--r-- | src/gui/gui-input.h | 75 | ||||
-rw-r--r-- | src/gui/gui-window.c | 36 | ||||
-rw-r--r-- | src/gui/gui-window.h | 1 | ||||
-rw-r--r-- | src/plugins/plugin.c | 1 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 37 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 31 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 34 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 36 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 37 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 5 |
12 files changed, 647 insertions, 396 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index e350ddd25..e11dd9a49 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -740,8 +740,7 @@ COMMAND_CALLBACK(buffer) if (string_strcasecmp (argv[1], "notify") == 0) { COMMAND_MIN_ARGS(3, "buffer notify"); - config_weechat_notify_set (gui_current_window->buffer, - argv_eol[2]); + config_weechat_notify_set (buffer, argv_eol[2]); return WEECHAT_RC_OK; } @@ -860,15 +859,15 @@ COMMAND_CALLBACK(buffer) if (error && !error[0]) { /* buffer is currently displayed ? then jump to previous buffer */ - if ((number == gui_current_window->buffer->number) + if ((number == buffer->number) && (CONFIG_BOOLEAN(config_look_jump_current_to_previous_buffer)) && gui_buffers_visited) { - gui_input_jump_previously_visited_buffer (gui_current_window); + gui_input_jump_previously_visited_buffer (buffer); } else { - if (number != gui_current_window->buffer->number) + if (number != buffer->number) { gui_buffer_switch_by_number (gui_current_window, (int) number); @@ -883,8 +882,10 @@ COMMAND_CALLBACK(buffer) error = NULL; number = strtol (argv[1], &error, 10); if (error && !error[0]) + { gui_buffer_switch_by_number (gui_current_window, (int) number); + } else { ptr_buffer = NULL; @@ -2078,89 +2079,88 @@ COMMAND_CALLBACK(input) { /* make C compiler happy */ (void) data; - (void) buffer; if (argc > 1) { if (string_strcasecmp (argv[1], "clipboard_paste") == 0) - gui_input_clipboard_paste (gui_current_window); + gui_input_clipboard_paste (buffer); else if (string_strcasecmp (argv[1], "return") == 0) - gui_input_return (gui_current_window); + gui_input_return (buffer); else if (string_strcasecmp (argv[1], "complete_next") == 0) - gui_input_complete_next (gui_current_window); + gui_input_complete_next (buffer); else if (string_strcasecmp (argv[1], "complete_previous") == 0) - gui_input_complete_previous (gui_current_window); + gui_input_complete_previous (buffer); else if (string_strcasecmp (argv[1], "search_text") == 0) - gui_input_search_text (gui_current_window); + gui_input_search_text (buffer); else if (string_strcasecmp (argv[1], "delete_previous_char") == 0) - gui_input_delete_previous_char (gui_current_window); + gui_input_delete_previous_char (buffer); else if (string_strcasecmp (argv[1], "delete_next_char") == 0) - gui_input_delete_next_char (gui_current_window); + gui_input_delete_next_char (buffer); else if (string_strcasecmp (argv[1], "delete_previous_word") == 0) - gui_input_delete_previous_word (gui_current_window); + gui_input_delete_previous_word (buffer); else if (string_strcasecmp (argv[1], "delete_next_word") == 0) - gui_input_delete_next_word (gui_current_window); + gui_input_delete_next_word (buffer); else if (string_strcasecmp (argv[1], "delete_beginning_of_line") == 0) - gui_input_delete_beginning_of_line (gui_current_window); + gui_input_delete_beginning_of_line (buffer); else if (string_strcasecmp (argv[1], "delete_end_of_line") == 0) - gui_input_delete_end_of_line (gui_current_window); + gui_input_delete_end_of_line (buffer); else if (string_strcasecmp (argv[1], "delete_line") == 0) - gui_input_delete_line (gui_current_window); + gui_input_delete_line (buffer); else if (string_strcasecmp (argv[1], "transpose_chars") == 0) - gui_input_transpose_chars (gui_current_window); + gui_input_transpose_chars (buffer); else if (string_strcasecmp (argv[1], "move_beginning_of_line") == 0) - gui_input_move_beginning_of_line (gui_current_window); + gui_input_move_beginning_of_line (buffer); else if (string_strcasecmp (argv[1], "move_end_of_line") == 0) - gui_input_move_end_of_line (gui_current_window); + gui_input_move_end_of_line (buffer); else if (string_strcasecmp (argv[1], "move_previous_char") == 0) - gui_input_move_previous_char (gui_current_window); + gui_input_move_previous_char (buffer); else if (string_strcasecmp (argv[1], "move_next_char") == 0) - gui_input_move_next_char (gui_current_window); + gui_input_move_next_char (buffer); else if (string_strcasecmp (argv[1], "move_previous_word") == 0) - gui_input_move_previous_word (gui_current_window); + gui_input_move_previous_word (buffer); else if (string_strcasecmp (argv[1], "move_next_word") == 0) - gui_input_move_next_word (gui_current_window); + gui_input_move_next_word (buffer); else if (string_strcasecmp (argv[1], "history_previous") == 0) - gui_input_history_local_previous (gui_current_window); + gui_input_history_local_previous (buffer); else if (string_strcasecmp (argv[1], "history_next") == 0) - gui_input_history_local_next (gui_current_window); + gui_input_history_local_next (buffer); else if (string_strcasecmp (argv[1], "history_global_previous") == 0) - gui_input_history_global_previous (gui_current_window); + gui_input_history_global_previous (buffer); else if (string_strcasecmp (argv[1], "history_global_next") == 0) - gui_input_history_global_next (gui_current_window); + gui_input_history_global_next (buffer); else if (string_strcasecmp (argv[1], "jump_smart") == 0) - gui_input_jump_smart (gui_current_window); + gui_input_jump_smart (buffer); else if (string_strcasecmp (argv[1], "jump_last_buffer") == 0) - gui_input_jump_last_buffer (gui_current_window); + gui_input_jump_last_buffer (buffer); else if (string_strcasecmp (argv[1], "jump_previously_visited_buffer") == 0) - gui_input_jump_previously_visited_buffer (gui_current_window); + gui_input_jump_previously_visited_buffer (buffer); else if (string_strcasecmp (argv[1], "jump_next_visited_buffer") == 0) - gui_input_jump_next_visited_buffer (gui_current_window); + gui_input_jump_next_visited_buffer (buffer); else if (string_strcasecmp (argv[1], "hotlist_clear") == 0) - gui_input_hotlist_clear (gui_current_window); + gui_input_hotlist_clear (buffer); else if (string_strcasecmp (argv[1], "grab_key") == 0) - gui_input_grab_key (gui_current_window); + gui_input_grab_key (buffer); else if (string_strcasecmp (argv[1], "grab_key_command") == 0) - gui_input_grab_key_command (gui_current_window); + gui_input_grab_key_command (buffer); else if (string_strcasecmp (argv[1], "scroll_unread") == 0) - gui_input_scroll_unread (gui_current_window); + gui_input_scroll_unread (buffer); else if (string_strcasecmp (argv[1], "set_unread") == 0) gui_input_set_unread (); else if (string_strcasecmp (argv[1], "set_unread_current_buffer") == 0) - gui_input_set_unread_current (gui_current_window); + gui_input_set_unread_current (buffer); else if (string_strcasecmp (argv[1], "switch_active_buffer") == 0) - gui_input_switch_active_buffer (gui_current_window); + gui_input_switch_active_buffer (buffer); else if (string_strcasecmp (argv[1], "switch_active_buffer_previous") == 0) - gui_input_switch_active_buffer_previous (gui_current_window); + gui_input_switch_active_buffer_previous (buffer); else if (string_strcasecmp (argv[1], "insert") == 0) { if (argc > 2) - gui_input_insert (gui_current_window, argv_eol[2]); + gui_input_insert (buffer, argv_eol[2]); } else if (string_strcasecmp (argv[1], "undo") == 0) - gui_input_undo (gui_current_window); + gui_input_undo (buffer); else if (string_strcasecmp (argv[1], "redo") == 0) - gui_input_redo (gui_current_window); + gui_input_redo (buffer); } return WEECHAT_RC_OK; diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 8662a8218..2a3326468 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -317,16 +317,16 @@ gui_input_clipboard_copy (const char *buffer, int size) */ void -gui_input_clipboard_paste (struct t_gui_window *window) +gui_input_clipboard_paste (struct t_gui_buffer *buffer) { - if (window->buffer->input && gui_input_clipboard) + if (buffer->input && gui_input_clipboard) { - gui_buffer_undo_snap (window->buffer); - gui_input_insert_string (window->buffer, + gui_buffer_undo_snap (buffer); + gui_input_insert_string (buffer, gui_input_clipboard, -1); - gui_completion_stop (window->buffer->completion, 1); + gui_completion_stop (buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -335,11 +335,13 @@ gui_input_clipboard_paste (struct t_gui_window *window) */ void -gui_input_return (struct t_gui_window *window) +gui_input_return (struct t_gui_buffer *buffer) { + struct t_gui_window *window; char *command; - if (window->buffer->input) + window = gui_window_search_with_buffer (buffer); + if (window && window->buffer->input) { if (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED) { @@ -377,76 +379,76 @@ gui_input_return (struct t_gui_window *window) */ void -gui_input_complete (struct t_gui_window *window) +gui_input_complete (struct t_gui_buffer *buffer) { int i; - if (!window->buffer->completion) + if (!buffer->completion) return; - if (window->buffer->completion->word_found) + if (buffer->completion->word_found) { /* replace word with new completed word into input buffer */ - if (window->buffer->completion->diff_size > 0) + if (buffer->completion->diff_size > 0) { - window->buffer->input_buffer_size += - window->buffer->completion->diff_size; - window->buffer->input_buffer_length += - window->buffer->completion->diff_length; - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - for (i = window->buffer->input_buffer_size - 1; - i >= window->buffer->completion->position_replace + - (int)strlen (window->buffer->completion->word_found); i--) + buffer->input_buffer_size += + buffer->completion->diff_size; + buffer->input_buffer_length += + buffer->completion->diff_length; + gui_input_optimize_size (buffer); + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + for (i = buffer->input_buffer_size - 1; + i >= buffer->completion->position_replace + + (int)strlen (buffer->completion->word_found); i--) { - window->buffer->input_buffer[i] = - window->buffer->input_buffer[i - window->buffer->completion->diff_size]; + buffer->input_buffer[i] = + buffer->input_buffer[i - buffer->completion->diff_size]; } } else { - for (i = window->buffer->completion->position_replace + - strlen (window->buffer->completion->word_found); - i < window->buffer->input_buffer_size; i++) + for (i = buffer->completion->position_replace + + strlen (buffer->completion->word_found); + i < buffer->input_buffer_size; i++) { - window->buffer->input_buffer[i] = - window->buffer->input_buffer[i - window->buffer->completion->diff_size]; + buffer->input_buffer[i] = + buffer->input_buffer[i - buffer->completion->diff_size]; } - window->buffer->input_buffer_size += window->buffer->completion->diff_size; - window->buffer->input_buffer_length += window->buffer->completion->diff_length; - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + buffer->input_buffer_size += buffer->completion->diff_size; + buffer->input_buffer_length += buffer->completion->diff_length; + gui_input_optimize_size (buffer); + buffer->input_buffer[buffer->input_buffer_size] = '\0'; } - - strncpy (window->buffer->input_buffer + window->buffer->completion->position_replace, - window->buffer->completion->word_found, - strlen (window->buffer->completion->word_found)); - window->buffer->input_buffer_pos = - utf8_pos (window->buffer->input_buffer, - window->buffer->completion->position_replace) + - utf8_strlen (window->buffer->completion->word_found); + + strncpy (buffer->input_buffer + buffer->completion->position_replace, + buffer->completion->word_found, + strlen (buffer->completion->word_found)); + buffer->input_buffer_pos = + utf8_pos (buffer->input_buffer, + buffer->completion->position_replace) + + utf8_strlen (buffer->completion->word_found); /* * position is < 0 this means only one word was found to complete, * so reinit to stop completion */ - if (window->buffer->completion->position >= 0) - window->buffer->completion->position = utf8_real_pos (window->buffer->input_buffer, - window->buffer->input_buffer_pos); + if (buffer->completion->position >= 0) + buffer->completion->position = utf8_real_pos (buffer->input_buffer, + buffer->input_buffer_pos); /* add space if needed after completion */ - if (window->buffer->completion->add_space) + if (buffer->completion->add_space) { - if (window->buffer->input_buffer[utf8_real_pos (window->buffer->input_buffer, - window->buffer->input_buffer_pos)] != ' ') + if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer, + buffer->input_buffer_pos)] != ' ') { - gui_input_insert_string (window->buffer, " ", - window->buffer->input_buffer_pos); + gui_input_insert_string (buffer, " ", + buffer->input_buffer_pos); } else - window->buffer->input_buffer_pos++; - if (window->buffer->completion->position >= 0) - window->buffer->completion->position++; + buffer->input_buffer_pos++; + if (buffer->completion->position >= 0) + buffer->completion->position++; } } } @@ -456,20 +458,20 @@ gui_input_complete (struct t_gui_window *window) */ void -gui_input_complete_next (struct t_gui_window *window) +gui_input_complete_next (struct t_gui_buffer *buffer) { - if (window->buffer->input - && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) + if (buffer->input + && (buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { - gui_buffer_undo_snap (window->buffer); - gui_completion_search (window->buffer->completion, + gui_buffer_undo_snap (buffer); + gui_completion_search (buffer->completion, 1, - window->buffer->input_buffer, - window->buffer->input_buffer_size, - utf8_real_pos (window->buffer->input_buffer, - window->buffer->input_buffer_pos)); - gui_input_complete (window); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer, + buffer->input_buffer_size, + utf8_real_pos (buffer->input_buffer, + buffer->input_buffer_pos)); + gui_input_complete (buffer); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -478,20 +480,20 @@ gui_input_complete_next (struct t_gui_window *window) */ void -gui_input_complete_previous (struct t_gui_window *window) +gui_input_complete_previous (struct t_gui_buffer *buffer) { - if (window->buffer->input - && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) + if (buffer->input + && (buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { - gui_buffer_undo_snap (window->buffer); - gui_completion_search (window->buffer->completion, + gui_buffer_undo_snap (buffer); + gui_completion_search (buffer->completion, -1, - window->buffer->input_buffer, - window->buffer->input_buffer_size, - utf8_real_pos (window->buffer->input_buffer, - window->buffer->input_buffer_pos)); - gui_input_complete (window); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer, + buffer->input_buffer_size, + utf8_real_pos (buffer->input_buffer, + buffer->input_buffer_pos)); + gui_input_complete (buffer); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -500,9 +502,12 @@ gui_input_complete_previous (struct t_gui_window *window) */ void -gui_input_search_text (struct t_gui_window *window) +gui_input_search_text (struct t_gui_buffer *buffer) { - if (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window && (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED)) { /* toggle search */ if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) @@ -521,27 +526,27 @@ gui_input_search_text (struct t_gui_window *window) */ void -gui_input_delete_previous_char (struct t_gui_window *window) +gui_input_delete_previous_char (struct t_gui_buffer *buffer) { char *pos, *pos_last; int char_size, size_to_move; - if (window->buffer->input && (window->buffer->input_buffer_pos > 0)) + if (buffer->input && (buffer->input_buffer_pos > 0)) { - gui_buffer_undo_snap (window->buffer); - pos = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); - pos_last = utf8_prev_char (window->buffer->input_buffer, pos); + gui_buffer_undo_snap (buffer); + pos = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); + pos_last = utf8_prev_char (buffer->input_buffer, pos); char_size = pos - pos_last; size_to_move = strlen (pos); memmove (pos_last, pos, size_to_move); - window->buffer->input_buffer_size -= char_size; - window->buffer->input_buffer_length--; - window->buffer->input_buffer_pos--; - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size -= char_size; + buffer->input_buffer_length--; + buffer->input_buffer_pos--; + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -550,27 +555,27 @@ gui_input_delete_previous_char (struct t_gui_window *window) */ void -gui_input_delete_next_char (struct t_gui_window *window) +gui_input_delete_next_char (struct t_gui_buffer *buffer) { char *pos, *pos_next; int char_size, size_to_move; - if (window->buffer->input - && (window->buffer->input_buffer_pos < window->buffer->input_buffer_length)) + if (buffer->input + && (buffer->input_buffer_pos < buffer->input_buffer_length)) { - gui_buffer_undo_snap (window->buffer); - pos = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); + gui_buffer_undo_snap (buffer); + pos = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); pos_next = utf8_next_char (pos); char_size = pos_next - pos; size_to_move = strlen (pos_next); memmove (pos, pos_next, size_to_move); - window->buffer->input_buffer_size -= char_size; - window->buffer->input_buffer_length--; - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size -= char_size; + buffer->input_buffer_length--; + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -579,32 +584,32 @@ gui_input_delete_next_char (struct t_gui_window *window) */ void -gui_input_delete_previous_word (struct t_gui_window *window) +gui_input_delete_previous_word (struct t_gui_buffer *buffer) { int length_deleted, size_deleted; char *start, *string; - if (window->buffer->input && (window->buffer->input_buffer_pos > 0)) + if (buffer->input && (buffer->input_buffer_pos > 0)) { - gui_buffer_undo_snap (window->buffer); - start = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos - 1); + gui_buffer_undo_snap (buffer); + start = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos - 1); string = start; while (string && (string[0] == ' ')) { - string = utf8_prev_char (window->buffer->input_buffer, string); + string = utf8_prev_char (buffer->input_buffer, string); } if (string) { while (string && (string[0] != ' ')) { - string = utf8_prev_char (window->buffer->input_buffer, string); + string = utf8_prev_char (buffer->input_buffer, string); } if (string) { while (string && (string[0] == ' ')) { - string = utf8_prev_char (window->buffer->input_buffer, string); + string = utf8_prev_char (buffer->input_buffer, string); } } } @@ -612,7 +617,7 @@ gui_input_delete_previous_word (struct t_gui_window *window) if (string) string = utf8_next_char (utf8_next_char (string)); else - string = window->buffer->input_buffer; + string = buffer->input_buffer; size_deleted = utf8_next_char (start) - string; length_deleted = utf8_strnlen (string, size_deleted); @@ -621,13 +626,13 @@ gui_input_delete_previous_word (struct t_gui_window *window) memmove (string, string + size_deleted, strlen (string + size_deleted)); - window->buffer->input_buffer_size -= size_deleted; - window->buffer->input_buffer_length -= length_deleted; - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - window->buffer->input_buffer_pos -= length_deleted; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size -= size_deleted; + buffer->input_buffer_length -= length_deleted; + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + buffer->input_buffer_pos -= length_deleted; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -636,16 +641,16 @@ gui_input_delete_previous_word (struct t_gui_window *window) */ void -gui_input_delete_next_word (struct t_gui_window *window) +gui_input_delete_next_word (struct t_gui_buffer *buffer) { int size_deleted, length_deleted; char *start, *string; - if (window->buffer->input) + if (buffer->input) { - gui_buffer_undo_snap (window->buffer); - start = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); + gui_buffer_undo_snap (buffer); + start = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); string = start; length_deleted = 0; while (string[0]) @@ -661,12 +666,12 @@ gui_input_delete_next_word (struct t_gui_window *window) memmove (start, string, strlen (string)); - window->buffer->input_buffer_size -= size_deleted; - window->buffer->input_buffer_length -= length_deleted; - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size -= size_deleted; + buffer->input_buffer_length -= length_deleted; + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -677,30 +682,30 @@ gui_input_delete_next_word (struct t_gui_window *window) */ void -gui_input_delete_beginning_of_line (struct t_gui_window *window) +gui_input_delete_beginning_of_line (struct t_gui_buffer *buffer) { int length_deleted, size_deleted; char *start; - if (window->buffer->input && (window->buffer->input_buffer_pos > 0)) + if (buffer->input && (buffer->input_buffer_pos > 0)) { - gui_buffer_undo_snap (window->buffer); - start = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); - size_deleted = start - window->buffer->input_buffer; - length_deleted = utf8_strnlen (window->buffer->input_buffer, size_deleted); - gui_input_clipboard_copy (window->buffer->input_buffer, - start - window->buffer->input_buffer); + gui_buffer_undo_snap (buffer); + start = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); + size_deleted = start - buffer->input_buffer; + length_deleted = utf8_strnlen (buffer->input_buffer, size_deleted); + gui_input_clipboard_copy (buffer->input_buffer, + start - buffer->input_buffer); - memmove (window->buffer->input_buffer, start, strlen (start)); + memmove (buffer->input_buffer, start, strlen (start)); - window->buffer->input_buffer_size -= size_deleted; - window->buffer->input_buffer_length -= length_deleted; - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - window->buffer->input_buffer_pos = 0; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size -= size_deleted; + buffer->input_buffer_length -= length_deleted; + buffer->input_buffer[buffer->input_buffer_size] = '\0'; + buffer->input_buffer_pos = 0; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -710,24 +715,24 @@ gui_input_delete_beginning_of_line (struct t_gui_window *window) */ void -gui_input_delete_end_of_line (struct t_gui_window *window) +gui_input_delete_end_of_line (struct t_gui_buffer *buffer) { char *start; int size_deleted; - if (window->buffer->input) + if (buffer->input) { - gui_buffer_undo_snap (window->buffer); - start = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); + gui_buffer_undo_snap (buffer); + start = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); size_deleted = strlen (start); gui_input_clipboard_copy (start, size_deleted); start[0] = '\0'; - window->buffer->input_buffer_size = strlen (window->buffer->input_buffer); - window->buffer->input_buffer_length = utf8_strlen (window->buffer->input_buffer); - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + buffer->input_buffer_size = strlen (buffer->input_buffer); + buffer->input_buffer_length = utf8_strlen (buffer->input_buffer); + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -736,18 +741,18 @@ gui_input_delete_end_of_line (struct t_gui_window *window) */ void -gui_input_delete_line (struct t_gui_window *window) +gui_input_delete_line (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input) { - gui_buffer_undo_snap (window->buffer); - window->buffer->input_buffer[0] = '\0'; - window->buffer->input_buffer_size = 0; - window->buffer->input_buffer_length = 0; - window->buffer->input_buffer_pos = 0; - gui_input_optimize_size (window->buffer); - gui_completion_stop (window->buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + gui_buffer_undo_snap (buffer); + buffer->input_buffer[0] = '\0'; + buffer->input_buffer_size = 0; + buffer->input_buffer_length = 0; + buffer->input_buffer_pos = 0; + gui_input_optimize_size (buffer); + gui_completion_stop (buffer->completion, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -757,22 +762,22 @@ gui_input_delete_line (struct t_gui_window *window) */ void -gui_input_transpose_chars (struct t_gui_window *window) +gui_input_transpose_chars (struct t_gui_buffer *buffer) { char *start, *prev_char, saved_char[5]; int size_prev_char, size_start_char; - if (window->buffer->input && (window->buffer->input_buffer_pos > 0) - && (window->buffer->input_buffer_length > 1)) + if (buffer->input && (buffer->input_buffer_pos > 0) + && (buffer->input_buffer_length > 1)) { - gui_buffer_undo_snap (window->buffer); + gui_buffer_undo_snap (buffer); - if (window->buffer->input_buffer_pos == window->buffer->input_buffer_length) - window->buffer->input_buffer_pos--; + if (buffer->input_buffer_pos == buffer->input_buffer_length) + buffer->input_buffer_pos--; - start = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); - prev_char = utf8_prev_char (window->buffer->input_buffer, start); + start = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); + prev_char = utf8_prev_char (buffer->input_buffer, start); size_prev_char = start - prev_char; size_start_char = utf8_char_size (start); @@ -780,11 +785,11 @@ gui_input_transpose_chars (struct t_gui_window *window) memcpy (prev_char, start, size_start_char); memcpy (prev_char + size_start_char, saved_char, size_prev_char); - window->buffer->input_buffer_pos++; + buffer->input_buffer_pos++; - gui_completion_stop (window->buffer->completion, 1); + gui_completion_stop (buffer->completion, 1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + gui_input_text_changed_modifier_and_signal (buffer, 1); } } @@ -793,15 +798,12 @@ gui_input_transpose_chars (struct t_gui_window *window) */ void -gui_input_move_beginning_of_line (struct t_gui_window *window) +gui_input_move_beginning_of_line (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input && (buffer->input_buffer_pos > 0)) { - if (window->buffer->input_buffer_pos > 0) - { - window->buffer->input_buffer_pos = 0; - gui_input_text_cursor_moved_signal (); - } + buffer->input_buffer_pos = 0; + gui_input_text_cursor_moved_signal (); } } @@ -810,15 +812,13 @@ gui_input_move_beginning_of_line (struct t_gui_window *window) */ void -gui_input_move_end_of_line (struct t_gui_window *window) +gui_input_move_end_of_line (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input + && (buffer->input_buffer_pos < buffer->input_buffer_length)) { - if (window->buffer->input_buffer_pos < window->buffer->input_buffer_length) - { - window->buffer->input_buffer_pos = window->buffer->input_buffer_length; - gui_input_text_cursor_moved_signal (); - } + buffer->input_buffer_pos = buffer->input_buffer_length; + gui_input_text_cursor_moved_signal (); } } @@ -827,15 +827,12 @@ gui_input_move_end_of_line (struct t_gui_window *window) */ void -gui_input_move_previous_char (struct t_gui_window *window) +gui_input_move_previous_char (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input && (buffer->input_buffer_pos > 0)) { - if (window->buffer->input_buffer_pos > 0) - { - window->buffer->input_buffer_pos--; - gui_input_text_cursor_moved_signal (); - } + buffer->input_buffer_pos--; + gui_input_text_cursor_moved_signal (); } } @@ -844,15 +841,13 @@ gui_input_move_previous_char (struct t_gui_window *window) */ void -gui_input_move_next_char (struct t_gui_window *window) +gui_input_move_next_char (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input + && (buffer->input_buffer_pos < buffer->input_buffer_length)) { - if (window->buffer->input_buffer_pos < window->buffer->input_buffer_length) - { - window->buffer->input_buffer_pos++; - gui_input_text_cursor_moved_signal (); - } + buffer->input_buffer_pos++; + gui_input_text_cursor_moved_signal (); } } @@ -862,38 +857,36 @@ gui_input_move_next_char (struct t_gui_window *window) */ void -gui_input_move_previous_word (struct t_gui_window *window) +gui_input_move_previous_word (struct t_gui_buffer *buffer) { char *pos; - if (window->buffer->input) + if (buffer->input + && (buffer->input_buffer_pos > 0)) { - if (window->buffer->input_buffer_pos > 0) + pos = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos - 1); + while (pos && (pos[0] == ' ')) + { + pos = utf8_prev_char (buffer->input_buffer, pos); + } + if (pos) { - pos = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos - 1); - while (pos && (pos[0] == ' ')) + while (pos && (pos[0] != ' ')) { - pos = utf8_prev_char (window->buffer->input_buffer, pos); + pos = utf8_prev_char (buffer->input_buffer, pos); } if (pos) - { - while (pos && (pos[0] != ' ')) - { - pos = utf8_prev_char (window->buffer->input_buffer, pos); - } - if (pos) - pos = utf8_next_char (pos); - else - pos = window->buffer->input_buffer; - window->buffer->input_buffer_pos = utf8_pos (window->buffer->input_buffer, - pos - window->buffer->input_buffer); - } + pos = utf8_next_char (pos); else - window->buffer->input_buffer_pos = 0; - - gui_input_text_cursor_moved_signal (); + pos = buffer->input_buffer; + buffer->input_buffer_pos = utf8_pos (buffer->input_buffer, + pos - buffer->input_buffer); } + else + buffer->input_buffer_pos = 0; + + gui_input_text_cursor_moved_signal (); } } @@ -903,44 +896,42 @@ gui_input_move_previous_word (struct t_gui_window *window) */ void -gui_input_move_next_word (struct t_gui_window *window) +gui_input_move_next_word (struct t_gui_buffer *buffer) { char *pos; - if (window->buffer->input) + if (buffer->input + && (buffer->input_buffer_pos < buffer->input_buffer_length)) { - if (window->buffer->input_buffer_pos < window->buffer->input_buffer_length) + pos = utf8_add_offset (buffer->input_buffer, + buffer->input_buffer_pos); + while (pos[0] && (pos[0] == ' ')) { - pos = utf8_add_offset (window->buffer->input_buffer, - window->buffer->input_buffer_pos); - while (pos[0] && (pos[0] == ' ')) + pos = utf8_next_char (pos); + } + if (pos[0]) + { + while (pos[0] && (pos[0] != ' ')) { pos = utf8_next_char (pos); } if (pos[0]) { - while (pos[0] && (pos[0] != ' ')) - { - pos = utf8_next_char (pos); - } - if (pos[0]) - { - window->buffer->input_buffer_pos = - utf8_pos (window->buffer->input_buffer, - pos - window->buffer->input_buffer); - } - else - window->buffer->input_buffer_pos = window->buffer->input_buffer_length; + buffer->input_buffer_pos = + utf8_pos (buffer->input_buffer, + pos - buffer->input_buffer); } else - { - window->buffer->input_buffer_pos = - utf8_pos (window->buffer->input_buffer, - utf8_prev_char (window->buffer->input_buffer, pos) - window->buffer->input_buffer); - } - - gui_input_text_cursor_moved_signal (); + buffer->input_buffer_pos = buffer->input_buffer_length; } + else + { + buffer->input_buffer_pos = + utf8_pos (buffer->input_buffer, + utf8_prev_char (buffer->input_buffer, pos) - buffer->input_buffer); + } + + gui_input_text_cursor_moved_signal (); } } @@ -1094,11 +1085,17 @@ gui_input_history_next (struct t_gui_window *window, */ void -gui_input_history_local_previous (struct t_gui_window *window) +gui_input_history_local_previous (struct t_gui_buffer *buffer) { - gui_input_history_previous (window, - window->buffer->history, - &(window->buffer->ptr_history)); + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window) + { + gui_input_history_previous (window, + window->buffer->history, + &(window->buffer->ptr_history)); + } } /* @@ -1107,11 +1104,17 @@ gui_input_history_local_previous (struct t_gui_window *window) */ void -gui_input_history_local_next (struct t_gui_window *window) +gui_input_history_local_next (struct t_gui_buffer *buffer) { - gui_input_history_next (window, - window->buffer->history, - &(window->buffer->ptr_history)); + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window) + { + gui_input_history_next (window, + window->buffer->history, + &(window->buffer->ptr_history)); + } } /* @@ -1120,11 +1123,17 @@ gui_input_history_local_next (struct t_gui_window *window) */ void -gui_input_history_global_previous (struct t_gui_window *window) +gui_input_history_global_previous (struct t_gui_buffer *buffer) { - gui_input_history_previous (window, - history_global, - &history_global_ptr); + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window) + { + gui_input_history_previous (window, + history_global, + &history_global_ptr); + } } /* @@ -1133,21 +1142,31 @@ gui_input_history_global_previous (struct t_gui_window *window) */ void -gui_input_history_global_next (struct t_gui_window *window) +gui_input_history_global_next (struct t_gui_buffer *buffer) { - gui_input_history_next (window, - history_global, - &history_global_ptr); + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window) + { + gui_input_history_next (window, + history_global, + &history_global_ptr); + } } /* - * gui_input_jump_smart: jump to buffer with activity (default key: alt-A) + * gui_input_jump_smart: jump to buffer with activity (default key: alt-a) */ void -gui_input_jump_smart (struct t_gui_window *window) +gui_input_jump_smart (struct t_gui_buffer *buffer) { - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window + && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { if (gui_hotlist) { @@ -1175,9 +1194,13 @@ gui_input_jump_smart (struct t_gui_window *window) */ void -gui_input_jump_last_buffer (struct t_gui_window *window) +gui_input_jump_last_buffer (struct t_gui_buffer *buffer) { - if ((window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window + && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) && last_gui_buffer) { gui_buffer_switch_by_number (window, last_gui_buffer->number); @@ -1191,12 +1214,15 @@ gui_input_jump_last_buffer (struct t_gui_window *window) */ void -gui_input_jump_previously_visited_buffer (struct t_gui_window *window) +gui_input_jump_previously_visited_buffer (struct t_gui_buffer *buffer) { + struct t_gui_window *window; int index; struct t_gui_buffer_visited *ptr_buffer_visited; - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + window = gui_window_search_with_buffer (buffer); + if (window + && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { index = gui_buffer_visited_get_index_previous (); if (index >= 0) @@ -1223,12 +1249,15 @@ gui_input_jump_previously_visited_buffer (struct t_gui_window *window) */ void -gui_input_jump_next_visited_buffer (struct t_gui_window *window) +gui_input_jump_next_visited_buffer (struct t_gui_buffer *buffer) { + struct t_gui_window *window; int index; struct t_gui_buffer_visited *ptr_buffer_visited; - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + window = gui_window_search_with_buffer (buffer); + if (window + && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { index = gui_buffer_visited_get_index_next (); if (index >= 0) @@ -1252,10 +1281,10 @@ gui_input_jump_next_visited_buffer (struct t_gui_window *window) */ void -gui_input_hotlist_clear (struct t_gui_window *window) +gui_input_hotlist_clear (struct t_gui_buffer *buffer) { gui_hotlist_clear (); - gui_hotlist_initial_buffer = window->buffer; + gui_hotlist_initial_buffer = buffer; } /* @@ -1264,9 +1293,9 @@ gui_input_hotlist_clear (struct t_gui_window *window) */ void -gui_input_grab_key (struct t_gui_window *window) +gui_input_grab_key (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input) gui_keyboard_grab_init (0); } @@ -1276,9 +1305,9 @@ gui_input_grab_key (struct t_gui_window *window) */ void -gui_input_grab_key_command (struct t_gui_window *window) +gui_input_grab_key_command (struct t_gui_buffer *buffer) { - if (window->buffer->input) + if (buffer->input) gui_keyboard_grab_init (1); } @@ -1288,9 +1317,13 @@ gui_input_grab_key_command (struct t_gui_window *window) */ void -gui_input_scroll_unread (struct t_gui_window *window) +gui_input_scroll_unread (struct t_gui_buffer *buffer) { - if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) + struct t_gui_window *window; + + window = gui_window_search_with_buffer (buffer); + if (window + && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { if (CONFIG_STRING(config_look_read_marker) && CONFIG_STRING(config_look_read_marker)[0] && @@ -1339,26 +1372,30 @@ gui_input_set_unread () */ void -gui_input_set_unread_current (struct t_gui_window *window) +gui_input_set_unread_current (struct t_gui_buffer *buffer) { - gui_buffer_set_unread (window->buffer); + gui_buffer_set_unread (buffer); } /* * gui_input_switch_active_buffer: switch active buffer to next buffer * (when many buffers are merged) + * (default key: ctrl-x) */ void -gui_input_switch_active_buffer (struct t_gui_window *window) +gui_input_switch_active_buffer (struct t_gui_buffer *buffer) { struct t_gui_buffer *ptr_buffer; + struct t_gui_window *window; - ptr_buffer = gui_buffer_get_next_active_buffer (window->buffer); + ptr_buffer = gui_buffer_get_next_active_buffer (buffer); if (ptr_buffer) { gui_buffer_set_active_buffer (ptr_buffer); - gui_window_switch_to_buffer (window, ptr_buffer, 1); + window = gui_window_search_with_buffer (buffer); + if (window) + gui_window_switch_to_buffer (window, ptr_buffer, 1); } } @@ -1369,15 +1406,18 @@ gui_input_switch_active_buffer (struct t_gui_window *window) */ void -gui_input_switch_active_buffer_previous (struct t_gui_window *window) +gui_input_switch_active_buffer_previous (struct t_gui_buffer *buffer) { struct t_gui_buffer *ptr_buffer; + struct t_gui_window *window; - ptr_buffer = gui_buffer_get_previous_active_buffer (window->buffer); + ptr_buffer = gui_buffer_get_previous_active_buffer (buffer); if (ptr_buffer) { gui_buffer_set_active_buffer (ptr_buffer); - gui_window_switch_to_buffer (window, ptr_buffer, 1); + window = gui_window_search_with_buffer (buffer); + if (window) + gui_window_switch_to_buffer (window, ptr_buffer, 1); } } @@ -1387,16 +1427,16 @@ gui_input_switch_active_buffer_previous (struct t_gui_window *window) */ void -gui_input_insert (struct t_gui_window *window, const char *args) +gui_input_insert (struct t_gui_buffer *buffer, const char *args) { char *args2; if (args) { - gui_buffer_undo_snap (window->buffer); + gui_buffer_undo_snap (buffer); args2 = string_convert_hex_chars (args); - gui_input_insert_string (window->buffer, (args2) ? args2 : args, -1); - gui_input_text_changed_modifier_and_signal (window->buffer, 1); + gui_input_insert_string (buffer, (args2) ? args2 : args, -1); + gui_input_text_changed_modifier_and_signal (buffer, 1); if (args2) free (args2); } @@ -1422,28 +1462,28 @@ gui_input_undo_use (struct t_gui_buffer *buffer, struct t_gui_input_undo *undo) */ void -gui_input_undo (struct t_gui_window *window) +gui_input_undo (struct t_gui_buffer *buffer) { - if (window->buffer->ptr_input_undo) + if (buffer->ptr_input_undo) { /* * if we are doing undo and that undo pointer is to the end of list * (for example first time undo is used), then save current input * content in undo list */ - if ((window->buffer->ptr_input_undo == window->buffer->last_input_undo) - && (window->buffer->ptr_input_undo)->data - && (strcmp (window->buffer->input_buffer, (window->buffer->ptr_input_undo)->data) != 0)) + if ((buffer->ptr_input_undo == buffer->last_input_undo) + && (buffer->ptr_input_undo)->data + && (strcmp (buffer->input_buffer, (buffer->ptr_input_undo)->data) != 0)) { - gui_buffer_undo_snap_free (window->buffer); - gui_buffer_undo_add (window->buffer); + gui_buffer_undo_snap_free (buffer); + gui_buffer_undo_add (buffer); } - if (window->buffer->ptr_input_undo - && (window->buffer->ptr_input_undo)->prev_undo) + if (buffer->ptr_input_undo + && (buffer->ptr_input_undo)->prev_undo) { - window->buffer->ptr_input_undo = (window->buffer->ptr_input_undo)->prev_undo; - gui_input_undo_use (window->buffer, window->buffer->ptr_input_undo); + buffer->ptr_input_undo = (buffer->ptr_input_undo)->prev_undo; + gui_input_undo_use (buffer, buffer->ptr_input_undo); } } } @@ -1453,12 +1493,12 @@ gui_input_undo (struct t_gui_window *window) */ void -gui_input_redo (struct t_gui_window *window) +gui_input_redo (struct t_gui_buffer *buffer) { - if (window->buffer->ptr_input_undo - && (window->buffer->ptr_input_undo)->next_undo) + if (buffer->ptr_input_undo + && (buffer->ptr_input_undo)->next_undo) { - window->buffer->ptr_input_undo = (window->buffer->ptr_input_undo)->next_undo; - gui_input_undo_use (window->buffer, window->buffer->ptr_input_undo); + buffer->ptr_input_undo = (buffer->ptr_input_undo)->next_undo; + gui_input_undo_use (buffer, buffer->ptr_input_undo); } } diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index 43f2866cf..557180154 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -21,7 +21,6 @@ #define __WEECHAT_GUI_INPUT_H 1 struct t_gui_buffer; -struct t_gui_window; /* input variables */ @@ -39,43 +38,43 @@ extern int gui_input_insert_string (struct t_gui_buffer *buffer, const char *string, int pos); extern void gui_input_move_to_buffer (struct t_gui_buffer *from_buffer, struct t_gui_buffer *to_buffer); -extern void gui_input_clipboard_paste (struct t_gui_window *window); -extern void gui_input_return (struct t_gui_window *window); -extern void gui_input_complete_next (struct t_gui_window *window); -extern void gui_input_complete_previous (struct t_gui_window *window); -extern void gui_input_search_text (struct t_gui_window *window); -extern void gui_input_delete_previous_char (struct t_gui_window *window); -extern void gui_input_delete_next_char (struct t_gui_window *window); -extern void gui_input_delete_previous_word (struct t_gui_window *window); -extern void gui_input_delete_next_word (struct t_gui_window *window); -extern void gui_input_delete_beginning_of_line (struct t_gui_window *window); -extern void gui_input_delete_end_of_line (struct t_gui_window *window); -extern void gui_input_delete_line (struct t_gui_window *window); -extern void gui_input_transpose_chars (struct t_gui_window *window); -extern void gui_input_move_beginning_of_line (struct t_gui_window *window); -extern void gui_input_move_end_of_line (struct t_gui_window *window); -extern void gui_input_move_previous_char (struct t_gui_window *window); -extern void gui_input_move_next_char (struct t_gui_window *window); -extern void gui_input_move_previous_word (struct t_gui_window *window); -extern void gui_input_move_next_word (struct t_gui_window *window); -extern void gui_input_history_local_previous (struct t_gui_window *window); -extern void gui_input_history_local_next (struct t_gui_window *window); -extern void gui_input_history_global_previous (struct t_gui_window *window); -extern void gui_input_history_global_next (struct t_gui_window *window); -extern void gui_input_jump_smart (struct t_gui_window *window); -extern void gui_input_jump_last_buffer (struct t_gui_window *window); -extern void gui_input_jump_previously_visited_buffer (struct t_gui_window *window); -extern void gui_input_jump_next_visited_buffer (struct t_gui_window *window); -extern void gui_input_hotlist_clear (struct t_gui_window *window); -extern void gui_input_grab_key (struct t_gui_window *window); -extern void gui_input_grab_key_command (struct t_gui_window *window); -extern void gui_input_scroll_unread (struct t_gui_window *window); +extern void gui_input_clipboard_paste (struct t_gui_buffer *buffer); +extern void gui_input_return (struct t_gui_buffer *buffer); +extern void gui_input_complete_next (struct t_gui_buffer *buffer); +extern void gui_input_complete_previous (struct t_gui_buffer *buffer); +extern void gui_input_search_text (struct t_gui_buffer *buffer); +extern void gui_input_delete_previous_char (struct t_gui_buffer *buffer); +extern void gui_input_delete_next_char (struct t_gui_buffer *buffer); +extern void gui_input_delete_previous_word (struct t_gui_buffer *buffer); +extern void gui_input_delete_next_word (struct t_gui_buffer *buffer); +extern void gui_input_delete_beginning_of_line (struct t_gui_buffer *buffer); +extern void gui_input_delete_end_of_line (struct t_gui_buffer *buffer); +extern void gui_input_delete_line (struct t_gui_buffer *buffer); +extern void gui_input_transpose_chars (struct t_gui_buffer *buffer); +extern void gui_input_move_beginning_of_line (struct t_gui_buffer *buffer); +extern void gui_input_move_end_of_line (struct t_gui_buffer *buffer); +extern void gui_input_move_previous_char (struct t_gui_buffer *buffer); +extern void gui_input_move_next_char (struct t_gui_buffer *buffer); +extern void gui_input_move_previous_word (struct t_gui_buffer *buffer); +extern void gui_input_move_next_word (struct t_gui_buffer *buffer); +extern void gui_input_history_local_previous (struct t_gui_buffer *buffer); +extern void gui_input_history_local_next (struct t_gui_buffer *buffer); +extern void gui_input_history_global_previous (struct t_gui_buffer *buffer); +extern void gui_input_history_global_next (struct t_gui_buffer *buffer); +extern void gui_input_jump_smart (struct t_gui_buffer *buffer); +extern void gui_input_jump_last_buffer (struct t_gui_buffer *buffer); +extern void gui_input_jump_previously_visited_buffer (struct t_gui_buffer *buffer); +extern void gui_input_jump_next_visited_buffer (struct t_gui_buffer *buffer); +extern void gui_input_hotlist_clear (struct t_gui_buffer *buffer); +extern void gui_input_grab_key (struct t_gui_buffer *buffer); +extern void gui_input_grab_key_command (struct t_gui_buffer *buffer); +extern void gui_input_scroll_unread (struct t_gui_buffer *buffer); extern void gui_input_set_unread (); -extern void gui_input_set_unread_current (struct t_gui_window *window); -extern void gui_input_switch_active_buffer (struct t_gui_window *window); -extern void gui_input_switch_active_buffer_previous (struct t_gui_window *window); -extern void gui_input_insert (struct t_gui_window *window, const char *args); -extern void gui_input_undo (struct t_gui_window *window); -extern void gui_input_redo (struct t_gui_window *window); +extern void gui_input_set_unread_current (struct t_gui_buffer *buffer); +extern void gui_input_switch_active_buffer (struct t_gui_buffer *buffer); +extern void gui_input_switch_active_buffer_previous (struct t_gui_buffer *buffer); +extern void gui_input_insert (struct t_gui_buffer *buffer, const char *args); +extern void gui_input_undo (struct t_gui_buffer *buffer); +extern void gui_input_redo (struct t_gui_buffer *buffer); #endif /* __WEECHAT_GUI_INPUT_H */ diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 8048ecac5..7e9505e68 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -484,6 +484,38 @@ gui_window_valid (struct t_gui_window *window) } /* + * gui_window_search_with_buffer: search window displaying a buffer + * return NULL if no window is displaying given + * buffer + * If many windows are displaying this buffer, + * the first window in list is returned (or + * current window if it is displaying this + * buffer) + */ + +struct t_gui_window * +gui_window_search_with_buffer (struct t_gui_buffer *buffer) +{ + struct t_gui_window *ptr_window; + + if (!buffer) + return NULL; + + if (gui_current_window->buffer == buffer) + return gui_current_window; + + for (ptr_window = gui_windows; ptr_window; + ptr_window = ptr_window->next_window) + { + if (ptr_window->buffer == buffer) + return ptr_window; + } + + /* no window displaying buffer */ + return NULL; +} + +/* * gui_window_get_integer: get a window property as integer */ @@ -1064,7 +1096,7 @@ gui_window_search_start (struct t_gui_window *window) if (window->buffer->input_buffer && window->buffer->input_buffer[0]) window->buffer->text_search_input = strdup (window->buffer->input_buffer); - gui_input_delete_line (window); + gui_input_delete_line (window->buffer); } /* @@ -1101,7 +1133,7 @@ gui_window_search_stop (struct t_gui_window *window) { window->buffer->text_search = GUI_TEXT_SEARCH_DISABLED; window->buffer->text_search = 0; - gui_input_delete_line (window); + gui_input_delete_line (window->buffer); if (window->buffer->text_search_input) { gui_input_insert_string (window->buffer, diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 1e7920d49..6aabcb57e 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -128,6 +128,7 @@ extern struct t_gui_window *gui_window_new (struct t_gui_window *parent_window, int x, int y, int width, int height, int width_pct, int height_pct); extern int gui_window_valid (struct t_gui_window *window); +extern struct t_gui_window *gui_window_search_with_buffer (struct t_gui_buffer *buffer); extern int gui_window_get_integer (struct t_gui_window *window, const char *property); extern const char *gui_window_get_string (struct t_gui_window *window, diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 771488656..a17088f96 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -621,6 +621,7 @@ plugin_load (const char *filename) new_plugin->buffer_string_replace_local_var = &gui_buffer_string_replace_local_var; new_plugin->buffer_match_list = &gui_buffer_match_list; + new_plugin->window_search_with_buffer = &gui_window_search_with_buffer; new_plugin->window_get_integer = &gui_window_get_integer; new_plugin->window_get_string = &gui_window_get_string; new_plugin->window_get_pointer = &gui_window_get_pointer; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index f0b64af5d..286b4509b 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -5303,6 +5303,42 @@ weechat_lua_api_current_window (lua_State *L) } /* + * weechat_lua_api_window_search_with_buffer: search a window with buffer + * pointer + */ + +static int +weechat_lua_api_window_search_with_buffer (lua_State *L) +{ + const char *buffer; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script || !lua_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + LUA_RETURN_EMPTY; + } + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + LUA_RETURN_EMPTY; + } + + buffer = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (weechat_window_search_with_buffer (script_str2ptr (buffer))); + + LUA_RETURN_STRING_FREE(result); +} + +/* * weechat_lua_api_window_get_integer: get a window property as integer */ @@ -7807,6 +7843,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "buffer_string_replace_local_var", &weechat_lua_api_buffer_string_replace_local_var }, { "buffer_match_list", &weechat_lua_api_buffer_match_list }, { "current_window", &weechat_lua_api_current_window }, + { "window_search_with_buffer", &weechat_lua_api_window_search_with_buffer }, { "window_get_integer", &weechat_lua_api_window_get_integer }, { "window_get_string", &weechat_lua_api_window_get_string }, { "window_get_pointer", &weechat_lua_api_window_get_pointer }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 6ea96f1bc..0219a8e08 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -4823,6 +4823,36 @@ XS (XS_weechat_api_current_window) } /* + * weechat::window_search_with_buffer: search a window with buffer pointer + */ + +XS (XS_weechat_api_window_search_with_buffer) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script || !perl_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + PERL_RETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + PERL_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_window_search_with_buffer (script_str2ptr (SvPV (ST (0), PL_na)))); + + PERL_RETURN_STRING_FREE(result); +} + + +/* * weechat::window_get_integer: get a window property as integer */ @@ -6742,6 +6772,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::buffer_string_replace_local_var", XS_weechat_api_buffer_string_replace_local_var, "weechat"); newXS ("weechat::buffer_match_list", XS_weechat_api_buffer_match_list, "weechat"); newXS ("weechat::current_window", XS_weechat_api_current_window, "weechat"); + newXS ("weechat::window_search_with_buffer", XS_weechat_api_window_search_with_buffer, "weechat"); newXS ("weechat::window_get_integer", XS_weechat_api_window_get_integer, "weechat"); newXS ("weechat::window_get_string", XS_weechat_api_window_get_string, "weechat"); newXS ("weechat::window_get_pointer", XS_weechat_api_window_get_pointer, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 58dd89af1..9a3924fc4 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -5081,6 +5081,39 @@ weechat_python_api_current_window (PyObject *self, PyObject *args) } /* + * weechat_python_api_window_search_with_buffer: search a window with buffer + * pointer + */ + +static PyObject * +weechat_python_api_window_search_with_buffer (PyObject *self, PyObject *args) +{ + char *buffer, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script || !python_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + PYTHON_RETURN_EMPTY; + } + + buffer = NULL; + + if (!PyArg_ParseTuple (args, "s", &buffer)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_window_search_with_buffer (script_str2ptr (buffer))); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* * weechat_python_api_window_get_integer get a window property as integer */ @@ -7076,6 +7109,7 @@ PyMethodDef weechat_python_funcs[] = { "buffer_string_replace_local_var", &weechat_python_api_buffer_string_replace_local_var, METH_VARARGS, "" }, { "buffer_match_list", &weechat_python_api_buffer_match_list, METH_VARARGS, "" }, { "current_window", &weechat_python_api_current_window, METH_VARARGS, "" }, + { "window_search_with_buffer", &weechat_python_api_window_search_with_buffer, METH_VARARGS, "" }, { "window_get_integer", &weechat_python_api_window_get_integer, METH_VARARGS, "" }, { "window_get_string", &weechat_python_api_window_get_string, METH_VARARGS, "" }, { "window_get_pointer", &weechat_python_api_window_get_pointer, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index af75cad78..cfa82cf88 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -5498,6 +5498,41 @@ weechat_ruby_api_current_window (VALUE class) } /* + * weechat_ruby_api_window_search_with_buffer: search a window with buffer + * pointer + */ + +static VALUE +weechat_ruby_api_window_search_with_buffer (VALUE class, VALUE buffer) +{ + char *c_buffer, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script || !ruby_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (buffer)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + RUBY_RETURN_EMPTY; + } + + Check_Type (buffer, T_STRING); + + c_buffer = StringValuePtr (buffer); + + result = script_ptr2str (weechat_window_search_with_buffer (script_str2ptr (c_buffer))); + + RUBY_RETURN_STRING_FREE(result); +} + +/* * weechat_ruby_api_window_get_integer: get a window property as integer */ @@ -7745,6 +7780,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "buffer_string_replace_local_var", &weechat_ruby_api_buffer_string_replace_local_var, 2); rb_define_module_function (ruby_mWeechat, "buffer_match_list", &weechat_ruby_api_buffer_match_list, 2); rb_define_module_function (ruby_mWeechat, "current_window", &weechat_ruby_api_current_window, 0); + rb_define_module_function (ruby_mWeechat, "window_search_with_buffer", &weechat_ruby_api_window_search_with_buffer, 1); rb_define_module_function (ruby_mWeechat, "window_get_integer", &weechat_ruby_api_window_get_integer, 2); rb_define_module_function (ruby_mWeechat, "window_get_string", &weechat_ruby_api_window_get_string, 2); rb_define_module_function (ruby_mWeechat, "window_get_pointer", &weechat_ruby_api_window_get_pointer, 2); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 9f870efb9..b36d72ad3 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -5391,6 +5391,41 @@ weechat_tcl_api_current_window (ClientData clientData, Tcl_Interp *interp, } /* + * weechat_tcl_api_window_search_with_buffer: search a window with buffer + * pointer + */ + +static int +weechat_tcl_api_window_search_with_buffer (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *buffer, *result; + int i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script || !tcl_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + TCL_RETURN_EMPTY; + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "window_search_with_buffer"); + TCL_RETURN_EMPTY; + } + + buffer = Tcl_GetStringFromObj (objv[1], &i); + + result = script_ptr2str (weechat_window_search_with_buffer (script_str2ptr (buffer))); + + TCL_RETURN_STRING_FREE(result); +} + +/* * weechat_tcl_api_window_get_integer: get a window property as integer */ @@ -7690,6 +7725,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) weechat_tcl_api_buffer_match_list, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::current_window", weechat_tcl_api_current_window, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp, "weechat::window_search_with_buffer", + weechat_tcl_api_window_search_with_buffer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::window_get_integer", weechat_tcl_api_window_get_integer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::window_get_string", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 92b6c40b2..e580aa230 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -45,7 +45,7 @@ struct timeval; */ /* API version (used to check that plugin has same API and can be loaded) */ -#define WEECHAT_PLUGIN_API_VERSION "20110311-01" +#define WEECHAT_PLUGIN_API_VERSION "20110413-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -600,6 +600,7 @@ struct t_weechat_plugin int (*buffer_match_list) (struct t_gui_buffer *buffer, const char *string); /* windows */ + struct t_gui_window *(*window_search_with_buffer) (struct t_gui_buffer *buffer); int (*window_get_integer) (struct t_gui_window *window, const char *property); const char *(*window_get_string) (struct t_gui_window *window, @@ -1260,6 +1261,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->buffer_match_list(__buffer, __string) /* windows */ +#define weechat_window_search_with_buffer(__buffer) \ + weechat_plugin->window_search_with_buffer(__buffer) #define weechat_window_get_integer(__window, __property) \ weechat_plugin->window_get_integer(__window, __property) #define weechat_window_get_string(__window, __property) \ |