diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2018-01-07 12:37:04 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2018-01-07 12:37:04 +0100 |
commit | f3de26c0755feaa5810704ad34eb2ea069c139af (patch) | |
tree | e2c2c41f8313dbba96870e10da63e83afb072092 /src/gui | |
parent | d7ca5f04f625474891161e3df34cb90a70a761b3 (diff) | |
download | weechat-f3de26c0755feaa5810704ad34eb2ea069c139af.zip |
core: set input callback on user buffers after /upgrade
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-buffer.c | 90 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 3 |
2 files changed, 93 insertions, 0 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index a2db73974..db80180a4 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -553,6 +553,31 @@ gui_buffer_input_buffer_init (struct t_gui_buffer *buffer) } /* + * Checks if the name is reserved for WeeChat. + * + * Returns: + * 0: name is not reserved for WeeChat + * 1: name is reserved for WeeChat + */ + +int +gui_buffer_is_reserved_name (const char *name) +{ + int i; + + if (!name) + return 0; + + for (i = 0; gui_buffer_reserved_names[i]; i++) + { + if (strcmp (name, gui_buffer_reserved_names[i]) == 0) + break; + } + + return (gui_buffer_reserved_names[i]) ? 1 : 0; +} + +/* * Creates a new buffer in current window. * * Returns pointer to new buffer, NULL if error. @@ -763,6 +788,71 @@ gui_buffer_new (struct t_weechat_plugin *plugin, } /* + * Input callback for user buffers. + */ + +int +gui_buffer_user_input_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer, const char *input_data) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + + if (string_strcasecmp (input_data, "q") == 0) + { + gui_buffer_close (buffer); + } + + return WEECHAT_RC_OK; +} + +/* + * Creates a new user buffer in current window. + * + * Returns pointer to new buffer, NULL if error. + */ + +struct t_gui_buffer * +gui_buffer_new_user (const char *name) +{ + struct t_gui_buffer *new_buffer; + + new_buffer = gui_buffer_new (NULL, name, + &gui_buffer_user_input_cb, NULL, NULL, + NULL, NULL, NULL); + if (new_buffer) + gui_buffer_set (new_buffer, "localvar_set_type", "user"); + + return new_buffer; +} + +/* + * Sets callbacks on user buffers. + */ + +void +gui_buffer_user_set_callbacks () +{ + struct t_gui_buffer *ptr_buffer; + const char *ptr_type; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (!ptr_buffer->plugin + && !gui_buffer_is_reserved_name (ptr_buffer->name)) + { + ptr_type = gui_buffer_get_string (ptr_buffer, "localvar_type"); + if (ptr_type && (strcmp (ptr_type, "user") == 0)) + { + ptr_buffer->input_callback = &gui_buffer_user_input_cb; + } + } + } +} + +/* * Checks if a buffer pointer is valid. * * Returns: diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 99fd2ec90..fa9eb761c 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -249,6 +249,7 @@ extern const char *gui_buffer_get_short_name (struct t_gui_buffer *buffer); extern void gui_buffer_build_full_name (struct t_gui_buffer *buffer); extern void gui_buffer_notify_set_all (); extern void gui_buffer_input_buffer_init (struct t_gui_buffer *buffer); +extern int gui_buffer_is_reserved_name (const char *name); extern struct t_gui_buffer *gui_buffer_new (struct t_weechat_plugin *plugin, const char *name, int (*input_callback)(const void *pointer, @@ -262,6 +263,8 @@ extern struct t_gui_buffer *gui_buffer_new (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer), const void *close_callback_pointer, void *close_callback_data); +extern struct t_gui_buffer *gui_buffer_new_user (const char *name); +extern void gui_buffer_user_set_callbacks (); extern int gui_buffer_valid (struct t_gui_buffer *buffer); extern char *gui_buffer_string_replace_local_var (struct t_gui_buffer *buffer, const char *string); |