diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-17 17:59:27 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-17 17:59:27 +0200 |
commit | e349ae491a9ce9bebd38b14e41c95aabe694a7ed (patch) | |
tree | ef15cbc2c558b52bc71da95ac92a23f819270b83 /src | |
parent | 62bcf75851fbf10e4b8307ce96592ca8392f78dc (diff) | |
download | weechat-e349ae491a9ce9bebd38b14e41c95aabe694a7ed.zip |
Added infolist "window", scroll in buffers with free content, fixed config hooks (use of string_match)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-hook.c | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 2 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 316 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 13 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 | ||||
-rw-r--r-- | src/gui/gui-window.c | 32 | ||||
-rw-r--r-- | src/gui/gui-window.h | 1 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 132 |
8 files changed, 387 insertions, 114 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index ec0227911..a9f43f990 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -990,8 +990,7 @@ hook_config_exec (char *option, char *value) if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_CONFIG(ptr_hook, option) - || (string_strcasecmp (HOOK_CONFIG(ptr_hook, option), - option) == 0))) + || (string_match (option, HOOK_CONFIG(ptr_hook, option), 0)))) { ptr_hook->running = 1; (void) (HOOK_CONFIG(ptr_hook, callback)) diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 8fabd0b02..02fcb8fe9 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -1259,6 +1259,8 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) } } break; + case GUI_BUFFER_NUM_TYPES: + break; } wnoutrefresh (GUI_CURSES(ptr_win)->win_chat); } diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index ee79a461d..bfd018190 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -553,6 +553,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window, if (window->buffer != buffer) { + window->start_line = NULL; + window->start_line_pos = 0; window->buffer->last_read_line = window->buffer->last_line; if (buffer->last_read_line == buffer->last_line) buffer->last_read_line = NULL; @@ -622,9 +624,6 @@ gui_window_switch_to_buffer (struct t_gui_window *window, window->win_status_y, window->win_status_x); - window->start_line = NULL; - window->start_line_pos = 0; - buffer->num_displayed++; gui_hotlist_remove_buffer (buffer); @@ -647,23 +646,42 @@ gui_window_switch_to_buffer (struct t_gui_window *window, void gui_window_page_up (struct t_gui_window *window) { + char scroll[32]; + if (!gui_ok) return; - if (!window->first_line_displayed) + switch (window->buffer->type) { - gui_chat_calculate_line_diff (window, &window->start_line, - &window->start_line_pos, - (window->start_line) ? - (-1) * (window->win_chat_height - 1) : - (-1) * ((window->win_chat_height - 1) * 2)); - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { - window->start_line = NULL; - window->start_line_pos = 0; - } - gui_status_refresh_needed = 1; + case GUI_BUFFER_TYPE_FORMATED: + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * (window->win_chat_height - 1) : + (-1) * ((window->win_chat_height - 1) * 2)); + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: + if (window->start_line) + { + snprintf (scroll, sizeof (scroll), "-%d", + window->win_chat_height); + gui_window_scroll (window, scroll); + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + } + break; + case GUI_BUFFER_NUM_TYPES: + break; } } @@ -676,36 +694,51 @@ gui_window_page_down (struct t_gui_window *window) { struct t_gui_line *ptr_line; int line_pos; + char scroll[32]; if (!gui_ok) return; - if (window->start_line) + switch (window->buffer->type) { - gui_chat_calculate_line_diff (window, &window->start_line, - &window->start_line_pos, - window->win_chat_height - 1); - - /* check if we can display all */ - ptr_line = window->start_line; - line_pos = window->start_line_pos; - gui_chat_calculate_line_diff (window, &ptr_line, - &line_pos, - window->win_chat_height - 1); - if (!ptr_line) - { - window->start_line = NULL; - window->start_line_pos = 0; - } - - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { - window->start_line = NULL; - window->start_line_pos = 0; - gui_hotlist_remove_buffer (window->buffer); - } - gui_status_refresh_needed = 1; + case GUI_BUFFER_TYPE_FORMATED: + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + window->win_chat_height - 1); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_hotlist_remove_buffer (window->buffer); + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: + snprintf (scroll, sizeof (scroll), "+%d", + window->win_chat_height); + gui_window_scroll (window, scroll); + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + break; + case GUI_BUFFER_NUM_TYPES: + break; } } @@ -716,25 +749,44 @@ gui_window_page_down (struct t_gui_window *window) void gui_window_scroll_up (struct t_gui_window *window) { + char scroll[32]; + if (!gui_ok) return; - - if (!window->first_line_displayed) + + switch (window->buffer->type) { - gui_chat_calculate_line_diff (window, &window->start_line, - &window->start_line_pos, - (window->start_line) ? - (-1) * CONFIG_INTEGER(config_look_scroll_amount) : - (-1) * ( (window->win_chat_height - 1) + - CONFIG_INTEGER(config_look_scroll_amount))); - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { - window->start_line = NULL; - window->start_line_pos = 0; - } - gui_status_refresh_needed = 1; - } + case GUI_BUFFER_TYPE_FORMATED: + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * CONFIG_INTEGER(config_look_scroll_amount) : + (-1) * ( (window->win_chat_height - 1) + + CONFIG_INTEGER(config_look_scroll_amount))); + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: + if (window->start_line) + { + snprintf (scroll, sizeof (scroll), "-%d", + CONFIG_INTEGER(config_look_scroll_amount)); + gui_window_scroll (window, scroll); + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + } + break; + case GUI_BUFFER_NUM_TYPES: + break; + } } /* @@ -746,37 +798,52 @@ gui_window_scroll_down (struct t_gui_window *window) { struct t_gui_line *ptr_line; int line_pos; + char scroll[32]; if (!gui_ok) return; - if (window->start_line) + switch (window->buffer->type) { - gui_chat_calculate_line_diff (window, &window->start_line, - &window->start_line_pos, - CONFIG_INTEGER(config_look_scroll_amount)); - - /* check if we can display all */ - ptr_line = window->start_line; - line_pos = window->start_line_pos; - gui_chat_calculate_line_diff (window, &ptr_line, - &line_pos, - window->win_chat_height - 1); - - if (!ptr_line) - { - window->start_line = NULL; - window->start_line_pos = 0; - } - - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { - window->start_line = NULL; - window->start_line_pos = 0; - gui_hotlist_remove_buffer (window->buffer); - } - gui_status_refresh_needed = 1; + case GUI_BUFFER_TYPE_FORMATED: + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + CONFIG_INTEGER(config_look_scroll_amount)); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_hotlist_remove_buffer (window->buffer); + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: + snprintf (scroll, sizeof (scroll), "+%d", + CONFIG_INTEGER(config_look_scroll_amount)); + gui_window_scroll (window, scroll); + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + break; + case GUI_BUFFER_NUM_TYPES: + break; } } @@ -790,17 +857,33 @@ gui_window_scroll_top (struct t_gui_window *window) if (!gui_ok) return; - if (!window->first_line_displayed) + switch (window->buffer->type) { - window->start_line = gui_chat_get_first_line_displayed (window->buffer); - window->start_line_pos = 0; - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { - window->start_line = NULL; - window->start_line_pos = 0; - } - gui_status_refresh_needed = 1; + case GUI_BUFFER_TYPE_FORMATED: + if (!window->first_line_displayed) + { + window->start_line = gui_chat_get_first_line_displayed (window->buffer); + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: + if (window->start_line) + { + window->start_line = NULL; + gui_buffer_ask_chat_refresh (window->buffer, 2); + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + } + break; + case GUI_BUFFER_NUM_TYPES: + break; } } @@ -811,21 +894,46 @@ gui_window_scroll_top (struct t_gui_window *window) void gui_window_scroll_bottom (struct t_gui_window *window) { + char scroll[32]; + if (!gui_ok) return; - - if (window->start_line) + + switch (window->buffer->type) { - window->start_line = NULL; - window->start_line_pos = 0; - gui_chat_draw (window->buffer, 0); - if (!window->scroll) - { + case GUI_BUFFER_TYPE_FORMATED: + if (window->start_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + if (!window->scroll) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_hotlist_remove_buffer (window->buffer); + } + gui_status_refresh_needed = 1; + } + break; + case GUI_BUFFER_TYPE_FREE: window->start_line = NULL; - window->start_line_pos = 0; - gui_hotlist_remove_buffer (window->buffer); - } - gui_status_refresh_needed = 1; + if (window->buffer->lines_count > window->win_chat_height) + { + snprintf (scroll, sizeof (scroll), "-%d", + window->win_chat_height - 1); + gui_window_scroll (window, scroll); + } + else + { + gui_buffer_ask_chat_refresh (window->buffer, 2); + gui_status_refresh_needed = 1; + } + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, window); + break; + case GUI_BUFFER_NUM_TYPES: + break; } } diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 031d66eb6..3bdfd982e 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -360,13 +360,6 @@ gui_buffer_set_type (struct t_gui_buffer *buffer, enum t_gui_buffer_type type) gui_chat_line_free_all (buffer); - switch (type) - { - case GUI_BUFFER_TYPE_FORMATED: - break; - case GUI_BUFFER_TYPE_FREE: - break; - } buffer->type = type; gui_buffer_ask_chat_refresh (buffer, 2); } @@ -520,6 +513,12 @@ gui_buffer_set (struct t_gui_buffer *buffer, char *property, char *value) else gui_keyboard_unbind (buffer, property + 11); } + else if (string_strcasecmp (property, "input") == 0) + { + gui_input_delete_line (buffer); + gui_input_insert_string (buffer, value, 0); + gui_buffer_ask_input_refresh (buffer, 1); + } } /* diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index f292fa9be..4951b8df3 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -24,6 +24,8 @@ enum t_gui_buffer_type { GUI_BUFFER_TYPE_FORMATED = 0, GUI_BUFFER_TYPE_FREE, + /* number of buffer types */ + GUI_BUFFER_NUM_TYPES, }; #define GUI_BUFFER_NOTIFY_LEVEL_MIN 0 diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 66761bfa2..edc6c2f0a 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -34,8 +34,10 @@ #include "../core/weechat.h" #include "../core/wee-config.h" +#include "../core/wee-hook.h" #include "../core/wee-log.h" #include "../core/wee-utf8.h" +#include "../plugins/plugin.h" #include "gui-window.h" #include "gui-bar.h" #include "gui-buffer.h" @@ -284,6 +286,31 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height } /* + * gui_window_valid: check if a buffer pointer exists + * return 1 if buffer exists + * 0 if buffer is not found + */ + +int +gui_window_valid (struct t_gui_window *window) +{ + struct t_gui_window *ptr_window; + + if (!window) + return 0; + + for (ptr_window = gui_windows; ptr_window; + ptr_window = ptr_window->next_window) + { + if (ptr_window == window) + return 1; + } + + /* window not found */ + return 0; +} + +/* * gui_window_free: delete a window */ @@ -646,7 +673,10 @@ gui_window_scroll (struct t_gui_window *window, char *scroll) if (direction < 0) gui_window_scroll_top (window); else - gui_window_scroll_bottom (window); + { + if (window->buffer->type == GUI_BUFFER_TYPE_FORMATED) + gui_window_scroll_bottom (window); + } } } diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index cedb0d2a2..bf5352266 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -129,6 +129,7 @@ extern void gui_window_tree_free (struct t_gui_window_tree **tree); extern struct t_gui_window *gui_window_new (struct t_gui_window *parent, 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 void gui_window_free (struct t_gui_window *window); extern struct t_gui_window *gui_window_search_by_buffer (struct t_gui_buffer *buffer); extern void gui_window_switch_server (struct t_gui_window *window); diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 73ef72aba..1c9cd99ce 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -511,6 +511,101 @@ plugin_api_infolist_get_add_buffer_line (struct t_plugin_infolist *infolist, } /* + * plugin_api_infolist_get_add_window: add a window in a list + * return 1 if ok, 0 if error + */ + +int +plugin_api_infolist_get_add_window (struct t_plugin_infolist *infolist, + struct t_gui_window *window) +{ + struct t_plugin_infolist_item *ptr_item; + + if (!infolist || !window) + return 0; + + ptr_item = plugin_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!plugin_infolist_new_var_pointer (ptr_item, "pointer", window)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "x", window->win_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "y", window->win_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "width", window->win_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "height", window->win_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "width_pct", window->win_width_pct)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "height_pct", window->win_height_pct)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "chat_x", window->win_chat_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "chat_y", window->win_chat_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "chat_width", window->win_chat_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "chat_height", window->win_chat_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "nick_x", window->win_nick_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "nick_y", window->win_nick_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "nick_width", window->win_nick_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "nick_height", window->win_nick_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "nick_start", window->win_nick_start)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "title_x", window->win_title_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "title_y", window->win_title_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "title_width", window->win_title_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "title_start", window->win_title_start)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "status_x", window->win_status_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "status_y", window->win_status_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "status_width", window->win_status_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "status_height", window->win_status_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "infobar_x", window->win_infobar_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "infobar_y", window->win_infobar_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "infobar_width", window->win_infobar_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "infobar_height", window->win_infobar_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "input_x", window->win_input_x)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "input_y", window->win_input_y)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "input_width", window->win_input_width)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "input_height", window->win_input_height)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "input_cursor_x", window->win_input_cursor_x)) + return 0; + if (!plugin_infolist_new_var_pointer (ptr_item, "buffer", window->buffer)) + return 0; + if (!plugin_infolist_new_var_integer (ptr_item, "start_line_y", + ((window->buffer->type == GUI_BUFFER_TYPE_FREE) + && (window->start_line)) ? + window->start_line->y : 0)) + return 0; + + return 1; +} + +/* * plugin_api_infolist_get_add_options: add config options in a list * return 1 if ok, 0 if error */ @@ -722,6 +817,7 @@ plugin_api_infolist_get (char *name, void *pointer, char *arguments) struct t_plugin_infolist *ptr_infolist; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; + struct t_gui_window *ptr_window; if (!name || !name[0]) return NULL; @@ -789,6 +885,42 @@ plugin_api_infolist_get (char *name, void *pointer, char *arguments) return ptr_infolist; } } + if (string_strcasecmp (name, "window") == 0) + { + /* invalid window pointer ? */ + if (pointer && (!gui_window_valid (pointer))) + return NULL; + + ptr_infolist = plugin_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one window */ + if (!plugin_api_infolist_get_add_window (ptr_infolist, pointer)) + { + plugin_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all windows */ + for (ptr_window = gui_windows; ptr_window; + ptr_window = ptr_window->next_window) + { + if (!plugin_api_infolist_get_add_window (ptr_infolist, + ptr_window)) + { + plugin_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } else if (string_strcasecmp (name, "options") == 0) { ptr_infolist = plugin_infolist_new (); |