diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 13 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 12 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 12 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 12 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 12 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 37 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-buffer.cpp | 147 |
8 files changed, 234 insertions, 12 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 1ab59c1a8..88eba477f 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] New features:: * core: allow command `/toggle` to create option before setting the value, if allowed in the section (issue #1837) + * core: add signals "buffer_user_input_xxx" and "buffer_user_closing_xxx" for buffers created with `/buffer add` (issue #1848) * trigger: add regex command "y" to translate chars, set default regex command to "s" (regex replace) (issue #1510) Bug fixes:: diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 046f66724..ae5fce9f7 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -10959,6 +10959,16 @@ List of signals sent by WeeChat and plugins: | Pointer: buffer. | Merged buffer unzoomed. +| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8 +| String: text sent to buffer. +| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). + + If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q" + can not be used any more to close the buffer. + +| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8 +| - +| User buffer is closing (sent only for buffers created with `/buffer add`). + | weechat | [[hook_signal_cursor_start]] cursor_start | 3.2 | - | Start cursor mode. @@ -11198,7 +11208,8 @@ List of signals sent by WeeChat and plugins: |=== [NOTE] -^(1)^ _xxx_ is IRC server name, _yyy_ is IRC command name. +^(1)^ _xxx_ is IRC server name, _yyy_ is IRC command name. + +^(2)^ _xxx_ is buffer name. C example: diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index d1600a3de..442fa49c6 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -11180,6 +11180,18 @@ Liste des signaux envoyés par WeeChat et les extensions : | Pointeur : tampon. | Fin du zoom sur un tampon mélangé. +| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8 +| Chaîne : texte envoyé au tampon. +| Texte envoyé au tampon utilisateur (envoyé seulement sur les tampons créés + avec `/buffer add`). + + Si le code retour d'une fonction de rappel est _WEECHAT_RC_OK_EAT_, alors + la chaîne "q" ne peut plus être utilisée pour fermer le tampon. + +| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8 +| - +| Fermeture du tampon utilisateur en cours (envoyé seulement sur les tampons créés + avec `/buffer add`). + | weechat | [[hook_signal_cursor_start]] cursor_start | 3.2 | - | Début du mode curseur. diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 3d778bc61..e905abbfc 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -11374,6 +11374,18 @@ List of signals sent by WeeChat and plugins: | Merged buffer unzoomed. // TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8 +| String: text sent to buffer. +| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). + + If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q" + can not be used any more to close the buffer. + +// TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8 +| - +| User buffer is closing (sent only for buffers created with `/buffer add`). + +// TRANSLATION MISSING | weechat | [[hook_signal_cursor_start]] cursor_start | 3.2 | - | Start cursor mode. diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 26f86fd89..5ac8b531c 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -11022,6 +11022,18 @@ WeeChat とプラグインが送信するシグナルのリスト: | マージされたバッファをアンズーム // TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8 +| String: text sent to buffer. +| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). + + If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q" + can not be used any more to close the buffer. + +// TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8 +| - +| User buffer is closing (sent only for buffers created with `/buffer add`). + +// TRANSLATION MISSING | weechat | [[hook_signal_cursor_start]] cursor_start | 3.2 | - | Start cursor mode. diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 6c22fc646..c05ba5361 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -10602,6 +10602,18 @@ struct t_hook *weechat_hook_signal (const char *signal, | Показивач: бафер. | Одзумиран је спојени бафер. +// TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_input_xxx]] buffer_user_input_xxx ^(2)^ | 3.8 +| String: text sent to buffer. +| Text sent to a user buffer as input (sent only for buffers created with `/buffer add`). + + If the return code of a callback is _WEECHAT_RC_OK_EAT_, then the string "q" + can not be used any more to close the buffer. + +// TRANSLATION MISSING +| weechat | [[hook_signal_buffer_user_closing_xxx]] buffer_user_closing_xxx ^(2)^ | 3.8 +| - +| User buffer is closing (sent only for buffers created with `/buffer add`). + | weechat | [[hook_signal_cursor_start]] cursor_start | 3.2 | - | Почетак режима померања курсора. diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 4fbe8ee0e..16fab2c71 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -903,10 +903,22 @@ int gui_buffer_user_input_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *input_data) { + char str_signal[1024]; + int rc; + /* make C compiler happy */ (void) pointer; (void) data; + snprintf (str_signal, sizeof (str_signal), + "buffer_user_input_%s", + buffer->name); + rc = hook_signal_send (str_signal, + WEECHAT_HOOK_SIGNAL_STRING, (void *)input_data); + + if (rc == WEECHAT_RC_OK_EAT) + return WEECHAT_RC_OK; + if (string_strcasecmp (input_data, "q") == 0) { gui_buffer_close (buffer); @@ -916,6 +928,29 @@ gui_buffer_user_input_cb (const void *pointer, void *data, } /* + * Close callback for user buffers. + */ + +int +gui_buffer_user_close_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer) +{ + char str_signal[1024]; + + /* make C compiler happy */ + (void) pointer; + (void) data; + + snprintf (str_signal, sizeof (str_signal), + "buffer_user_closing_%s", + buffer->name); + hook_signal_send (str_signal, + WEECHAT_HOOK_SIGNAL_STRING, NULL); + + return WEECHAT_RC_OK; +} + +/* * Creates a new user buffer in current window. * * Returns pointer to new buffer, NULL if error. @@ -944,7 +979,7 @@ gui_buffer_new_user (const char *name, enum t_gui_buffer_type buffer_type) new_buffer = gui_buffer_new_props (NULL, name, properties, &gui_buffer_user_input_cb, NULL, NULL, - NULL, NULL, NULL); + &gui_buffer_user_close_cb, NULL, NULL); if (properties) hashtable_free (properties); diff --git a/tests/unit/gui/test-gui-buffer.cpp b/tests/unit/gui/test-gui-buffer.cpp index 0a040fdbb..ab2d79ff6 100644 --- a/tests/unit/gui/test-gui-buffer.cpp +++ b/tests/unit/gui/test-gui-buffer.cpp @@ -25,17 +25,85 @@ extern "C" { #include <string.h> #include "src/core/wee-hashtable.h" +#include "src/core/wee-hook.h" +#include "src/core/wee-input.h" #include "src/gui/gui-buffer.h" #include "src/gui/gui-key.h" #include "src/gui/gui-line.h" #include "src/gui/gui-nicklist.h" #include "src/plugins/plugin.h" + +extern int gui_buffer_user_input_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int gui_buffer_user_close_cb (const void *pointer, void *data, + struct t_gui_buffer *buffer); } #define TEST_BUFFER_NAME "test" +char signal_buffer_user_input[256]; +int signal_buffer_user_closing = 0; + TEST_GROUP(GuiBuffer) { + static int signal_buffer_user_input_cb (const void *pointer, void *data, + const char *signal, + const char *type_data, + void *signal_data) + { + /* make C++ compiler happy */ + (void) pointer; + (void) data; + (void) signal; + (void) type_data; + + if (signal_data) + { + snprintf (signal_buffer_user_input, + sizeof (signal_buffer_user_input), + "%s", + (const char *)signal_data); + } + return WEECHAT_RC_OK; + } + + static int signal_buffer_user_input_eat_cb (const void *pointer, void *data, + const char *signal, + const char *type_data, + void *signal_data) + { + /* make C++ compiler happy */ + (void) pointer; + (void) data; + (void) signal; + (void) type_data; + + if (signal_data) + { + snprintf (signal_buffer_user_input, + sizeof (signal_buffer_user_input), + "%s", + (const char *)signal_data); + } + return WEECHAT_RC_OK_EAT; + } + + static int signal_buffer_user_closing_cb (const void *pointer, void *data, + const char *signal, + const char *type_data, + void *signal_data) + { + /* make C++ compiler happy */ + (void) pointer; + (void) data; + (void) signal; + (void) type_data; + (void) signal_data; + + signal_buffer_user_closing = 1; + return WEECHAT_RC_OK_EAT; + } }; /* @@ -435,21 +503,80 @@ TEST(GuiBuffer, New) /* * Tests functions: * gui_buffer_user_input_cb - */ - -TEST(GuiBuffer, UserInputCb) -{ - /* TODO: write tests */ -} - -/* - * Tests functions: + * gui_buffer_user_close_cb * gui_buffer_new_user */ TEST(GuiBuffer, NewUser) { - /* TODO: write tests */ + int type; + struct t_gui_buffer *buffer; + struct t_hook *signal_input, *signal_closing; + + for (type = 0; type < GUI_BUFFER_NUM_TYPES; type++) + { + signal_input = hook_signal (NULL, + "buffer_user_input_" TEST_BUFFER_NAME, + &signal_buffer_user_input_cb, NULL, NULL); + signal_closing = hook_signal (NULL, + "buffer_user_closing_" TEST_BUFFER_NAME, + &signal_buffer_user_closing_cb, NULL, NULL); + + /* test creation of user buffer */ + buffer = gui_buffer_new_user (TEST_BUFFER_NAME, + (enum t_gui_buffer_type)type); + CHECK(buffer); + STRCMP_EQUAL(TEST_BUFFER_NAME, buffer->name); + STRCMP_EQUAL("core." TEST_BUFFER_NAME, buffer->full_name); + POINTERS_EQUAL(&gui_buffer_user_input_cb, buffer->input_callback); + POINTERS_EQUAL(&gui_buffer_user_close_cb, buffer->close_callback); + + /* test signal "buffer_user_input_test" */ + signal_buffer_user_input[0] = '\0'; + input_data (buffer, "something", NULL); + STRCMP_EQUAL("something", signal_buffer_user_input); + + /* test signal "buffer_user_closing_test" */ + signal_buffer_user_closing = 0; + gui_buffer_close (buffer); + LONGS_EQUAL(1, signal_buffer_user_closing); + + /* create the buffer again */ + buffer = gui_buffer_new_user (TEST_BUFFER_NAME, + (enum t_gui_buffer_type)type); + + /* close the buffer by sending "q" */ + signal_buffer_user_input[0] = '\0'; + signal_buffer_user_closing = 0; + input_data (buffer, "q", NULL); + STRCMP_EQUAL("q", signal_buffer_user_input); + LONGS_EQUAL(1, signal_buffer_user_closing); + + /* create the buffer again */ + buffer = gui_buffer_new_user (TEST_BUFFER_NAME, + (enum t_gui_buffer_type)type); + + /* hook a signal that eats the input */ + unhook (signal_input); + signal_input = hook_signal (NULL, + "buffer_user_input_" TEST_BUFFER_NAME, + &signal_buffer_user_input_eat_cb, NULL, NULL); + + /* + * try to close the buffer by sending "q": it should not close it + * because the input signal callback as returned WEECHAT_RC_OK_EAT + */ + signal_buffer_user_input[0] = '\0'; + signal_buffer_user_closing = 0; + input_data (buffer, "q", NULL); + STRCMP_EQUAL("q", signal_buffer_user_input); + LONGS_EQUAL(0, signal_buffer_user_closing); + + gui_buffer_close (buffer); + + unhook (signal_input); + unhook (signal_closing); + } } /* |