mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 08:43:13 +02:00
buflist: add support of item names in command /buflist refresh
This commit is contained in:
@@ -21,6 +21,7 @@ add_library(buflist MODULE
|
||||
buflist.c buflist.h
|
||||
buflist-bar-item.c buflist-bar-item.h
|
||||
buflist-command.c buflist-command.h
|
||||
buflist-completion.c buflist-completion.h
|
||||
buflist-config.c buflist-config.h
|
||||
buflist-info.c buflist-info.h
|
||||
buflist-mouse.c buflist-mouse.h
|
||||
|
||||
@@ -105,24 +105,34 @@ buflist_bar_item_get_index_with_pointer (struct t_gui_bar_item *item)
|
||||
/*
|
||||
* Updates buflist bar item if buflist is enabled (or if force argument is 1).
|
||||
*
|
||||
* If force == 1, all used items are refreshed
|
||||
* (according to option buflist.look.use_items).
|
||||
* If index == -1, all bar items (or all bar items used) are refreshed,
|
||||
* otherwise only this bar item is refreshed.
|
||||
*
|
||||
* If force == 1, all used items are refreshed (according to option
|
||||
* buflist.look.use_items).
|
||||
* If force == 2, all items are refreshed.
|
||||
*/
|
||||
|
||||
void
|
||||
buflist_bar_item_update (int force)
|
||||
buflist_bar_item_update (int index, int force)
|
||||
{
|
||||
int i, num_items;
|
||||
|
||||
if (force || weechat_config_boolean (buflist_config_look_enabled))
|
||||
{
|
||||
num_items = (force == 2) ?
|
||||
BUFLIST_BAR_NUM_ITEMS :
|
||||
weechat_config_integer (buflist_config_look_use_items);
|
||||
for (i = 0; i < num_items; i++)
|
||||
if ((index >= 0) && (index < BUFLIST_BAR_NUM_ITEMS))
|
||||
{
|
||||
weechat_bar_item_update (buflist_bar_item_get_name (i));
|
||||
weechat_bar_item_update (buflist_bar_item_get_name (index));
|
||||
}
|
||||
else
|
||||
{
|
||||
num_items = (force == 2) ?
|
||||
BUFLIST_BAR_NUM_ITEMS :
|
||||
weechat_config_integer (buflist_config_look_use_items);
|
||||
for (i = 0; i < num_items; i++)
|
||||
{
|
||||
weechat_bar_item_update (buflist_bar_item_get_name (i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ extern struct t_arraylist *buflist_list_buffers[BUFLIST_BAR_NUM_ITEMS];
|
||||
extern const char *buflist_bar_item_get_name (int index);
|
||||
extern int buflist_bar_item_get_index (const char *item_name);
|
||||
extern int buflist_bar_item_get_index_with_pointer (struct t_gui_bar_item *item);
|
||||
extern void buflist_bar_item_update (int force);
|
||||
extern void buflist_bar_item_update (int index, int force);
|
||||
extern int buflist_bar_item_init ();
|
||||
extern void buflist_bar_item_end ();
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ buflist_command_buflist (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer, int argc,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
int i, index;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
@@ -72,7 +74,20 @@ buflist_command_buflist (const void *pointer, void *data,
|
||||
|
||||
if (weechat_strcmp (argv[1], "refresh") == 0)
|
||||
{
|
||||
buflist_bar_item_update (0);
|
||||
if (argc > 2)
|
||||
{
|
||||
for (i = 2; i < argc; i++)
|
||||
{
|
||||
index = buflist_bar_item_get_index (argv[i]);
|
||||
if (index >= 0)
|
||||
buflist_bar_item_update (index, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* refresh all bar items used */
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -89,13 +104,16 @@ buflist_command_init ()
|
||||
weechat_hook_command (
|
||||
"buflist",
|
||||
N_("bar item with list of buffers"),
|
||||
"enable|disable|toggle || bar || refresh",
|
||||
"enable|disable|toggle"
|
||||
" || bar"
|
||||
" || refresh [<item>[,<item>...]]",
|
||||
N_(" enable: enable buflist\n"
|
||||
"disable: disable buflist\n"
|
||||
" toggle: toggle buflist\n"
|
||||
" bar: add the \"buflist\" bar\n"
|
||||
"refresh: force the refresh of the bar items (buflist, buflist2 "
|
||||
"buflist3, buflist4 and buflist5)\n"
|
||||
"refresh: force the refresh of some bar items (if no item is given, "
|
||||
"all bar items used are refreshed, according to option "
|
||||
"buflist.look.use_items)\n"
|
||||
"\n"
|
||||
"The lines with buffers are displayed using string evaluation "
|
||||
"(see /help eval for the format), with these options:\n"
|
||||
@@ -174,6 +192,8 @@ buflist_command_init ()
|
||||
" - ${format_tls_version}: indicator of TLS version for a server "
|
||||
"buffer, empty for channels (evaluation of option "
|
||||
"buflist.format.tls_version)"),
|
||||
"enable|disable|toggle || bar || refresh",
|
||||
"enable|disable|toggle"
|
||||
" || bar"
|
||||
" || refresh %(buflist_used_items)|%*",
|
||||
&buflist_command_buflist, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* buflist-completion.c - completion for buflist command
|
||||
*
|
||||
* Copyright (C) 2023 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "buflist.h"
|
||||
#include "buflist-bar-item.h"
|
||||
#include "buflist-config.h"
|
||||
|
||||
|
||||
/*
|
||||
* Adds all buflist items to completion list.
|
||||
*/
|
||||
|
||||
int
|
||||
buflist_completion_all_items_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
for (i = 0; i < BUFLIST_BAR_NUM_ITEMS; i++)
|
||||
{
|
||||
weechat_completion_list_add (completion,
|
||||
buflist_bar_item_get_name (i),
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds used buflist items to completion list.
|
||||
*/
|
||||
|
||||
int
|
||||
buflist_completion_used_items_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
for (i = 0; i < weechat_config_integer (buflist_config_look_use_items); i++)
|
||||
{
|
||||
weechat_completion_list_add (completion,
|
||||
buflist_bar_item_get_name (i),
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hooks completions.
|
||||
*/
|
||||
|
||||
void
|
||||
buflist_completion_init ()
|
||||
{
|
||||
weechat_hook_completion ("buflist_all_items",
|
||||
N_("all buflist bar items"),
|
||||
&buflist_completion_all_items_cb, NULL, NULL);
|
||||
weechat_hook_completion ("buflist_used_items",
|
||||
N_("used buflist bar items (according to option "
|
||||
"buflist.look.use_items)"),
|
||||
&buflist_completion_used_items_cb, NULL, NULL);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WEECHAT_PLUGIN_BUFLIST_COMPLETION_H
|
||||
#define WEECHAT_PLUGIN_BUFLIST_COMPLETION_H
|
||||
|
||||
extern void buflist_completion_init ();
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_BUFLIST_COMPLETION_H */
|
||||
@@ -159,7 +159,7 @@ buflist_config_signal_buffer_cb (const void *pointer, void *data,
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -261,13 +261,13 @@ buflist_config_change_enabled (const void *pointer, void *data,
|
||||
/* buflist enabled */
|
||||
buflist_config_hook_signals_refresh ();
|
||||
weechat_command (NULL, "/mute /bar show buflist");
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* buflist disabled */
|
||||
weechat_command (NULL, "/mute /bar hide buflist");
|
||||
buflist_bar_item_update (1);
|
||||
buflist_bar_item_update (-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ buflist_config_change_sort (const void *pointer, void *data,
|
||||
|
||||
weechat_hashtable_free (hashtable_pointers);
|
||||
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -368,7 +368,7 @@ buflist_config_change_nick_prefix (const void *pointer, void *data,
|
||||
(void) option;
|
||||
|
||||
buflist_config_change_signals_refresh (NULL, NULL, NULL);
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -384,7 +384,7 @@ buflist_config_change_use_items (const void *pointer, void *data,
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
buflist_bar_item_update (2);
|
||||
buflist_bar_item_update (-1, 2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -400,7 +400,7 @@ buflist_config_change_buflist (const void *pointer, void *data,
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -461,7 +461,7 @@ buflist_config_change_format (const void *pointer, void *data,
|
||||
buflist_config_format_hotlist_eval = buflist_config_add_eval_for_formats (
|
||||
weechat_config_string (buflist_config_format_hotlist));
|
||||
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "buflist.h"
|
||||
#include "buflist-bar-item.h"
|
||||
#include "buflist-command.h"
|
||||
#include "buflist-completion.h"
|
||||
#include "buflist-config.h"
|
||||
#include "buflist-info.h"
|
||||
#include "buflist-mouse.h"
|
||||
@@ -458,10 +459,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
buflist_config_change_sort (NULL, NULL, NULL);
|
||||
|
||||
buflist_command_init ();
|
||||
buflist_completion_init ();
|
||||
|
||||
buflist_add_bar ();
|
||||
|
||||
buflist_bar_item_update (0);
|
||||
buflist_bar_item_update (-1, 0);
|
||||
|
||||
buflist_mouse_init ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user