Skip to content

Commit

Permalink
core: add buffer property "modes"
Browse files Browse the repository at this point in the history
  • Loading branch information
flashcode committed May 12, 2024
1 parent e57777a commit e7b2d98
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For a list of important changes that require manual actions, please look at rele

New features::

* core: add buffer property "input_prompt"
* core: add buffer properties "input_prompt" and "modes"
* core: send signal "buffer_line_added" on buffers with free content
* core: add support of XDG "state" directory (issue #2106, issue #1747)
* core: use nick offline color for nick in action message
Expand Down
8 changes: 8 additions & 0 deletions doc/en/weechat_plugin_api.en.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12146,6 +12146,10 @@ List of signals sent by WeeChat and plugins:
| Pointer: buffer.
| Title of buffer changed.

| weechat | [[hook_signal_buffer_modes_changed]] buffer_modes_changed | 4.3.0
| Pointer: buffer.
| Modes of buffer changed.

| weechat | [[hook_signal_buffer_type_changed]] buffer_type_changed |
| Pointer: buffer.
| Type of buffer changed.
Expand Down Expand Up @@ -14707,6 +14711,7 @@ Arguments:
** _short_name_: short name of buffer (note: used for display only and can be changed by user, this must not be used to find name of buffer, use instead _name_, _full_name_ or local variable _channel_)
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: title of buffer
** _modes_: modes _(WeeChat ≥ 4.3.0)_
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
** _input_prompt_: input prompt _(WeeChat ≥ 4.3.0)_
** _input_: input text
Expand Down Expand Up @@ -14883,6 +14888,9 @@ Properties:
| title | | any string
| Set new title for buffer.

| modes | 4.3.0 | any string
| Set new modes for buffer.

| time_for_each_line | | "0" or "1"
| "0" to hide time for all lines in buffer, "1" to see time for all lines
(default for a new buffer).
Expand Down
8 changes: 8 additions & 0 deletions doc/fr/weechat_plugin_api.fr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12397,6 +12397,10 @@ Liste des signaux envoyés par WeeChat et les extensions :
| Pointeur : tampon.
| Titre du tampon changé.

| weechat | [[hook_signal_buffer_modes_changed]] buffer_modes_changed | 4.3.0
| Pointeur : tampon.
| Modes du tampon changés.

| weechat | [[hook_signal_buffer_type_changed]] buffer_type_changed |
| Pointeur : tampon.
| Type de tampon changé.
Expand Down Expand Up @@ -15024,6 +15028,7 @@ Paramètres :
** _short_name_ : nom court du tampon (note : utilisé pour l'affichage seulement et peut être changé par l'utilisateur, il ne doit pas être utilisé pour trouver le nom du tampon, utilisez à la place _name_, _full_name_ ou bien la variable locale _channel_)
** _type_ : type de tampon : "formatted" (formaté) ou "free" (contenu libre) _(WeeChat ≥ 4.2.0)_
** _title_ : titre du tampon
** _modes_ : modes _(WeeChat ≥ 4.3.0)_
** _nicklist_last_id_assigned_ : dernier identifiant unique utilisé dans ce tampon pour un groupe ou un pseudo _(WeeChat ≥ 4.3.0)_
** _input_prompt_ : invite de la zone saisie _(WeeChat ≥ 4.3.0)_
** _input_ : texte saisi
Expand Down Expand Up @@ -15204,6 +15209,9 @@ Propriétés :
| title | | toute chaîne
| Change le titre du tampon.

| modes | 4.3.0 | toue chaîne
| Change les modes du tampon.

| time_for_each_line | | "0" ou "1"
| "0" pour cacher l'heure sur toutes les lignes du tampon, "1" pour afficher
l'heure sur toutes les lignes (par défaut pour un nouveau tampon).
Expand Down
11 changes: 11 additions & 0 deletions doc/it/weechat_plugin_api.it.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12647,6 +12647,11 @@ List of signals sent by WeeChat and plugins:
| Puntatore: buffer.
| Titolo del buffer modificato.

// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_modes_changed]] buffer_modes_changed | 4.3.0
| Pointer: buffer.
| Modes of buffer changed.

| weechat | [[hook_signal_buffer_type_changed]] buffer_type_changed |
| Puntatore: buffer.
| Tipo di buffer modificato.
Expand Down Expand Up @@ -15408,6 +15413,8 @@ Argomenti:
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: titolo del buffer
// TRANSLATION MISSING
** _modes_: modes _(WeeChat ≥ 4.3.0)_
// TRANSLATION MISSING
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
// TRANSLATION MISSING
** _input_prompt_: input prompt _(WeeChat ≥ 4.3.0)_
Expand Down Expand Up @@ -15608,6 +15615,10 @@ Properties:
| title | | qualsiasi stringa
| Imposta nuovo titolo per il buffer.

// TRANSLATION MISSING
| modes | 4.3.0 | any string
| Set new modes for buffer.

| time_for_each_line | | "0" oppure "1"
| "0" per nascondere l'orario in tutte le righe del buffer, "1" per
visualizzarlo su tutte le righe (predefinito per un nuovo buffer).
Expand Down
11 changes: 11 additions & 0 deletions doc/ja/weechat_plugin_api.ja.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12308,6 +12308,11 @@ WeeChat とプラグインが送信するシグナルのリスト:
| Pointer: バッファ
| バッファのタイトルを変更

// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_modes_changed]] buffer_modes_changed | 4.3.0
| Pointer: buffer.
| Modes of buffer changed.

| weechat | [[hook_signal_buffer_type_changed]] buffer_type_changed |
| Pointer: バッファ
| バッファのタイプを変更
Expand Down Expand Up @@ -14943,6 +14948,8 @@ const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: バッファのタイトル
// TRANSLATION MISSING
** _modes_: modes _(WeeChat ≥ 4.3.0)_
// TRANSLATION MISSING
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
// TRANSLATION MISSING
** _input_prompt_: input prompt _(WeeChat ≥ 4.3.0)_
Expand Down Expand Up @@ -15126,6 +15133,10 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
| title | | 任意の文字列
| 指定したバッファの新しいタイトルを設定

// TRANSLATION MISSING
| modes | 4.3.0 | any string
| Set new modes for buffer.

| time_for_each_line | | "0" または "1"
| バッファのすべての行に時間を表示しない場合は "0"、表示する場合は
"1" (新規バッファに対するデフォルト)
Expand Down
11 changes: 11 additions & 0 deletions doc/sr/weechat_plugin_api.sr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11821,6 +11821,11 @@ struct t_hook *weechat_hook_signal (const char *signal,
| Показивач: бафер.
| Промењен је наслов бафера.

// TRANSLATION MISSING
| weechat | [[hook_signal_buffer_modes_changed]] buffer_modes_changed | 4.3.0
| Pointer: buffer.
| Modes of buffer changed.

| weechat | [[hook_signal_buffer_type_changed]] buffer_type_changed |
| Показивач: бафер.
| Промењен је тип бафера.
Expand Down Expand Up @@ -14285,6 +14290,8 @@ const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
** _short_name_: кратко име бафера (напомена: користи се само за приказ и корисник може да га промени, ово не сме да се употребљава за проналажење имена бафера, уместо њега употребите _name_, _full_name_ или локалну променљиву _channel_)
** _type_: тип бафера: „formatted” или „free” _(WeeChat ≥ 4.2.0)_
** _title_: наслов бафера
// TRANSLATION MISSING
** _modes_: modes _(WeeChat ≥ 4.3.0)_
** _nicklist_last_id_assigned_: последњи јединствени идентификатор употребљен у овом баферу за групу или надимак _(WeeChat ≥ 4.3.0)_
// TRANSLATION MISSING
** _input_prompt_: input prompt _(WeeChat ≥ 4.3.0)_
Expand Down Expand Up @@ -14462,6 +14469,10 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
| title | | било који стринг
| Поставља нови наслов бафера.

// TRANSLATION MISSING
| modes | 4.3.0 | any string
| Set new modes for buffer.

| time_for_each_line | | "0" или "1"
| "0" да се скрива време у свим линијама бафера, "1" да се приказује у свим
линијама (подразумевано за нови бафер).
Expand Down
3 changes: 3 additions & 0 deletions src/core/core-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ upgrade_weechat_read_buffer (struct t_infolist *infolist)
ptr_buffer->title = (str) ? strdup (str) : NULL;
}

/* modes */
gui_buffer_set_modes (ptr_buffer, infolist_string (infolist, "modes"));

/* first line not read */
ptr_buffer->lines->first_line_not_read =
infolist_integer (infolist, "first_line_not_read");
Expand Down
8 changes: 5 additions & 3 deletions src/gui/gui-bar-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,10 +1301,12 @@ gui_bar_item_buffer_modes_cb (const void *pointer, void *data,
(void) data;
(void) item;
(void) window;
(void) buffer;
(void) extra_info;

return NULL;
if (!buffer)
return NULL;

return (buffer->modes) ? strdup (buffer->modes) : NULL;
}

/*
Expand Down Expand Up @@ -2387,7 +2389,7 @@ gui_bar_item_init ()
gui_bar_item_new (NULL,
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES],
&gui_bar_item_buffer_modes_cb, NULL, NULL);
gui_bar_item_hook_signal ("window_switch;buffer_switch",
gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_modes_changed",
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES]);

/* buffer filter */
Expand Down
41 changes: 37 additions & 4 deletions src/gui/gui-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ char *gui_buffer_properties_get_integer[] =
};
char *gui_buffer_properties_get_string[] =
{ "id", "plugin", "name", "full_name", "old_full_name", "short_name", "title",
"nicklist_last_id_assigned", "input_prompt", "input", "text_search_input",
"highlight_words", "highlight_disable_regex", "highlight_regex",
"highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks",
"modes", "nicklist_last_id_assigned", "input_prompt", "input",
"text_search_input", "highlight_words", "highlight_disable_regex",
"highlight_regex", "highlight_tags_restrict", "highlight_tags",
"hotlist_max_level_nicks",
NULL
};
char *gui_buffer_properties_get_pointer[] =
Expand All @@ -123,7 +124,7 @@ char *gui_buffer_properties_get_pointer[] =
char *gui_buffer_properties_set[] =
{ "hotlist", "unread", "display", "hidden", "print_hooks_enabled", "day_change",
"clear", "filter", "number", "name", "short_name", "type", "notify", "title",
"time_for_each_line", "nicklist", "nicklist_case_sensitive",
"modes", "time_for_each_line", "nicklist", "nicklist_case_sensitive",
"nicklist_display_groups", "highlight_words", "highlight_words_add",
"highlight_words_del", "highlight_disable_regex", "highlight_regex",
"highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks",
Expand Down Expand Up @@ -867,6 +868,9 @@ gui_buffer_new_props_with_id (long long id,
/* title */
new_buffer->title = NULL;

/* modes */
new_buffer->modes = NULL;

/* chat content */
new_buffer->own_lines = gui_line_lines_alloc ();
new_buffer->mixed_lines = NULL;
Expand Down Expand Up @@ -1538,6 +1542,8 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property)
return gui_buffer_type_string[buffer->type];
else if (strcmp (property, "title") == 0)
return buffer->title;
else if (strcmp (property, "modes") == 0)
return buffer->modes;
else if (strcmp (property, "nicklist_last_id_assigned") == 0)
{
snprintf (str_value, sizeof (str_value),
Expand Down Expand Up @@ -1793,6 +1799,24 @@ gui_buffer_set_title (struct t_gui_buffer *buffer, const char *new_title)
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}

/*
* Sets modes for a buffer.
*/

void
gui_buffer_set_modes (struct t_gui_buffer *buffer, const char *modes)
{
if (!buffer || (string_strcmp (buffer->modes, modes) == 0))
return;

free (buffer->modes);
buffer->modes = (modes && modes[0]) ? strdup (modes) : NULL;

(void) gui_buffer_send_signal (buffer,
"buffer_modes_changed",
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
}

/*
* Sets flag "time for each line" for a buffer.
*/
Expand Down Expand Up @@ -2650,6 +2674,10 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
{
gui_buffer_set_title (buffer, value);
}
else if (strcmp (property, "modes") == 0)
{
gui_buffer_set_modes (buffer, value);
}
else if (strcmp (property, "time_for_each_line") == 0)
{
error = NULL;
Expand Down Expand Up @@ -3777,6 +3805,7 @@ gui_buffer_close (struct t_gui_buffer *buffer)
free (buffer->old_full_name);
free (buffer->short_name);
free (buffer->title);
free (buffer->modes);
free (buffer->input_prompt);
free (buffer->input_buffer);
free (buffer->input_undo_snap);
Expand Down Expand Up @@ -5202,6 +5231,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data,
HDATA_VAR(struct t_gui_buffer, close_callback_data, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, closing, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, title, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, modes, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, own_lines, POINTER, 0, NULL, "lines");
HDATA_VAR(struct t_gui_buffer, mixed_lines, POINTER, 0, NULL, "lines");
HDATA_VAR(struct t_gui_buffer, lines, POINTER, 0, NULL, "lines");
Expand Down Expand Up @@ -5445,6 +5475,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_string (ptr_item, "title", buffer->title))
return 0;
if (!infolist_new_var_string (ptr_item, "modes", buffer->modes))
return 0;
if (!infolist_new_var_integer (ptr_item, "input", buffer->input))
return 0;
if (!infolist_new_var_integer (ptr_item, "input_get_any_user_data", buffer->input_get_any_user_data))
Expand Down Expand Up @@ -5659,6 +5691,7 @@ gui_buffer_print_log ()
log_printf (" close_callback_data . . : %p", ptr_buffer->close_callback_data);
log_printf (" closing . . . . . . . . : %d", ptr_buffer->closing);
log_printf (" title . . . . . . . . . : '%s'", ptr_buffer->title);
log_printf (" modes . . . . . . . . . : '%s'", ptr_buffer->modes);
log_printf (" own_lines . . . . . . . : %p", ptr_buffer->own_lines);
gui_lines_print_log (ptr_buffer->own_lines);
log_printf (" mixed_lines . . . . . . : %p", ptr_buffer->mixed_lines);
Expand Down
5 changes: 5 additions & 0 deletions src/gui/gui-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ struct t_gui_buffer
/* buffer title */
char *title; /* buffer title */

/* buffer modes */
char *modes; /* buffer modes */

/* chat content */
struct t_gui_lines *own_lines; /* lines (for this buffer only) */
struct t_gui_lines *mixed_lines; /* mixed lines (if buffers merged) */
Expand Down Expand Up @@ -373,6 +376,8 @@ extern void gui_buffer_ask_chat_refresh (struct t_gui_buffer *buffer,
int refresh);
extern void gui_buffer_set_title (struct t_gui_buffer *buffer,
const char *new_title);
extern void gui_buffer_set_modes (struct t_gui_buffer *buffer,
const char *new_modes);
extern void gui_buffer_set_highlight_words (struct t_gui_buffer *buffer,
const char *new_highlight_words);
extern void gui_buffer_set_highlight_disable_regex (struct t_gui_buffer *buffer,
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/gui/test-gui-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ TEST(GuiBuffer, NewProps)
POINTERS_EQUAL(NULL, buffer->close_callback_data);
LONGS_EQUAL(0, buffer->closing);
POINTERS_EQUAL(NULL, buffer->title);
POINTERS_EQUAL(NULL, buffer->modes);
CHECK(buffer->own_lines);
POINTERS_EQUAL(NULL, buffer->own_lines->first_line);
POINTERS_EQUAL(NULL, buffer->own_lines->last_line);
Expand Down Expand Up @@ -639,6 +640,7 @@ TEST(GuiBuffer, NewProps)
gui_buffer_close (buffer);

hashtable_set (properties, "title", "the buffer title");
hashtable_set (properties, "modes", "+nt");
hashtable_set (properties, "short_name", "the_short_name");
hashtable_set (properties, "localvar_set_test", "value");
hashtable_set (properties, "key_bind_meta-y", "/test_y arg1 arg2");
Expand All @@ -647,6 +649,7 @@ TEST(GuiBuffer, NewProps)
&test_buffer_input_cb, NULL, NULL,
&test_buffer_close_cb, NULL, NULL);
STRCMP_EQUAL("the buffer title", buffer->title);
STRCMP_EQUAL("+nt", buffer->modes);
STRCMP_EQUAL("the_short_name", buffer->short_name);
LONGS_EQUAL(3, buffer->local_variables->items_count);
STRCMP_EQUAL("value",
Expand Down Expand Up @@ -934,6 +937,7 @@ TEST(GuiBuffer, GetString)
STRCMP_EQUAL("weechat", gui_buffer_get_string (gui_buffers, "short_name"));
STRCMP_EQUAL("formatted", gui_buffer_get_string (gui_buffers, "type"));
STRNCMP_EQUAL("WeeChat ", gui_buffer_get_string (gui_buffers, "title"), 8);
POINTERS_EQUAL(NULL, gui_buffer_get_string (gui_buffers, "modes"));
POINTERS_EQUAL(NULL, gui_buffer_get_string (gui_buffers, "input_prompt"));
STRCMP_EQUAL("", gui_buffer_get_string (gui_buffers, "input"));
POINTERS_EQUAL(NULL, gui_buffer_get_string (gui_buffers, "text_search_input"));
Expand Down Expand Up @@ -1033,6 +1037,16 @@ TEST(GuiBuffer, SetTitle)
/* TODO: write tests */
}

/*
* Tests functions:
* gui_buffer_set_modes
*/

TEST(GuiBuffer, SetModes)
{
/* TODO: write tests */
}

/*
* Tests functions:
* gui_buffer_set_time_for_each_line
Expand Down

0 comments on commit e7b2d98

Please sign in to comment.