summaryrefslogtreecommitdiff
path: root/src/plugins/scripts/script-api.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-03-05 16:19:10 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-03-05 16:19:10 +0100
commit14d393b11ebcbc34916213055b45f39d0afa8db2 (patch)
treefa6f3d9f6c1e3435410cec1aec0629861f3b9828 /src/plugins/scripts/script-api.c
parentd64e852a3863ba495cb3638ebe4bf1b89983a7f3 (diff)
downloadweechat-14d393b11ebcbc34916213055b45f39d0afa8db2.zip
Partial support of bars, with custom items.
Today only root bars are partially working (refresh is not always performed), and bars are not saved in configuration file. To be continued...
Diffstat (limited to 'src/plugins/scripts/script-api.c')
-rw-r--r--src/plugins/scripts/script-api.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index e3bc57056..ebb73ba15 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -815,6 +815,71 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
}
/*
+ * script_api_bar_item_new: add a new bar item
+ */
+
+struct t_gui_bar_item *
+script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *name,
+ char *(*build_callback)(void *data,
+ struct t_gui_bar_item *item,
+ struct t_gui_window *window,
+ int remaining_space),
+ char *function_build)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_gui_bar_item *new_item;
+
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return NULL;
+
+ new_item = weechat_bar_item_new (name,
+ (function_build && function_build[0]) ?
+ build_callback : NULL,
+ (function_build && function_build[0]) ?
+ new_script_callback : NULL);
+ if (!new_item)
+ {
+ free (new_script_callback);
+ return NULL;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = (function_build && function_build[0]) ?
+ strdup (function_build) : NULL;
+ new_script_callback->bar_item = new_item;
+ script_callback_add (script, new_script_callback);
+
+ return new_item;
+}
+
+/*
+ * script_api_bar_item_remove: remove a bar item
+ */
+
+void
+script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_bar_item *item)
+{
+ struct t_script_callback *ptr_script_callback;
+
+ if (!weechat_plugin || !script || !item)
+ return;
+
+ weechat_bar_item_remove (item);
+
+ for (ptr_script_callback = script->callbacks; ptr_script_callback;
+ ptr_script_callback = ptr_script_callback->next_callback)
+ {
+ if (ptr_script_callback->bar_item == item)
+ script_callback_remove (script, ptr_script_callback);
+ }
+}
+
+/*
* script_api_command: execute a command (simulate user entry)
*/