summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-05-20 16:46:07 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-05-20 17:08:30 +0200
commitcbde92c44e55da9913d117007f63d69296fc69da (patch)
tree79d275c48969c4c7292d6cad66a3fb44bf47e50c /src
parent00f4ae760d03cd5d1781e940d95b46d707e72585 (diff)
downloadweechat-cbde92c44e55da9913d117007f63d69296fc69da.zip
script: create buffer with function buffer_new_props (issue #1942)
With this function, buffer properties are set when the buffer is created and can be read immediately by other plugins/scripts, for example in a callback of signal "buffer_opened".
Diffstat (limited to 'src')
-rw-r--r--src/plugins/script/script-buffer.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/plugins/script/script-buffer.c b/src/plugins/script/script-buffer.c
index 105a9afce..f05ee1e3a 100644
--- a/src/plugins/script/script-buffer.c
+++ b/src/plugins/script/script-buffer.c
@@ -1144,24 +1144,38 @@ script_buffer_set_localvar_filter ()
void
script_buffer_open ()
{
- if (!script_buffer)
+ struct t_hashtable *buffer_props;
+
+ if (script_buffer)
+ return;
+
+ buffer_props = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (buffer_props)
{
- script_buffer = weechat_buffer_new (
- SCRIPT_BUFFER_NAME,
- &script_buffer_input_cb, NULL, NULL,
- &script_buffer_close_cb, NULL, NULL);
-
- /* failed to create buffer ? then exit */
- if (!script_buffer)
- return;
-
- weechat_buffer_set (script_buffer, "type", "free");
- weechat_buffer_set (script_buffer, "title", _("Scripts"));
- script_buffer_set_keys ();
- weechat_buffer_set (script_buffer, "localvar_set_type", "script");
- script_buffer_set_localvar_filter ();
-
- script_buffer_selected_line = 0;
- script_buffer_detail_script = NULL;
+ weechat_hashtable_set (buffer_props, "type", "free");
+ weechat_hashtable_set (buffer_props, "title", _("Scripts"));
+ weechat_hashtable_set (buffer_props, "localvar_set_type", "script");
}
+
+ script_buffer = weechat_buffer_new_props (
+ SCRIPT_BUFFER_NAME,
+ buffer_props,
+ &script_buffer_input_cb, NULL, NULL,
+ &script_buffer_close_cb, NULL, NULL);
+
+ if (buffer_props)
+ weechat_hashtable_free (buffer_props);
+
+ if (!script_buffer)
+ return;
+
+ script_buffer_set_keys ();
+ script_buffer_set_localvar_filter ();
+
+ script_buffer_selected_line = 0;
+ script_buffer_detail_script = NULL;
}