diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-05-16 20:55:56 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-05-16 20:55:56 +0200 |
commit | b1430131a79597de58119a421f83feec22a7aeef (patch) | |
tree | 5f9658b3178b589cd731b2aacd228359d3af2468 /src | |
parent | 540abf0874dc9e38a3acde11c3c4c8705ad4c931 (diff) | |
download | weechat-b1430131a79597de58119a421f83feec22a7aeef.zip |
core: add bar item "buffer_short_name" (task #10882)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui-bar-item.c | 52 | ||||
-rw-r--r-- | src/gui/gui-bar-item.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-bar-item.c | 57 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 1 |
5 files changed, 96 insertions, 16 deletions
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 6cbb5b204..7f296ab0c 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -59,9 +59,9 @@ struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */ char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] = { "input_paste", "input_prompt", "input_search", "input_text", "time", "buffer_count", "buffer_last_number", "buffer_plugin", "buffer_number", - "buffer_name", "buffer_modes", "buffer_filter", "buffer_zoom", - "buffer_nicklist_count", "scroll", "hotlist", "completion", "buffer_title", - "buffer_nicklist", "window_number" + "buffer_name", "buffer_short_name", "buffer_modes", "buffer_filter", + "buffer_zoom", "buffer_nicklist_count", "scroll", "hotlist", "completion", + "buffer_title", "buffer_nicklist", "window_number" }; char *gui_bar_items_default_for_bars[][2] = { { GUI_BAR_DEFAULT_NAME_INPUT, @@ -1056,13 +1056,44 @@ gui_bar_item_default_buffer_name (void *data, struct t_gui_bar_item *item, return NULL; snprintf (str_name, sizeof (str_name), "%s%s", - gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_name))), + gui_color_get_custom ( + gui_color_get_name (CONFIG_COLOR(config_color_status_name))), buffer->name); return strdup (str_name); } /* + * Default item for short name of buffer. + */ + +char * +gui_bar_item_default_buffer_short_name (void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + struct t_gui_buffer *buffer, + struct t_hashtable *extra_info) +{ + char str_short_name[256]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) extra_info; + + if (!buffer) + return NULL; + + snprintf (str_short_name, sizeof (str_short_name), "%s%s", + gui_color_get_custom ( + gui_color_get_name (CONFIG_COLOR(config_color_status_name))), + buffer->short_name); + + return strdup (str_short_name); +} + +/* * Default item for modes of buffer. * * Note: this bar item is empty for WeeChat core, this is used only by plugins @@ -1976,6 +2007,19 @@ gui_bar_item_init () gui_bar_item_hook_signal ("buffer_moved", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]); + /* buffer short name */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME], + &gui_bar_item_default_buffer_short_name, NULL); + gui_bar_item_hook_signal ("window_switch", + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); + gui_bar_item_hook_signal ("buffer_switch", + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); + gui_bar_item_hook_signal ("buffer_renamed", + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); + gui_bar_item_hook_signal ("buffer_moved", + gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); + /* buffer modes */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES], diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h index 58a4f429f..1ea670009 100644 --- a/src/gui/gui-bar-item.h +++ b/src/gui/gui-bar-item.h @@ -32,6 +32,7 @@ enum t_gui_bar_item_weechat GUI_BAR_ITEM_BUFFER_PLUGIN, GUI_BAR_ITEM_BUFFER_NUMBER, GUI_BAR_ITEM_BUFFER_NAME, + GUI_BAR_ITEM_BUFFER_SHORT_NAME, GUI_BAR_ITEM_BUFFER_MODES, GUI_BAR_ITEM_BUFFER_FILTER, GUI_BAR_ITEM_BUFFER_ZOOM, diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index 0e84023f8..6a6f22cf5 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -176,10 +176,7 @@ irc_bar_item_buffer_plugin (void *data, struct t_gui_bar_item *item, */ char * -irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window, - struct t_gui_buffer *buffer, - struct t_hashtable *extra_info) +irc_bar_item_buffer_name_content (struct t_gui_buffer *buffer, int short_name) { char buf[512], buf_name[256], modes[128]; const char *name; @@ -187,12 +184,6 @@ irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, struct t_irc_server *server; struct t_irc_channel *channel; - /* make C compiler happy */ - (void) data; - (void) item; - (void) window; - (void) extra_info; - if (!buffer) return NULL; @@ -228,7 +219,7 @@ irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, (server && display_server) ? IRC_COLOR_BAR_DELIM : "", (server && display_server) ? "/" : "", (server && server->ssl_connected) ? IRC_COLOR_STATUS_NAME_SSL : IRC_COLOR_STATUS_NAME, - channel->name, + (short_name) ? weechat_buffer_get_string (buffer, "short_name") : channel->name, (part_from_channel) ? IRC_COLOR_BAR_DELIM : "", (part_from_channel) ? ")" : ""); } @@ -236,7 +227,8 @@ irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, } else { - name = weechat_buffer_get_string (buffer, "name"); + name = weechat_buffer_get_string (buffer, + (short_name) ? "short_name" : "name"); if (name) snprintf (buf_name, sizeof (buf_name), "%s", name); } @@ -250,6 +242,45 @@ irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, } /* + * Returns content of bar item "buffer_name": bar item with buffer name. + */ + +char * +irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + struct t_gui_buffer *buffer, + struct t_hashtable *extra_info) +{ + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) extra_info; + + return irc_bar_item_buffer_name_content (buffer, 0); +} + +/* + * Returns content of bar item "buffer_short_name": bar item with buffer short + * name. + */ + +char * +irc_bar_item_buffer_short_name (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + struct t_gui_buffer *buffer, + struct t_hashtable *extra_info) +{ + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) extra_info; + + return irc_bar_item_buffer_name_content (buffer, 1); +} + +/* * Returns content of bar item "buffer_modes": bar item with buffer modes. */ @@ -605,6 +636,7 @@ irc_bar_item_buffer_switch (void *data, const char *signal, weechat_bar_item_update ("away"); weechat_bar_item_update ("buffer_title"); weechat_bar_item_update ("buffer_name"); + weechat_bar_item_update ("buffer_short_name"); weechat_bar_item_update ("buffer_modes"); weechat_bar_item_update ("irc_channel"); weechat_bar_item_update ("lag"); @@ -625,6 +657,7 @@ irc_bar_item_init () weechat_bar_item_new ("buffer_title", &irc_bar_item_buffer_title, NULL); weechat_bar_item_new ("buffer_plugin", &irc_bar_item_buffer_plugin, NULL); weechat_bar_item_new ("buffer_name", &irc_bar_item_buffer_name, NULL); + weechat_bar_item_new ("buffer_short_name", &irc_bar_item_buffer_short_name, NULL); weechat_bar_item_new ("buffer_modes", &irc_bar_item_buffer_modes, NULL); weechat_bar_item_new ("irc_channel", &irc_bar_item_channel, NULL); weechat_bar_item_new ("lag", &irc_bar_item_lag, NULL); diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 5329063e1..19c835876 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -610,6 +610,7 @@ irc_config_change_look_item_display_server (void *data, weechat_bar_item_update ("buffer_plugin"); weechat_bar_item_update ("buffer_name"); + weechat_bar_item_update ("buffer_short_name"); } /* diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index f94a7c01b..ab6ef9703 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -4047,6 +4047,7 @@ irc_server_connect (struct t_irc_server *server) } weechat_bar_item_update ("buffer_name"); + weechat_bar_item_update ("buffer_short_name"); irc_server_set_index_current_address (server, server->index_current_address); |