mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 08:13:14 +02:00
core: add display conditions in custom bar items (issue #808)
This commit is contained in:
+38
-15
@@ -3395,8 +3395,8 @@ COMMAND_CALLBACK(input)
|
||||
COMMAND_CALLBACK(item)
|
||||
{
|
||||
struct t_gui_bar_item_custom *ptr_bar_item_custom;
|
||||
char str_command[4096], str_pos[16];
|
||||
int i, update;
|
||||
char str_command[4096], str_pos[16], **sargv;
|
||||
int i, update, sargc;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
@@ -3415,9 +3415,19 @@ COMMAND_CALLBACK(item)
|
||||
ptr_bar_item_custom = ptr_bar_item_custom->next_item)
|
||||
{
|
||||
gui_chat_printf (
|
||||
NULL, " %s -> \"%s\"",
|
||||
ptr_bar_item_custom->bar_item->name,
|
||||
CONFIG_STRING(ptr_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
NULL, " %s:", ptr_bar_item_custom->bar_item->name);
|
||||
gui_chat_printf (NULL, _(" conditions: %s\"%s%s%s\"%s"),
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT),
|
||||
CONFIG_STRING(ptr_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]),
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT));
|
||||
gui_chat_printf (NULL, _(" content: %s\"%s%s%s\"%s"),
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT),
|
||||
CONFIG_STRING(ptr_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]),
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -3432,12 +3442,18 @@ COMMAND_CALLBACK(item)
|
||||
if ((string_strcasecmp (argv[1], "add") == 0)
|
||||
|| (string_strcasecmp (argv[1], "addreplace") == 0))
|
||||
{
|
||||
COMMAND_MIN_ARGS(4, argv[1]);
|
||||
sargv = string_split_shell (argv_eol[2], &sargc);
|
||||
if (!sargv || (sargc < 3))
|
||||
{
|
||||
if (sargv)
|
||||
string_free_split (sargv);
|
||||
COMMAND_ERROR;
|
||||
}
|
||||
|
||||
update = 0;
|
||||
if (string_strcasecmp (argv[1], "addreplace") == 0)
|
||||
{
|
||||
ptr_bar_item_custom = gui_bar_item_custom_search (argv[2]);
|
||||
ptr_bar_item_custom = gui_bar_item_custom_search (sargv[0]);
|
||||
if (ptr_bar_item_custom)
|
||||
{
|
||||
gui_bar_item_custom_free (ptr_bar_item_custom);
|
||||
@@ -3445,23 +3461,26 @@ COMMAND_CALLBACK(item)
|
||||
}
|
||||
}
|
||||
|
||||
ptr_bar_item_custom = gui_bar_item_custom_new (argv[2], argv_eol[3]);
|
||||
ptr_bar_item_custom = gui_bar_item_custom_new (sargv[0], sargv[1],
|
||||
sargv[2]);
|
||||
if (ptr_bar_item_custom)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
(update) ?
|
||||
_("Custom bar item \"%s\" updated") :
|
||||
_("Custom bar item \"%s\" added"),
|
||||
argv[2]);
|
||||
sargv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sUnable to add custom bar item \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2]);
|
||||
sargv[0]);
|
||||
}
|
||||
|
||||
string_free_split (sargv);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -3483,8 +3502,9 @@ COMMAND_CALLBACK(item)
|
||||
if (ptr_bar_item_custom)
|
||||
{
|
||||
snprintf (str_command, sizeof (str_command),
|
||||
"/item addreplace %s %s",
|
||||
"/item addreplace %s \"%s\" \"%s\"",
|
||||
ptr_bar_item_custom->bar_item->name,
|
||||
CONFIG_STRING(ptr_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]),
|
||||
CONFIG_STRING(ptr_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
gui_buffer_set (buffer, "input", str_command);
|
||||
snprintf (str_pos, sizeof (str_pos),
|
||||
@@ -8021,7 +8041,7 @@ command_init ()
|
||||
NULL, "item",
|
||||
N_("manage custom bar items"),
|
||||
N_("list"
|
||||
" || add|addreplace <name> <content>"
|
||||
" || add|addreplace <name> \"<conditions>\" \"<content>\""
|
||||
" || rename <name> <new_name>"
|
||||
" || refresh <name> [<name>...]"
|
||||
" || recreate <name>"
|
||||
@@ -8030,6 +8050,8 @@ command_init ()
|
||||
" add: add a custom bar item\n"
|
||||
"addreplace: add or replace an existing custom bar item\n"
|
||||
" name: custom bar item name\n"
|
||||
"conditions: evaluated conditions to display the bar item "
|
||||
"(for example to display the bar item only in specific buffers)\n"
|
||||
" content: content (evaluated, see /help eval)\n"
|
||||
" rename: rename a custom bar item\n"
|
||||
" refresh: update content of item in all bars where the item is "
|
||||
@@ -8041,9 +8063,10 @@ command_init ()
|
||||
" -all: delete all custom bar items\n"
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
" /item add terminfo term:${info:term_width}x${info:term_height}\n"
|
||||
" /item add bufinfo ${buffer.number}:${buffer.name}"
|
||||
"${if:${buffer.zoomed}?(Z)}"),
|
||||
" /item add terminfo \"${buffer.number} == 1\" "
|
||||
"\"term:${info:term_width}x${info:term_height}\"\n"
|
||||
" /item add bufinfo \"\" \"${buffer.number}:${buffer.name}"
|
||||
"${if:${buffer.zoomed}?(Z)}\""),
|
||||
"list"
|
||||
" || add %(custom_bar_items_names)"
|
||||
" || addreplace %(custom_bar_items_names) %(custom_bar_item_content)"
|
||||
|
||||
@@ -1939,10 +1939,10 @@ config_weechat_bar_read_cb (const void *pointer, void *data,
|
||||
*/
|
||||
|
||||
int
|
||||
config_weechat_bar_item_read_cb (const void *pointer, void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
const char *option_name, const char *value)
|
||||
config_weechat_custom_bar_item_read_cb (const void *pointer, void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
const char *option_name, const char *value)
|
||||
{
|
||||
char *pos_option, *item_name;
|
||||
struct t_gui_bar_item_custom *ptr_temp_item;
|
||||
@@ -1997,7 +1997,7 @@ config_weechat_bar_item_read_cb (const void *pointer, void *data,
|
||||
if (index_option >= 0)
|
||||
{
|
||||
gui_bar_item_custom_create_option_temp (ptr_temp_item, index_option,
|
||||
value);
|
||||
value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4746,7 +4746,7 @@ config_weechat_init_options ()
|
||||
ptr_section = config_file_new_section (
|
||||
weechat_config_file, "custom_bar_item",
|
||||
0, 0,
|
||||
&config_weechat_bar_item_read_cb, NULL, NULL,
|
||||
&config_weechat_custom_bar_item_read_cb, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
|
||||
@@ -39,7 +39,10 @@
|
||||
|
||||
|
||||
char *gui_bar_item_custom_option_string[GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS] =
|
||||
{ "content" };
|
||||
{ "conditions", "content" };
|
||||
char *gui_bar_item_custom_option_default[GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS] =
|
||||
{ "", "" };
|
||||
|
||||
|
||||
struct t_gui_bar_item_custom *gui_custom_bar_items = NULL;
|
||||
struct t_gui_bar_item_custom *last_gui_custom_bar_item = NULL;
|
||||
@@ -49,7 +52,6 @@ struct t_gui_bar_item_custom *gui_temp_custom_bar_items = NULL;
|
||||
struct t_gui_bar_item_custom *last_gui_temp_custom_bar_item = NULL;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Checks if a custom bar item name is valid: it must not have any
|
||||
* space/period.
|
||||
@@ -163,12 +165,12 @@ gui_bar_item_custom_search_with_option_name (const char *option_name)
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback called when option "content" is changed.
|
||||
* Callback called when option "conditions" or "content" is changed.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_item_custom_config_change_content (const void *pointer, void *data,
|
||||
struct t_config_option *option)
|
||||
gui_bar_item_custom_config_change (const void *pointer, void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_bar_item_custom *ptr_item;
|
||||
|
||||
@@ -208,6 +210,17 @@ gui_bar_item_custom_create_option (const char *item_name, int index_option,
|
||||
|
||||
switch (index_option)
|
||||
{
|
||||
case GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_custom_bar_item,
|
||||
option_name, "string",
|
||||
N_("condition(s) to display the bar item "
|
||||
"(evaluated, see /help eval)"),
|
||||
NULL, 0, 0, value, NULL, 0,
|
||||
NULL, NULL, NULL,
|
||||
&gui_bar_item_custom_config_change, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT:
|
||||
ptr_option = config_file_new_option (
|
||||
weechat_config_file, weechat_config_section_custom_bar_item,
|
||||
@@ -215,7 +228,7 @@ gui_bar_item_custom_create_option (const char *item_name, int index_option,
|
||||
N_("content of bar item (evaluated, see /help eval)"),
|
||||
NULL, 0, 0, value, NULL, 0,
|
||||
NULL, NULL, NULL,
|
||||
&gui_bar_item_custom_config_change_content, NULL, NULL,
|
||||
&gui_bar_item_custom_config_change, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
break;
|
||||
case GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS:
|
||||
@@ -263,14 +276,18 @@ gui_bar_item_custom_callback (const void *pointer,
|
||||
struct t_hashtable *extra_info)
|
||||
{
|
||||
struct t_gui_bar_item_custom *ptr_item;
|
||||
struct t_hashtable *pointers;
|
||||
struct t_hashtable *pointers, *options;
|
||||
const char *ptr_conditions;
|
||||
char *result;
|
||||
int rc;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) item;
|
||||
(void) extra_info;
|
||||
|
||||
result = NULL;
|
||||
|
||||
ptr_item = (struct t_gui_bar_item_custom *)pointer;
|
||||
if (!ptr_item)
|
||||
return NULL;
|
||||
@@ -286,12 +303,41 @@ gui_bar_item_custom_callback (const void *pointer,
|
||||
hashtable_set (pointers, "buffer", buffer);
|
||||
}
|
||||
|
||||
options = hashtable_new (32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (options)
|
||||
hashtable_set (options, "type", "condition");
|
||||
|
||||
/* check conditions */
|
||||
ptr_conditions = CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]);
|
||||
if (ptr_conditions && ptr_conditions[0])
|
||||
{
|
||||
result = eval_expression (
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]),
|
||||
pointers, NULL, options);
|
||||
rc = eval_is_true (result);
|
||||
if (result)
|
||||
{
|
||||
free (result);
|
||||
result = NULL;
|
||||
}
|
||||
if (!rc)
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* evaluate content */
|
||||
result = eval_expression (
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]),
|
||||
pointers, NULL, NULL);
|
||||
|
||||
end:
|
||||
if (pointers)
|
||||
hashtable_free (pointers);
|
||||
if (options)
|
||||
hashtable_free (options);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -349,6 +395,7 @@ gui_bar_item_custom_create_bar_item (struct t_gui_bar_item_custom *item)
|
||||
|
||||
struct t_gui_bar_item_custom *
|
||||
gui_bar_item_custom_new_with_options (const char *name,
|
||||
struct t_config_option *conditions,
|
||||
struct t_config_option *content)
|
||||
{
|
||||
struct t_gui_bar_item_custom *new_bar_item_custom;
|
||||
@@ -358,6 +405,7 @@ gui_bar_item_custom_new_with_options (const char *name,
|
||||
if (!new_bar_item_custom)
|
||||
return NULL;
|
||||
|
||||
new_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS] = conditions;
|
||||
new_bar_item_custom->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT] = content;
|
||||
new_bar_item_custom->bar_item = NULL;
|
||||
|
||||
@@ -380,9 +428,10 @@ gui_bar_item_custom_new_with_options (const char *name,
|
||||
*/
|
||||
|
||||
struct t_gui_bar_item_custom *
|
||||
gui_bar_item_custom_new (const char *name, const char *content)
|
||||
gui_bar_item_custom_new (const char *name, const char *conditions,
|
||||
const char *content)
|
||||
{
|
||||
struct t_config_option *option_content;
|
||||
struct t_config_option *option_conditions, *option_content;
|
||||
struct t_gui_bar_item_custom *new_bar_item_custom;
|
||||
|
||||
if (!gui_bar_item_custom_name_valid (name))
|
||||
@@ -391,13 +440,19 @@ gui_bar_item_custom_new (const char *name, const char *content)
|
||||
if (gui_bar_item_custom_search (name))
|
||||
return NULL;
|
||||
|
||||
option_conditions = gui_bar_item_custom_create_option (
|
||||
name,
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS,
|
||||
conditions);
|
||||
option_content = gui_bar_item_custom_create_option (
|
||||
name,
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT,
|
||||
content);
|
||||
|
||||
new_bar_item_custom = gui_bar_item_custom_new_with_options (name,
|
||||
option_content);
|
||||
new_bar_item_custom = gui_bar_item_custom_new_with_options (
|
||||
name,
|
||||
option_conditions,
|
||||
option_content);
|
||||
if (new_bar_item_custom)
|
||||
{
|
||||
gui_bar_item_custom_create_bar_item (new_bar_item_custom);
|
||||
@@ -405,6 +460,8 @@ gui_bar_item_custom_new (const char *name, const char *content)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option_conditions)
|
||||
config_file_option_free (option_conditions, 0);
|
||||
if (option_content)
|
||||
config_file_option_free (option_content, 0);
|
||||
}
|
||||
@@ -420,10 +477,21 @@ void
|
||||
gui_bar_item_custom_use_temp_items ()
|
||||
{
|
||||
struct t_gui_bar_item_custom *ptr_temp_item;
|
||||
int i;
|
||||
|
||||
for (ptr_temp_item = gui_temp_custom_bar_items; ptr_temp_item;
|
||||
ptr_temp_item = ptr_temp_item->next_item)
|
||||
{
|
||||
for (i = 0; i < GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS; i++)
|
||||
{
|
||||
if (!ptr_temp_item->options[i])
|
||||
{
|
||||
ptr_temp_item->options[i] = gui_bar_item_custom_create_option (
|
||||
ptr_temp_item->name,
|
||||
i,
|
||||
gui_bar_item_custom_option_default[i]);
|
||||
}
|
||||
}
|
||||
gui_bar_item_custom_create_bar_item (ptr_temp_item);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ struct t_weechat_plugin;
|
||||
|
||||
enum t_gui_bar_item_custom_option
|
||||
{
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT = 0, /* item content */
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS = 0, /* condition(s) to display */
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT, /* item content */
|
||||
/* number of bar options */
|
||||
GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS,
|
||||
};
|
||||
@@ -60,6 +61,7 @@ extern void gui_bar_item_custom_create_option_temp (struct t_gui_bar_item_custom
|
||||
const char *value);
|
||||
extern struct t_gui_bar_item_custom *gui_bar_item_custom_alloc (const char *name);
|
||||
extern struct t_gui_bar_item_custom *gui_bar_item_custom_new (const char *name,
|
||||
const char *conditions,
|
||||
const char *content);
|
||||
extern void gui_bar_item_custom_use_temp_items ();
|
||||
extern int gui_bar_item_custom_rename (struct t_gui_bar_item_custom *item,
|
||||
|
||||
@@ -82,7 +82,8 @@ TEST(GuiBarItemCustom, SearchOption)
|
||||
LONGS_EQUAL(-1, gui_bar_item_custom_search_option (""));
|
||||
LONGS_EQUAL(-1, gui_bar_item_custom_search_option ("zzz"));
|
||||
|
||||
LONGS_EQUAL(0, gui_bar_item_custom_search_option ("content"));
|
||||
LONGS_EQUAL(0, gui_bar_item_custom_search_option ("conditions"));
|
||||
LONGS_EQUAL(1, gui_bar_item_custom_search_option ("content"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -94,10 +95,12 @@ TEST(GuiBarItemCustom, Search)
|
||||
{
|
||||
struct t_gui_bar_item_custom *new_item, *new_item2, *ptr_item;
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
CHECK(new_item);
|
||||
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
CHECK(new_item2);
|
||||
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search (NULL));
|
||||
@@ -107,6 +110,8 @@ TEST(GuiBarItemCustom, Search)
|
||||
ptr_item = gui_bar_item_custom_search ("test");
|
||||
POINTERS_EQUAL(new_item, ptr_item);
|
||||
STRCMP_EQUAL("test", ptr_item->name);
|
||||
STRCMP_EQUAL("${buffer.number} == 1",
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
STRCMP_EQUAL("some content",
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
CHECK(ptr_item->bar_item);
|
||||
@@ -119,6 +124,8 @@ TEST(GuiBarItemCustom, Search)
|
||||
ptr_item = gui_bar_item_custom_search ("test2");
|
||||
POINTERS_EQUAL(new_item2, ptr_item);
|
||||
STRCMP_EQUAL("test2", ptr_item->name);
|
||||
STRCMP_EQUAL("${buffer.number} == 2",
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
STRCMP_EQUAL("some content 2",
|
||||
CONFIG_STRING(ptr_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
CHECK(ptr_item->bar_item);
|
||||
@@ -141,19 +148,25 @@ TEST(GuiBarItemCustom, SearchWithOptionName)
|
||||
{
|
||||
struct t_gui_bar_item_custom *new_item, *new_item2;
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
CHECK(new_item);
|
||||
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
CHECK(new_item2);
|
||||
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name (NULL));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name (""));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name ("test"));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name ("test2"));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name ("conditions"));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_search_with_option_name ("content"));
|
||||
|
||||
POINTERS_EQUAL(new_item, gui_bar_item_custom_search_with_option_name ("test.conditions"));
|
||||
POINTERS_EQUAL(new_item, gui_bar_item_custom_search_with_option_name ("test.content"));
|
||||
|
||||
POINTERS_EQUAL(new_item2, gui_bar_item_custom_search_with_option_name ("test2.conditions"));
|
||||
POINTERS_EQUAL(new_item2, gui_bar_item_custom_search_with_option_name ("test2.content"));
|
||||
|
||||
gui_bar_item_custom_free (new_item);
|
||||
@@ -162,21 +175,28 @@ TEST(GuiBarItemCustom, SearchWithOptionName)
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* gui_bar_item_custom_config_change_content
|
||||
* gui_bar_item_custom_config_change
|
||||
*/
|
||||
|
||||
TEST(GuiBarItemCustom, ConfigChangeContent)
|
||||
TEST(GuiBarItemCustom, ConfigChange)
|
||||
{
|
||||
struct t_gui_bar_item_custom *new_item;
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
CHECK(new_item);
|
||||
STRCMP_EQUAL("${buffer.number} == 1",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
STRCMP_EQUAL("some content",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
|
||||
config_file_option_set (new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS],
|
||||
"${buffer.number} == 2", 1);
|
||||
STRCMP_EQUAL("${buffer.number} == 2",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
|
||||
config_file_option_set (new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT],
|
||||
"new content", 1);
|
||||
|
||||
STRCMP_EQUAL("new content",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
|
||||
@@ -198,12 +218,18 @@ TEST(GuiBarItemCustom, CreateOptionTemp)
|
||||
new_item = gui_bar_item_custom_alloc ("test");
|
||||
CHECK(new_item);
|
||||
|
||||
POINTERS_EQUAL(NULL, new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]);
|
||||
POINTERS_EQUAL(NULL, new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]);
|
||||
|
||||
gui_bar_item_custom_create_option_temp (new_item,
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS,
|
||||
"${buffer.number} == 1");
|
||||
STRCMP_EQUAL("${buffer.number} == 1",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
|
||||
gui_bar_item_custom_create_option_temp (new_item,
|
||||
GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT,
|
||||
"some content");
|
||||
|
||||
STRCMP_EQUAL("some content",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
|
||||
@@ -222,6 +248,7 @@ TEST(GuiBarItemCustom, Callback)
|
||||
|
||||
new_item = gui_bar_item_custom_new (
|
||||
"test",
|
||||
"${buffer.number} == 1",
|
||||
"${buffer.number} >> ${buffer.full_name}");
|
||||
CHECK(new_item);
|
||||
|
||||
@@ -236,6 +263,15 @@ TEST(GuiBarItemCustom, Callback)
|
||||
STRCMP_EQUAL("1 >> core.weechat", content);
|
||||
free (content);
|
||||
|
||||
/* change conditions so that it becomes false on first buffer */
|
||||
config_file_option_set (new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS],
|
||||
"${buffer.number} == 2", 1);
|
||||
POINTERS_EQUAL(NULL,
|
||||
gui_bar_item_custom_callback (new_item, NULL,
|
||||
new_item->bar_item,
|
||||
gui_windows, gui_buffers,
|
||||
NULL));
|
||||
|
||||
gui_bar_item_custom_free (new_item);
|
||||
}
|
||||
|
||||
@@ -290,12 +326,18 @@ TEST(GuiBarItemCustom, New)
|
||||
|
||||
/* invalid name: contains a space */
|
||||
POINTERS_EQUAL(NULL,
|
||||
gui_bar_item_custom_new ("test item", "some content"));
|
||||
gui_bar_item_custom_new ("test item",
|
||||
"${buffer.number} == 1",
|
||||
"some content"));
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
CHECK(new_item);
|
||||
|
||||
STRCMP_EQUAL("test", new_item->name);
|
||||
STRCMP_EQUAL(
|
||||
"${buffer.number} == 1",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
STRCMP_EQUAL(
|
||||
"some content",
|
||||
CONFIG_STRING(new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
@@ -310,16 +352,22 @@ TEST(GuiBarItemCustom, New)
|
||||
POINTERS_EQUAL(NULL, new_item->next_item);
|
||||
|
||||
/* invalid name: already exists */
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_new ("test", "some content"));
|
||||
POINTERS_EQUAL(NULL, gui_bar_item_custom_new ("test",
|
||||
"${buffer.number} == 1",
|
||||
"some content"));
|
||||
|
||||
/* add another item */
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
CHECK(new_item2);
|
||||
|
||||
POINTERS_EQUAL(NULL, new_item->prev_item);
|
||||
POINTERS_EQUAL(new_item2, new_item->next_item);
|
||||
|
||||
STRCMP_EQUAL("test2", new_item2->name);
|
||||
STRCMP_EQUAL(
|
||||
"${buffer.number} == 2",
|
||||
CONFIG_STRING(new_item2->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]));
|
||||
STRCMP_EQUAL(
|
||||
"some content 2",
|
||||
CONFIG_STRING(new_item2->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]));
|
||||
@@ -379,8 +427,10 @@ TEST(GuiBarItemCustom, Rename)
|
||||
{
|
||||
struct t_gui_bar_item_custom *new_item, *new_item2;
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
|
||||
CHECK(new_item);
|
||||
STRCMP_EQUAL("test", new_item->name);
|
||||
@@ -424,11 +474,13 @@ TEST(GuiBarItemCustom, Free)
|
||||
|
||||
gui_bar_item_custom_free (NULL);
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
POINTERS_EQUAL(new_item, gui_custom_bar_items);
|
||||
POINTERS_EQUAL(new_item, last_gui_custom_bar_item);
|
||||
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
POINTERS_EQUAL(new_item, gui_custom_bar_items);
|
||||
POINTERS_EQUAL(new_item2, last_gui_custom_bar_item);
|
||||
|
||||
@@ -440,8 +492,10 @@ TEST(GuiBarItemCustom, Free)
|
||||
POINTERS_EQUAL(NULL, gui_custom_bar_items);
|
||||
POINTERS_EQUAL(NULL, last_gui_custom_bar_item);
|
||||
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
POINTERS_EQUAL(new_item, gui_custom_bar_items);
|
||||
POINTERS_EQUAL(new_item2, last_gui_custom_bar_item);
|
||||
|
||||
@@ -450,8 +504,10 @@ TEST(GuiBarItemCustom, Free)
|
||||
POINTERS_EQUAL(NULL, last_gui_custom_bar_item);
|
||||
|
||||
/* remove items in reverse order */
|
||||
new_item = gui_bar_item_custom_new ("test", "some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "some content 2");
|
||||
new_item = gui_bar_item_custom_new ("test", "${buffer.number} == 1",
|
||||
"some content");
|
||||
new_item2 = gui_bar_item_custom_new ("test2", "${buffer.number} == 2",
|
||||
"some content 2");
|
||||
gui_bar_item_custom_free (new_item2);
|
||||
gui_bar_item_custom_free (new_item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user