diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-10 08:54:03 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-10 08:54:03 +0200 |
commit | 7634774327a231f2705a2ad68229b0037a92c9e7 (patch) | |
tree | 4bd3cb14f87ccf0f7bc6c51954281abfc743889d /src/gui | |
parent | e69cffd9bc1b921ab26220dbb592a084e7dd5e03 (diff) | |
download | weechat-7634774327a231f2705a2ad68229b0037a92c9e7.zip |
core: add buffer property "input_prompt"
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-bar-item.c | 9 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 42 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 1 |
3 files changed, 41 insertions, 11 deletions
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 3e6db5e7f..670ef3362 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -815,8 +815,6 @@ gui_bar_item_input_prompt_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { - const char *nick; - /* make C compiler happy */ (void) pointer; (void) data; @@ -827,9 +825,7 @@ gui_bar_item_input_prompt_cb (const void *pointer, void *data, if (!buffer) return NULL; - nick = (const char *)hashtable_get (buffer->local_variables, "nick"); - - return (nick) ? strdup (nick) : NULL; + return (buffer->input_prompt) ? strdup (buffer->input_prompt) : NULL; } /* @@ -2312,7 +2308,8 @@ gui_bar_item_init () gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT], &gui_bar_item_input_prompt_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_localvar_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;input_prompt_changed;" + "buffer_localvar_*", gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]); /* input search */ diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 5cfa8eb89..d33c703a4 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -110,9 +110,9 @@ 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", "text_search_input", "highlight_words", - "highlight_disable_regex", "highlight_regex", "highlight_tags_restrict", - "highlight_tags", "hotlist_max_level_nicks", + "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[] = @@ -128,8 +128,8 @@ char *gui_buffer_properties_set[] = "highlight_words_del", "highlight_disable_regex", "highlight_regex", "highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks", "hotlist_max_level_nicks_add", "hotlist_max_level_nicks_del", - "input", "input_pos", "input_get_any_user_data", "input_get_unknown_commands", - "input_get_empty", "input_multiline", + "input_prompt", "input", "input_pos", "input_get_any_user_data", + "input_get_unknown_commands", "input_get_empty", "input_multiline", NULL }; @@ -902,6 +902,7 @@ gui_buffer_new_props_with_id (long long id, new_buffer->input_get_unknown_commands = 0; new_buffer->input_get_empty = 0; new_buffer->input_multiline = 0; + new_buffer->input_prompt = NULL; gui_buffer_input_buffer_init (new_buffer); /* undo for input */ @@ -1543,6 +1544,8 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property) "%lld", buffer->nicklist_last_id_assigned); return str_value; } + else if (strcmp (property, "input_prompt") == 0) + return buffer->input_prompt; else if (strcmp (property, "input") == 0) return buffer->input_buffer; else if (strcmp (property, "text_search_input") == 0) @@ -2296,6 +2299,26 @@ gui_buffer_remove_hotlist_max_level_nicks (struct t_gui_buffer *buffer, } /* + * Sets buffer input prompt. + */ + +void +gui_buffer_set_input_prompt (struct t_gui_buffer *buffer, + const char *input_prompt) +{ + if (!buffer || (string_strcmp (buffer->input_prompt, input_prompt) == 0)) + return; + + free (buffer->input_prompt); + buffer->input_prompt = (input_prompt && input_prompt[0]) ? + strdup (input_prompt) : NULL; + + (void) gui_buffer_send_signal (buffer, + "input_prompt_changed", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); +} + +/* * Sets buffer input. */ @@ -2711,6 +2734,10 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, gui_key_unbind (buffer, -1, property + 11); } } + else if (strcmp (property, "input_prompt") == 0) + { + gui_buffer_set_input_prompt (buffer, value); + } else if (strcmp (property, "input") == 0) { gui_buffer_set_input (buffer, value); @@ -3750,6 +3777,7 @@ gui_buffer_close (struct t_gui_buffer *buffer) free (buffer->old_full_name); free (buffer->short_name); free (buffer->title); + free (buffer->input_prompt); free (buffer->input_buffer); free (buffer->input_undo_snap); free (buffer->text_search_input); @@ -5203,6 +5231,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data, HDATA_VAR(struct t_gui_buffer, input_get_unknown_commands, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, input_get_empty, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, input_multiline, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_gui_buffer, input_prompt, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, input_buffer, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, input_buffer_alloc, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, input_buffer_size, INTEGER, 0, NULL, NULL); @@ -5426,6 +5455,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "input_multiline", buffer->input_multiline)) return 0; + if (!infolist_new_var_string (ptr_item, "input_prompt", buffer->input_prompt)) + return 0; if (!infolist_new_var_string (ptr_item, "input_buffer", buffer->input_buffer)) return 0; if (!infolist_new_var_integer (ptr_item, "input_buffer_alloc", buffer->input_buffer_alloc)) @@ -5659,6 +5690,7 @@ gui_buffer_print_log () log_printf (" input_get_unknown_cmd . : %d", ptr_buffer->input_get_unknown_commands); log_printf (" input_get_empty . . . . : %d", ptr_buffer->input_get_empty); log_printf (" input_multiline . . . . : %d", ptr_buffer->input_multiline); + log_printf (" input_prompt. . . . . . : '%s'", ptr_buffer->input_prompt); log_printf (" input_buffer. . . . . . : '%s'", ptr_buffer->input_buffer); log_printf (" input_buffer_alloc. . . : %d", ptr_buffer->input_buffer_alloc); log_printf (" input_buffer_size . . . : %d", ptr_buffer->input_buffer_size); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 09373e9be..ed0974b7b 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -194,6 +194,7 @@ struct t_gui_buffer /* input_callback */ int input_multiline; /* 1 if multiple lines are sent as */ /* one message to input_callback */ + char *input_prompt; /* input prompt */ char *input_buffer; /* input buffer */ int input_buffer_alloc; /* input buffer: allocated size */ int input_buffer_size; /* buffer size in bytes */ |