mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 04:46:37 +02:00
core: allow empty short name on buffers (name is used if not set)
This commit is contained in:
@@ -439,8 +439,7 @@ upgrade_weechat_read_cb (void *data,
|
||||
strdup (infolist_string (infolist, "plugin_name"));
|
||||
upgrade_current_buffer->short_name =
|
||||
(infolist_string (infolist, "short_name")) ?
|
||||
strdup (infolist_string (infolist, "short_name")) :
|
||||
strdup (infolist_string (infolist, "name"));
|
||||
strdup (infolist_string (infolist, "short_name")) : NULL;
|
||||
upgrade_current_buffer->type =
|
||||
infolist_integer (infolist, "type");
|
||||
upgrade_current_buffer->notify =
|
||||
|
||||
@@ -320,11 +320,11 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
|
||||
void
|
||||
gui_chat_display_word (struct t_gui_window *window,
|
||||
struct t_gui_line *line,
|
||||
char *data, char *end_offset,
|
||||
const char *word, const char *word_end,
|
||||
int prefix, int num_lines, int count,
|
||||
int *lines_displayed, int simulate)
|
||||
{
|
||||
char *end_line, saved_char_end, saved_char, str_space[] = " ";
|
||||
char *data, *ptr_data, *end_line, saved_char, str_space[] = " ";
|
||||
int pos_saved_char, chars_to_display, num_displayed;
|
||||
int length_align;
|
||||
attr_t attrs;
|
||||
@@ -332,27 +332,26 @@ gui_chat_display_word (struct t_gui_window *window,
|
||||
short pair;
|
||||
short *ptr_pair;
|
||||
|
||||
if (!data ||
|
||||
if (!word ||
|
||||
((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)))
|
||||
return;
|
||||
|
||||
if (!simulate)
|
||||
window->coords[window->win_chat_cursor_y].line = line;
|
||||
|
||||
end_line = data + strlen (data);
|
||||
|
||||
if (end_offset && end_offset[0])
|
||||
{
|
||||
saved_char_end = end_offset[0];
|
||||
end_offset[0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
end_offset = NULL;
|
||||
saved_char_end = '\0';
|
||||
}
|
||||
data = strdup (word);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
while (data && data[0])
|
||||
end_line = data + strlen (data);
|
||||
|
||||
if (word_end && word_end[0])
|
||||
data[word_end - word] = '\0';
|
||||
else
|
||||
word_end = NULL;
|
||||
|
||||
ptr_data = data;
|
||||
while (ptr_data && ptr_data[0])
|
||||
{
|
||||
/* insert spaces for aligning text under time/nick */
|
||||
length_align = gui_line_get_align (window->buffer, line, 0, 0);
|
||||
@@ -393,27 +392,27 @@ gui_chat_display_word (struct t_gui_window *window,
|
||||
if (!simulate)
|
||||
wattr_set (GUI_WINDOW_OBJECTS(window)->win_chat, attrs, pair, NULL);
|
||||
}
|
||||
window->coords[window->win_chat_cursor_y].data = data;
|
||||
window->coords[window->win_chat_cursor_y].data = ptr_data;
|
||||
}
|
||||
|
||||
chars_to_display = gui_chat_strlen_screen (data);
|
||||
chars_to_display = gui_chat_strlen_screen (ptr_data);
|
||||
|
||||
/* too long for current line */
|
||||
if (window->win_chat_cursor_x + chars_to_display > gui_chat_get_real_width (window))
|
||||
{
|
||||
num_displayed = gui_chat_get_real_width (window) - window->win_chat_cursor_x;
|
||||
pos_saved_char = gui_chat_string_real_pos (data, num_displayed);
|
||||
pos_saved_char = gui_chat_string_real_pos (ptr_data, num_displayed);
|
||||
if (!simulate)
|
||||
{
|
||||
saved_char = data[pos_saved_char];
|
||||
data[pos_saved_char] = '\0';
|
||||
saved_char = ptr_data[pos_saved_char];
|
||||
ptr_data[pos_saved_char] = '\0';
|
||||
if ((count == 0) || (*lines_displayed >= num_lines - count))
|
||||
gui_chat_display_word_raw (window, data, 0, 1);
|
||||
gui_chat_display_word_raw (window, ptr_data, 0, 1);
|
||||
else
|
||||
gui_chat_display_word_raw (window, data, 0, 0);
|
||||
data[pos_saved_char] = saved_char;
|
||||
gui_chat_display_word_raw (window, ptr_data, 0, 0);
|
||||
ptr_data[pos_saved_char] = saved_char;
|
||||
}
|
||||
data += pos_saved_char;
|
||||
ptr_data += pos_saved_char;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -421,30 +420,29 @@ gui_chat_display_word (struct t_gui_window *window,
|
||||
if (!simulate)
|
||||
{
|
||||
if ((count == 0) || (*lines_displayed >= num_lines - count))
|
||||
gui_chat_display_word_raw (window, data, 0, 1);
|
||||
gui_chat_display_word_raw (window, ptr_data, 0, 1);
|
||||
else
|
||||
gui_chat_display_word_raw (window, data, 0, 0);
|
||||
gui_chat_display_word_raw (window, ptr_data, 0, 0);
|
||||
}
|
||||
data += strlen (data);
|
||||
ptr_data += strlen (ptr_data);
|
||||
}
|
||||
|
||||
window->win_chat_cursor_x += num_displayed;
|
||||
|
||||
/* display new line? */
|
||||
if ((!prefix && (data >= end_line)) ||
|
||||
if ((!prefix && (ptr_data >= end_line)) ||
|
||||
(((simulate) ||
|
||||
(window->win_chat_cursor_y <= window->win_chat_height - 1)) &&
|
||||
(window->win_chat_cursor_x > (gui_chat_get_real_width (window) - 1))))
|
||||
gui_chat_display_new_line (window, num_lines, count,
|
||||
lines_displayed, simulate);
|
||||
|
||||
if ((!prefix && (data >= end_line)) ||
|
||||
if ((!prefix && (ptr_data >= end_line)) ||
|
||||
((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)))
|
||||
data = NULL;
|
||||
ptr_data = NULL;
|
||||
}
|
||||
|
||||
if (end_offset)
|
||||
end_offset[0] = saved_char_end;
|
||||
free (data);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -460,6 +458,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
int simulate)
|
||||
{
|
||||
char str_space[] = " ", str_plus[] = "+", *prefix_highlighted;
|
||||
const char *short_name;
|
||||
int i, length, length_allowed, num_spaces;
|
||||
struct t_gui_lines *mixed_lines;
|
||||
|
||||
@@ -499,8 +498,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
}
|
||||
else
|
||||
length_allowed = mixed_lines->buffer_max_length;
|
||||
|
||||
length = gui_chat_strlen_screen (line->data->buffer->short_name);
|
||||
|
||||
short_name = gui_buffer_get_short_name (line->data->buffer);
|
||||
length = gui_chat_strlen_screen (short_name);
|
||||
num_spaces = length_allowed - length;
|
||||
|
||||
if (CONFIG_INTEGER(config_look_prefix_buffer_align) == CONFIG_LOOK_PREFIX_BUFFER_ALIGN_RIGHT)
|
||||
@@ -531,9 +531,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
&& (num_spaces < 0))
|
||||
{
|
||||
gui_chat_display_word (window, line,
|
||||
line->data->buffer->short_name,
|
||||
line->data->buffer->short_name +
|
||||
gui_chat_string_real_pos (line->data->buffer->short_name,
|
||||
short_name,
|
||||
short_name +
|
||||
gui_chat_string_real_pos (short_name,
|
||||
length_allowed),
|
||||
1, num_lines, count, lines_displayed,
|
||||
simulate);
|
||||
@@ -541,9 +541,8 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
else
|
||||
{
|
||||
gui_chat_display_word (window, line,
|
||||
line->data->buffer->short_name,
|
||||
NULL, 1, num_lines, count, lines_displayed,
|
||||
simulate);
|
||||
short_name, NULL, 1, num_lines, count,
|
||||
lines_displayed, simulate);
|
||||
}
|
||||
|
||||
window->coords[window->win_chat_cursor_y].buffer_x2 = window->win_chat_cursor_x - 1;
|
||||
|
||||
@@ -1147,6 +1147,8 @@ gui_color_buffer_open ()
|
||||
&gui_color_buffer_close_cb, NULL);
|
||||
if (gui_color_buffer)
|
||||
{
|
||||
if (!gui_color_buffer->short_name)
|
||||
gui_color_buffer->short_name = strdup ("color");
|
||||
gui_buffer_set (gui_color_buffer, "type", "free");
|
||||
gui_buffer_set (gui_color_buffer, "localvar_set_no_log", "1");
|
||||
gui_buffer_set (gui_color_buffer, "key_bind_meta-c", "/color switch");
|
||||
|
||||
@@ -134,6 +134,10 @@ gui_main_init ()
|
||||
|
||||
ptr_buffer->num_displayed = 1;
|
||||
|
||||
/* set short name */
|
||||
if (!ptr_buffer->short_name)
|
||||
ptr_buffer->short_name = strdup (GUI_BUFFER_MAIN);
|
||||
|
||||
/* set title for core buffer */
|
||||
gui_buffer_set_title (ptr_buffer,
|
||||
"WeeChat " PACKAGE_VERSION " "
|
||||
|
||||
@@ -1115,7 +1115,7 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item,
|
||||
CONFIG_INTEGER(config_look_hotlist_names_length));
|
||||
sprintf (buf + strlen (buf), format,
|
||||
(CONFIG_BOOLEAN(config_look_hotlist_short_names)) ?
|
||||
ptr_hotlist->buffer->short_name : ptr_hotlist->buffer->name);
|
||||
gui_buffer_get_short_name (ptr_hotlist->buffer) : ptr_hotlist->buffer->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+26
-12
@@ -122,6 +122,18 @@ gui_buffer_get_plugin_name (struct t_gui_buffer *buffer)
|
||||
return plugin_get_name (buffer->plugin);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_buffer_get_short_name: get short name of buffer (of name if short_name
|
||||
* is NULL)
|
||||
* Note: this function never returns NULL
|
||||
*/
|
||||
|
||||
const char *
|
||||
gui_buffer_get_short_name (struct t_gui_buffer *buffer)
|
||||
{
|
||||
return (buffer->short_name) ? buffer->short_name : buffer->name;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_buffer_local_var_add: add a new local variable to a buffer
|
||||
*/
|
||||
@@ -404,7 +416,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
|
||||
struct t_gui_completion *new_completion;
|
||||
int first_buffer_creation;
|
||||
|
||||
if (!name)
|
||||
if (!name || !name[0])
|
||||
return NULL;
|
||||
|
||||
if (gui_buffer_search_by_name (plugin_get_name (plugin), name))
|
||||
@@ -432,7 +444,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
|
||||
&(new_buffer->layout_number),
|
||||
&(new_buffer->layout_number_merge_order));
|
||||
new_buffer->name = strdup (name);
|
||||
new_buffer->short_name = strdup (name);
|
||||
new_buffer->short_name = NULL;
|
||||
new_buffer->type = GUI_BUFFER_TYPE_FORMATTED;
|
||||
new_buffer->notify = CONFIG_INTEGER(config_look_buffer_notify_default);
|
||||
new_buffer->num_displayed = 0;
|
||||
@@ -945,18 +957,20 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, const char *name)
|
||||
void
|
||||
gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name)
|
||||
{
|
||||
if (short_name && short_name[0])
|
||||
if (buffer->short_name)
|
||||
{
|
||||
if (buffer->short_name)
|
||||
free (buffer->short_name);
|
||||
buffer->short_name = strdup (short_name);
|
||||
if (buffer->mixed_lines)
|
||||
gui_line_compute_buffer_max_length (buffer, buffer->mixed_lines);
|
||||
gui_buffer_ask_chat_refresh (buffer, 1);
|
||||
|
||||
hook_signal_send ("buffer_renamed",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
free (buffer->short_name);
|
||||
buffer->short_name = NULL;
|
||||
}
|
||||
buffer->short_name = (short_name && short_name[0]) ?
|
||||
strdup (short_name) : NULL;
|
||||
|
||||
if (buffer->mixed_lines)
|
||||
gui_line_compute_buffer_max_length (buffer, buffer->mixed_lines);
|
||||
gui_buffer_ask_chat_refresh (buffer, 1);
|
||||
|
||||
hook_signal_send ("buffer_renamed",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -203,6 +203,7 @@ extern char *gui_buffer_properties_set[];
|
||||
/* buffer functions */
|
||||
|
||||
extern const char *gui_buffer_get_plugin_name (struct t_gui_buffer *buffer);
|
||||
extern const char *gui_buffer_get_short_name (struct t_gui_buffer *buffer);
|
||||
extern void gui_buffer_notify_set_all ();
|
||||
extern void gui_buffer_input_buffer_init (struct t_gui_buffer *buffer);
|
||||
extern struct t_gui_buffer *gui_buffer_new (struct t_weechat_plugin *plugin,
|
||||
|
||||
+5
-3
@@ -119,7 +119,7 @@ gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line,
|
||||
{
|
||||
if ((CONFIG_INTEGER(config_look_prefix_buffer_align) == CONFIG_LOOK_PREFIX_BUFFER_ALIGN_NONE)
|
||||
&& (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_NONE))
|
||||
length_buffer = gui_chat_strlen_screen (buffer->short_name) + 1;
|
||||
length_buffer = gui_chat_strlen_screen (gui_buffer_get_short_name (buffer)) + 1;
|
||||
else
|
||||
{
|
||||
if (CONFIG_INTEGER(config_look_prefix_buffer_align) == CONFIG_LOOK_PREFIX_BUFFER_ALIGN_NONE)
|
||||
@@ -507,14 +507,16 @@ gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer,
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
int length;
|
||||
const char *short_name;
|
||||
|
||||
lines->buffer_max_length = 0;
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
if ((ptr_buffer->number == buffer->number) && ptr_buffer->short_name)
|
||||
short_name = gui_buffer_get_short_name (ptr_buffer);
|
||||
if (ptr_buffer->number == buffer->number)
|
||||
{
|
||||
length = gui_chat_strlen_screen (ptr_buffer->short_name);
|
||||
length = gui_chat_strlen_screen (short_name);
|
||||
if (length > lines->buffer_max_length)
|
||||
lines->buffer_max_length = length;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ gui_window_get_context_at_xy (struct t_gui_window *window,
|
||||
else if ((win_x >= window->coords[win_y].buffer_x1)
|
||||
&& (win_x <= window->coords[win_y].buffer_x2))
|
||||
{
|
||||
*word = gui_color_decode ((*line)->data->buffer->short_name, NULL);
|
||||
*word = gui_color_decode (gui_buffer_get_short_name ((*line)->data->buffer), NULL);
|
||||
}
|
||||
else if ((win_x >= window->coords[win_y].prefix_x1)
|
||||
&& (win_x <= window->coords[win_y].prefix_x2))
|
||||
|
||||
Reference in New Issue
Block a user