mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 11:13:12 +02:00
Add "default" option to command /bar, to create default bars (today only input and status)
This commit is contained in:
+72
-34
@@ -61,16 +61,16 @@ struct t_hook *gui_bar_item_timer = NULL;
|
||||
*/
|
||||
|
||||
struct t_gui_bar_item *
|
||||
gui_bar_item_search (const char *name)
|
||||
gui_bar_item_search (const char *item_name)
|
||||
{
|
||||
struct t_gui_bar_item *ptr_item;
|
||||
|
||||
if (!name || !name[0])
|
||||
if (!item_name || !item_name[0])
|
||||
return NULL;
|
||||
|
||||
for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item)
|
||||
{
|
||||
if (strcmp (ptr_item->name, name) == 0)
|
||||
if (strcmp (ptr_item->name, item_name) == 0)
|
||||
return ptr_item;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ gui_bar_item_string_get_item_start (const char *string)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_string_is_item (const char *string, const char *name)
|
||||
gui_bar_item_string_is_item (const char *string, const char *item_name)
|
||||
{
|
||||
const char *item_start;
|
||||
int length;
|
||||
@@ -132,8 +132,8 @@ gui_bar_item_string_is_item (const char *string, const char *name)
|
||||
if (!item_start)
|
||||
return 0;
|
||||
|
||||
length = strlen (name);
|
||||
if (strncmp (item_start, name, length) == 0)
|
||||
length = strlen (item_name);
|
||||
if (strncmp (item_start, item_name, length) == 0)
|
||||
{
|
||||
if (!gui_bar_item_valid_char_name (item_start[length]))
|
||||
return 1;
|
||||
@@ -147,17 +147,18 @@ gui_bar_item_string_is_item (const char *string, const char *name)
|
||||
*/
|
||||
|
||||
struct t_gui_bar_item *
|
||||
gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, const char *name)
|
||||
gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin,
|
||||
const char *item_name)
|
||||
{
|
||||
struct t_gui_bar_item *ptr_item;
|
||||
|
||||
if (!name || !name[0])
|
||||
if (!item_name || !item_name[0])
|
||||
return NULL;
|
||||
|
||||
for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item)
|
||||
{
|
||||
if ((ptr_item->plugin == plugin)
|
||||
&& (strcmp (ptr_item->name, name) == 0))
|
||||
&& (strcmp (ptr_item->name, item_name) == 0))
|
||||
return ptr_item;
|
||||
}
|
||||
|
||||
@@ -165,6 +166,66 @@ gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, const char *na
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_contains_item: return 1 if a bar contains item, O otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_contains_item (struct t_gui_bar *bar, const char *item_name)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!bar || !item_name || !item_name[0])
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < bar->items_count; i++)
|
||||
{
|
||||
/* skip non letters chars at beginning (prefix) */
|
||||
if (gui_bar_item_string_is_item (bar->items_array[i], item_name))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* item is not in bar */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_used_in_a_bar: return 1 if an item is used in at least one bar
|
||||
* if partial_name == 1, then search a bar that
|
||||
* contains item beginning with "item_name"
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_used_in_a_bar (const char *item_name, int partial_name)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
int i, length;
|
||||
const char *ptr_start;
|
||||
|
||||
length = strlen (item_name);
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
for (i = 0; i < ptr_bar->items_count; i++)
|
||||
{
|
||||
ptr_start = gui_bar_item_string_get_item_start (ptr_bar->items_array[i]);
|
||||
if (ptr_start)
|
||||
{
|
||||
if ((partial_name
|
||||
&& strncmp (ptr_start, item_name, length) == 0)
|
||||
|| (!partial_name
|
||||
&& strcmp (ptr_start, item_name) == 0))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* item not used by any bar */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_input_text_update_for_display: update input text item for
|
||||
* display:
|
||||
@@ -456,42 +517,19 @@ gui_bar_item_new (struct t_weechat_plugin *plugin, const char *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_contains_item: return 1 if a bar contains item, O otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_contains_item (struct t_gui_bar *bar, const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!bar || !name || !name[0])
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < bar->items_count; i++)
|
||||
{
|
||||
/* skip non letters chars at beginning (prefix) */
|
||||
if (gui_bar_item_string_is_item (bar->items_array[i], name))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* item is not in bar */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_update: update an item on all bars displayed on screen
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_item_update (const char *name)
|
||||
gui_bar_item_update (const char *item_name)
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (!CONFIG_BOOLEAN(ptr_bar->hidden)
|
||||
&& gui_bar_contains_item (ptr_bar, name))
|
||||
&& gui_bar_contains_item (ptr_bar, item_name))
|
||||
{
|
||||
gui_bar_draw (ptr_bar);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ extern char *gui_bar_item_names[];
|
||||
/* functions */
|
||||
|
||||
extern struct t_gui_bar_item *gui_bar_item_search (const char *name);
|
||||
extern int gui_bar_item_used_in_a_bar (const char *item_name,
|
||||
int partial_name);
|
||||
extern char *gui_bar_item_get_value (const char *name,
|
||||
struct t_gui_bar *bar,
|
||||
struct t_gui_window *window,
|
||||
@@ -78,7 +80,8 @@ extern struct t_gui_bar_item *gui_bar_item_new (struct t_weechat_plugin *plugin,
|
||||
char *(*build_callback)(void *data,
|
||||
struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
int max_width, int max_height),
|
||||
int max_width,
|
||||
int max_height),
|
||||
void *build_callback_data);
|
||||
extern void gui_bar_item_update (const char *name);
|
||||
extern void gui_bar_item_free (struct t_gui_bar_item *item);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "gui-bar.h"
|
||||
#include "gui-bar-item.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-chat.h"
|
||||
#include "gui-color.h"
|
||||
@@ -1555,6 +1556,113 @@ gui_bar_use_temp_bars ()
|
||||
last_gui_temp_bar = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_create_default: create default bars if they do not exist
|
||||
*/
|
||||
|
||||
void
|
||||
gui_bar_create_default ()
|
||||
{
|
||||
struct t_gui_bar *ptr_bar;
|
||||
int length;
|
||||
char *buf;
|
||||
|
||||
/* search an input_text item */
|
||||
if (!gui_bar_item_used_in_a_bar (gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT], 1))
|
||||
{
|
||||
ptr_bar = gui_bar_search ("input");
|
||||
if (ptr_bar)
|
||||
{
|
||||
/* add item "input_text" to input bar */
|
||||
length = 1;
|
||||
if (CONFIG_STRING(ptr_bar->items))
|
||||
length += strlen (CONFIG_STRING(ptr_bar->items));
|
||||
length += 1; /* "," */
|
||||
length += strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]);
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "%s,%s",
|
||||
(CONFIG_STRING(ptr_bar->items)) ?
|
||||
CONFIG_STRING(ptr_bar->items) : "",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]);
|
||||
config_file_option_set (ptr_bar->items, buf, 1);
|
||||
gui_bar_draw (ptr_bar);
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create input bar */
|
||||
length = 1 /* "[" */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT])
|
||||
+ 2 /* "]," */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT])
|
||||
+ 1 /* \0 */;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "[%s],%s",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]);
|
||||
if (gui_bar_new (NULL, "input", "0", "999", "window", "",
|
||||
"bottom", "horizontal", "1", "0",
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_input)),
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_input_delimiters)),
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_input_bg)),
|
||||
"0", buf))
|
||||
{
|
||||
gui_chat_printf (NULL, _("Bar \"%s\" created"),
|
||||
"input");
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* search status bar */
|
||||
ptr_bar = gui_bar_search ("status");
|
||||
if (!ptr_bar)
|
||||
{
|
||||
/* create status bar */
|
||||
length = strlen (gui_bar_item_names[GUI_BAR_ITEM_TIME])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_HOTLIST])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_COMPLETION])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_SCROLL])
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_NICKLIST_COUNT])
|
||||
+ (9 * 4) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "[%s],[%s],[%s],%s,(%s),[%s],[%s],%s,%s",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_TIME],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_NICKLIST_COUNT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_HOTLIST],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_COMPLETION],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_SCROLL]);
|
||||
if (gui_bar_new (NULL, "status", "0", "0", "window", "",
|
||||
"bottom", "horizontal", "1", "0",
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_status)),
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_status_delimiters)),
|
||||
gui_color_get_name (CONFIG_COLOR(config_color_status_bg)),
|
||||
"0", buf))
|
||||
{
|
||||
gui_chat_printf (NULL, _("Bar \"%s\" created"),
|
||||
"input");
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_update: update a bar on screen
|
||||
*/
|
||||
|
||||
@@ -135,6 +135,7 @@ extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
|
||||
const char *separator,
|
||||
const char *items);
|
||||
extern void gui_bar_use_temp_bars ();
|
||||
extern void gui_bar_create_default ();
|
||||
extern void gui_bar_update (const char *name);
|
||||
extern void gui_bar_free (struct t_gui_bar *bar);
|
||||
extern void gui_bar_free_all ();
|
||||
|
||||
@@ -33,15 +33,27 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../core/wee-utf8.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-nicklist.h"
|
||||
#include "gui-buffer.h"
|
||||
#include "gui-color.h"
|
||||
#include "gui-status.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_nicklist_changed_signal: send "nicklist_changed" signal
|
||||
*/
|
||||
|
||||
void
|
||||
gui_nicklist_changed_signal ()
|
||||
{
|
||||
hook_signal_send ("nicklist_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_nicklist_find_pos_group: find position for a group (for sorting nicklist)
|
||||
*/
|
||||
@@ -200,6 +212,8 @@ gui_nicklist_add_group (struct t_gui_buffer *buffer,
|
||||
gui_status_refresh_needed = 1;
|
||||
}
|
||||
|
||||
gui_nicklist_changed_signal ();
|
||||
|
||||
return new_group;
|
||||
}
|
||||
|
||||
@@ -342,6 +356,8 @@ gui_nicklist_add_nick (struct t_gui_buffer *buffer,
|
||||
gui_status_refresh_needed = 1;
|
||||
}
|
||||
|
||||
gui_nicklist_changed_signal ();
|
||||
|
||||
return new_nick;
|
||||
}
|
||||
|
||||
@@ -379,6 +395,8 @@ gui_nicklist_remove_nick (struct t_gui_buffer *buffer,
|
||||
}
|
||||
|
||||
free (nick);
|
||||
|
||||
gui_nicklist_changed_signal ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -435,6 +453,8 @@ gui_nicklist_remove_group (struct t_gui_buffer *buffer,
|
||||
}
|
||||
|
||||
free (group);
|
||||
|
||||
gui_nicklist_changed_signal ();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user