summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2009-06-10 12:40:05 +0200
committerSebastien Helleu <flashcode@flashtux.org>2009-06-10 12:40:05 +0200
commit8d58b81d83d9a5462f1b4aeb274a16a91ef213d1 (patch)
tree4bf0ef51ea845f54fa97012b1ebe9a85e24f1750 /src/core
parentfd31dbb97ec00ee49cec21c4731677c403c80564 (diff)
downloadweechat-8d58b81d83d9a5462f1b4aeb274a16a91ef213d1.zip
Add buffer merging feature, with /buffer merge/unmerge (task #7404)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c144
-rw-r--r--src/core/wee-config.c15
-rw-r--r--src/core/wee-config.h9
-rw-r--r--src/core/wee-hook.c26
-rw-r--r--src/core/wee-upgrade-file.h2
-rw-r--r--src/core/wee-upgrade.c60
6 files changed, 196 insertions, 60 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index c7e094a27..f70c550db 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -544,9 +544,15 @@ command_buffer (void *data, struct t_gui_buffer *buffer,
number = strtol (argv[i], &error, 10);
if (error && !error[0])
{
- ptr_buffer = gui_buffer_search_by_number (number);
- if (ptr_buffer && (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATTED))
- gui_buffer_clear (ptr_buffer);
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if ((ptr_buffer->number == number)
+ && (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATTED))
+ {
+ gui_buffer_clear (ptr_buffer);
+ }
+ }
}
}
}
@@ -600,13 +606,77 @@ command_buffer (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
+ /* merge buffer with another number in the list */
+ if (string_strcasecmp (argv[1], "merge") == 0)
+ {
+ if (argc < 3)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: missing arguments for \"%s\" "
+ "command"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ "buffer");
+ return WEECHAT_RC_ERROR;
+ }
+
+ error = NULL;
+ number = strtol (argv[2], &error, 10);
+ if (error && !error[0])
+ {
+ ptr_buffer = gui_buffer_search_by_number ((int) number);
+ if (ptr_buffer)
+ gui_buffer_merge (buffer, ptr_buffer);
+ }
+ else
+ {
+ /* invalid number */
+ gui_chat_printf (NULL,
+ _("%sError: incorrect buffer number"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ return WEECHAT_RC_ERROR;
+ }
+
+ return WEECHAT_RC_OK;
+ }
+
+ /* unmerge buffer */
+ if (string_strcasecmp (argv[1], "unmerge") == 0)
+ {
+ number = -1;
+ if (argc >= 3)
+ {
+ error = NULL;
+ number = strtol (argv[2], &error, 10);
+ if (!error || error[0])
+ {
+ /* invalid number */
+ gui_chat_printf (NULL,
+ _("%sError: incorrect buffer number"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ return WEECHAT_RC_ERROR;
+ }
+ }
+ gui_buffer_unmerge (buffer, (int) number);
+
+ return WEECHAT_RC_OK;
+ }
+
/* close buffer */
if (string_strcasecmp (argv[1], "close") == 0)
{
if (argc < 3)
{
- number1 = buffer->number;
- number2 = buffer->number;
+ if (!buffer->plugin)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: WeeChat main buffer can't be "
+ "closed"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ }
+ else
+ {
+ gui_buffer_close (buffer);
+ }
}
else
{
@@ -649,22 +719,26 @@ command_buffer (void *data, struct t_gui_buffer *buffer,
}
if ((number1 < 0) || (number2 < 0) || (number2 < number1))
return WEECHAT_RC_ERROR;
- }
- for (i = number2; i >= number1; i--)
- {
- ptr_buffer = gui_buffer_search_by_number (i);
- if (ptr_buffer)
+
+ for (i = number2; i >= number1; i--)
{
- if (!ptr_buffer->plugin)
- {
- gui_chat_printf (NULL,
- _("%sError: WeeChat main buffer can't be "
- "closed"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
- }
- else
+ for (ptr_buffer = last_gui_buffer; ptr_buffer;
+ ptr_buffer = ptr_buffer->prev_buffer)
{
- gui_buffer_close (ptr_buffer);
+ if (ptr_buffer->number == i)
+ {
+ if (!ptr_buffer->plugin)
+ {
+ gui_chat_printf (NULL,
+ _("%sError: WeeChat main buffer "
+ "can't be closed"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ }
+ else
+ {
+ gui_buffer_close (ptr_buffer);
+ }
+ }
}
}
}
@@ -1763,6 +1837,8 @@ command_input (void *data, struct t_gui_buffer *buffer,
gui_input_set_unread ();
else if (string_strcasecmp (argv[1], "set_unread_current_buffer") == 0)
gui_input_set_unread_current_buffer ();
+ else if (string_strcasecmp (argv[1], "switch_active_buffer") == 0)
+ gui_input_switch_active_buffer ();
else if (string_strcasecmp (argv[1], "insert") == 0)
{
if (argc > 2)
@@ -3877,13 +3953,19 @@ command_init ()
&command_bar, NULL);
hook_command (NULL, "buffer",
N_("manage buffers"),
- N_("[clear [number | -all] | move number | close [n1[-n2]]| "
- "list | notify level | localvar | set property value | "
- "number | name]"),
+ N_("[clear [number | -all] | move number | merge number | "
+ "unmerge [number] | close [n1[-n2]]| list | notify level | "
+ "localvar | set property value | number | name]"),
N_(" clear: clear buffer content (-all for all buffers, "
"number for a buffer, or nothing for current buffer)\n"
" move: move buffer in the list (may be relative, for "
"example -1)\n"
+ " merge: merge current buffer to another buffer (chat "
+ "area will be mix of both buffers)\n"
+ " (by default ctrl-x switches between merged "
+ "buffers)\n"
+ " unmerge: unmerge buffer from other buffers which have "
+ "same number\n"
" close: close buffer (number/range is optional)\n"
" list: list buffers (no parameter implies this list)\n"
" notify: set notify level for current buffer: this "
@@ -3903,15 +3985,19 @@ command_init ()
"\"weechat.look.jump_current_to_previous_buffer\"\n"
" name: jump to buffer by (partial) name\n\n"
"Examples:\n"
- "clear current buffer: /buffer clear\n"
- " clear all buffers: /buffer clear -all\n"
- " move buffer: /buffer move 5\n"
- "close current buffer: /buffer close\n"
- "close buffers 5 to 7: /buffer close 5-7\n"
- " jump to #weechat: /buffer #weechat\n"
- " jump to next buffer: /buffer +1"),
+ " clear current buffer: /buffer clear\n"
+ " clear all buffers: /buffer clear -all\n"
+ " move buffer: /buffer move 5\n"
+ "merge with core buffer: /buffer merge 1\n"
+ " unmerge buffer: /buffer unmerge\n"
+ " close current buffer: /buffer close\n"
+ " close buffers 5 to 7: /buffer close 5-7\n"
+ " jump to #weechat: /buffer #weechat\n"
+ " jump to next buffer: /buffer +1"),
"clear -all|%(buffers_numbers)"
" || move %(buffers_numbers)"
+ " || merge %(buffers_numbers)"
+ " || unmerge %(buffers_numbers)"
" || close"
" || list"
" || notify reset|none|highlight|message|all"
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index a72727b85..a9f73149f 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -91,6 +91,7 @@ struct t_config_option *config_look_paste_max_lines;
struct t_config_option *config_look_prefix[GUI_CHAT_NUM_PREFIXES];
struct t_config_option *config_look_prefix_align;
struct t_config_option *config_look_prefix_align_max;
+struct t_config_option *config_look_prefix_buffer_align;
struct t_config_option *config_look_prefix_suffix;
struct t_config_option *config_look_read_marker;
struct t_config_option *config_look_save_config_on_exit;
@@ -107,6 +108,7 @@ struct t_config_option *config_color_chat;
struct t_config_option *config_color_chat_bg;
struct t_config_option *config_color_chat_time;
struct t_config_option *config_color_chat_time_delimiters;
+struct t_config_option *config_color_chat_prefix_buffer;
struct t_config_option *config_color_chat_prefix[GUI_CHAT_NUM_PREFIXES];
struct t_config_option *config_color_chat_prefix_more;
struct t_config_option *config_color_chat_prefix_suffix;
@@ -1363,6 +1365,12 @@ config_weechat_init_options ()
"prefix_align_max", "integer",
N_("max size for prefix (0 = no max size)"),
NULL, 0, 64, "0", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL);
+ config_look_prefix_buffer_align = config_file_new_option (
+ weechat_config_file, ptr_section,
+ "prefix_buffer_align", "integer",
+ N_("prefix alignment for buffer name, when many buffers are merged "
+ "with same number (none, left, right (default))"),
+ "none|left|right", 0, 0, "right", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL);
config_look_prefix_suffix = config_file_new_option (
weechat_config_file, ptr_section,
"prefix_suffix", "string",
@@ -1453,6 +1461,13 @@ config_weechat_init_options ()
N_("text color for time delimiters"),
NULL, GUI_COLOR_CHAT_TIME_DELIMITERS, 0, "brown", NULL, 0,
NULL, NULL, &config_change_color, NULL, NULL, NULL);
+ config_color_chat_prefix_buffer = config_file_new_option (
+ weechat_config_file, ptr_section,
+ "chat_prefix_buffer", "color",
+ N_("text color for buffer name (before prefix, when many buffers are "
+ "merged with same number)"),
+ NULL, GUI_COLOR_CHAT_PREFIX_BUFFER, 0, "brown", NULL, 0,
+ NULL, NULL, &config_change_color, NULL, NULL, NULL);
config_color_chat_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option (
weechat_config_file, ptr_section,
"chat_prefix_error", "color",
diff --git a/src/core/wee-config.h b/src/core/wee-config.h
index 5b7db86ea..720dfeb7a 100644
--- a/src/core/wee-config.h
+++ b/src/core/wee-config.h
@@ -41,6 +41,13 @@ enum t_config_look_prefix_align
CONFIG_LOOK_PREFIX_ALIGN_RIGHT,
};
+enum t_config_look_prefix_buffer_align
+{
+ CONFIG_LOOK_PREFIX_BUFFER_ALIGN_NONE = 0,
+ CONFIG_LOOK_PREFIX_BUFFER_ALIGN_LEFT,
+ CONFIG_LOOK_PREFIX_BUFFER_ALIGN_RIGHT,
+};
+
enum t_config_look_hotlist_sort
{
CONFIG_LOOK_HOTLIST_SORT_GROUP_TIME_ASC = 0,
@@ -99,6 +106,7 @@ extern struct t_config_option *config_look_paste_max_lines;
extern struct t_config_option *config_look_prefix[];
extern struct t_config_option *config_look_prefix_align;
extern struct t_config_option *config_look_prefix_align_max;
+extern struct t_config_option *config_look_prefix_buffer_align;
extern struct t_config_option *config_look_prefix_suffix;
extern struct t_config_option *config_look_read_marker;
extern struct t_config_option *config_look_save_config_on_exit;
@@ -113,6 +121,7 @@ extern struct t_config_option *config_color_chat;
extern struct t_config_option *config_color_chat_bg;
extern struct t_config_option *config_color_chat_time;
extern struct t_config_option *config_color_chat_time_delimiters;
+extern struct t_config_option *config_color_chat_prefix_buffer;
extern struct t_config_option *config_color_chat_prefix[];
extern struct t_config_option *config_color_chat_prefix_more;
extern struct t_config_option *config_color_chat_prefix_suffix;
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 72ad4ec61..a18883c06 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -41,10 +41,10 @@
#include "wee-string.h"
#include "wee-utf8.h"
#include "wee-util.h"
-#include "../gui/gui-buffer.h"
#include "../gui/gui-chat.h"
#include "../gui/gui-color.h"
#include "../gui/gui-completion.h"
+#include "../gui/gui-line.h"
#include "../plugins/plugin.h"
@@ -1542,12 +1542,13 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
char *prefix_no_color, *message_no_color;
int tags_match, tag_found, i, j;
- if (!line->message || !line->message[0])
+ if (!line->data->message || !line->data->message[0])
return;
- prefix_no_color = (line->prefix) ? gui_color_decode (line->prefix, NULL) : NULL;
+ prefix_no_color = (line->data->prefix) ?
+ gui_color_decode (line->data->prefix, NULL) : NULL;
- message_no_color = gui_color_decode (line->message, NULL);
+ message_no_color = gui_color_decode (line->data->message, NULL);
if (!message_no_color)
{
free (prefix_no_color);
@@ -1574,17 +1575,17 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
if (HOOK_PRINT(ptr_hook, tags_array))
{
/* if there are tags in message printed */
- if (line->tags_array)
+ if (line->data->tags_array)
{
tags_match = 1;
for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++)
{
/* search for tag in message */
tag_found = 0;
- for (j = 0; j < line->tags_count; j++)
+ for (j = 0; j < line->data->tags_count; j++)
{
if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i],
- line->tags_array[j]) != 0)
+ line->data->tags_array[j]) != 0)
{
tag_found = 1;
break;
@@ -1609,11 +1610,12 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
ptr_hook->running = 1;
(void) (HOOK_PRINT(ptr_hook, callback))
- (ptr_hook->callback_data, buffer, line->date,
- line->tags_count, (const char **)line->tags_array,
- (int)line->displayed, (int)line->highlight,
- (HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->prefix,
- (HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->message);
+ (ptr_hook->callback_data, buffer, line->data->date,
+ line->data->tags_count,
+ (const char **)line->data->tags_array,
+ (int)line->data->displayed, (int)line->data->highlight,
+ (HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix,
+ (HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message);
ptr_hook->running = 0;
}
}
diff --git a/src/core/wee-upgrade-file.h b/src/core/wee-upgrade-file.h
index ff865ca05..569839f2f 100644
--- a/src/core/wee-upgrade-file.h
+++ b/src/core/wee-upgrade-file.h
@@ -20,7 +20,7 @@
#ifndef __WEECHAT_UPGRADE_FILE_H
#define __WEECHAT_UPGRADE_FILE_H 1
-#define UPGRADE_SIGNATURE "===== WeeChat Upgrade file v2.1 - binary, do not edit! ====="
+#define UPGRADE_SIGNATURE "===== WeeChat Upgrade file v2.2 - binary, do not edit! ====="
#define UPGRADE_ERROR(msg1, msg2) \
upgrade_file_error(upgrade_file, msg1, msg2, __FILE__, __LINE__)
diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c
index 849aa927e..c7fa6f425 100644
--- a/src/core/wee-upgrade.c
+++ b/src/core/wee-upgrade.c
@@ -36,6 +36,7 @@
#include "../gui/gui-chat.h"
#include "../gui/gui-history.h"
#include "../gui/gui-hotlist.h"
+#include "../gui/gui-line.h"
#include "../gui/gui-nicklist.h"
#include "../gui/gui-window.h"
#include "../plugins/plugin.h"
@@ -43,6 +44,7 @@
struct t_gui_buffer *upgrade_current_buffer = NULL;
struct t_gui_buffer *upgrade_set_current_buffer = NULL;
+int upgrade_last_buffer_number = 1;
int hotlist_reset = 0;
@@ -147,14 +149,15 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file)
}
/* save buffer lines */
- for (ptr_line = ptr_buffer->lines; ptr_line;
+ for (ptr_line = ptr_buffer->own_lines->first_line; ptr_line;
ptr_line = ptr_line->next_line)
{
ptr_infolist = infolist_new ();
if (!ptr_infolist)
return 0;
- if (!gui_buffer_line_add_to_infolist (ptr_infolist,
- ptr_buffer, ptr_line))
+ if (!gui_line_add_to_infolist (ptr_infolist,
+ ptr_buffer->own_lines,
+ ptr_line))
{
infolist_free (ptr_infolist);
return 0;
@@ -289,10 +292,11 @@ upgrade_weechat_read_cb (void *data,
int object_id,
struct t_infolist *infolist)
{
- const char *key, *var_name, *type, *name, *group_name;
+ const char *key, *var_name, *type, *name, *group_name, *plugin_name;
+ const char *buffer_name;
char option_name[64], *option_key, *option_var;
struct t_gui_nick_group *ptr_group;
- struct t_gui_buffer *ptr_buffer;
+ struct t_gui_buffer *ptr_buffer, *ptr_buffer_for_merge;
struct t_gui_line *new_line;
struct timeval creation_time;
void *buf;
@@ -330,6 +334,7 @@ upgrade_weechat_read_cb (void *data,
{
/* create buffer if it was created by a plugin (ie not
WeeChat main buffer) */
+ ptr_buffer_for_merge = last_gui_buffer;
upgrade_current_buffer = gui_buffer_new (
NULL,
infolist_string (infolist, "name"),
@@ -341,6 +346,10 @@ upgrade_weechat_read_cb (void *data,
upgrade_set_current_buffer = upgrade_current_buffer;
upgrade_current_buffer->plugin_name_for_upgrade =
strdup (infolist_string (infolist, "plugin_name"));
+ upgrade_current_buffer->merge_for_upgrade = NULL;
+ if (infolist_integer (infolist, "number") == upgrade_last_buffer_number)
+ upgrade_current_buffer->merge_for_upgrade = ptr_buffer_for_merge;
+ upgrade_last_buffer_number = infolist_integer (infolist, "number");
upgrade_current_buffer->short_name =
(infolist_string (infolist, "short_name")) ?
strdup (infolist_string (infolist, "short_name")) :
@@ -356,7 +365,7 @@ upgrade_weechat_read_cb (void *data,
upgrade_current_buffer->title =
(infolist_string (infolist, "title")) ?
strdup (infolist_string (infolist, "title")) : NULL;
- upgrade_current_buffer->first_line_not_read =
+ upgrade_current_buffer->lines->first_line_not_read =
infolist_integer (infolist, "first_line_not_read");
upgrade_current_buffer->time_for_each_line =
infolist_integer (infolist, "time_for_each_line");
@@ -449,7 +458,7 @@ upgrade_weechat_read_cb (void *data,
/* add line to current buffer */
if (upgrade_current_buffer)
{
- new_line = gui_chat_line_add (
+ new_line = gui_line_add (
upgrade_current_buffer,
infolist_time (infolist, "date"),
infolist_time (infolist, "date_printed"),
@@ -458,10 +467,10 @@ upgrade_weechat_read_cb (void *data,
infolist_string (infolist, "message"));
if (new_line)
{
- new_line->highlight = infolist_integer (infolist, "highlight");
+ new_line->data->highlight = infolist_integer (infolist, "highlight");
}
if (infolist_integer (infolist, "last_read_line"))
- upgrade_current_buffer->last_read_line = new_line;
+ upgrade_current_buffer->lines->last_read_line = new_line;
}
break;
case UPGRADE_WEECHAT_TYPE_NICKLIST:
@@ -519,17 +528,23 @@ upgrade_weechat_read_cb (void *data,
gui_hotlist_clear ();
hotlist_reset = 1;
}
- ptr_buffer = gui_buffer_search_by_number (infolist_integer (infolist, "buffer_number"));
- if (ptr_buffer)
+ plugin_name = infolist_string (infolist, "plugin_name");
+ buffer_name = infolist_string (infolist, "plugin_name");
+ if (plugin_name && buffer_name)
{
- buf = infolist_buffer (infolist, "creation_time", &size);
- if (buf)
+ ptr_buffer = gui_buffer_search_by_name (plugin_name,
+ buffer_name);
+ if (ptr_buffer)
{
- memcpy (&creation_time, buf, size);
- gui_hotlist_add (ptr_buffer,
- infolist_integer (infolist, "priority"),
- &creation_time,
- 1);
+ buf = infolist_buffer (infolist, "creation_time", &size);
+ if (buf)
+ {
+ memcpy (&creation_time, buf, size);
+ gui_hotlist_add (ptr_buffer,
+ infolist_integer (infolist, "priority"),
+ &creation_time,
+ 1);
+ }
}
}
break;
@@ -549,12 +564,21 @@ upgrade_weechat_load ()
{
int rc;
struct t_upgrade_file *upgrade_file;
+ struct t_gui_buffer *ptr_buffer;
upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 0);
rc = upgrade_file_read (upgrade_file, &upgrade_weechat_read_cb, NULL);
if (!hotlist_reset)
gui_hotlist_clear ();
+
+ /* merge buffers */
+ for (ptr_buffer = gui_buffers; ptr_buffer;
+ ptr_buffer = ptr_buffer->next_buffer)
+ {
+ if (ptr_buffer->merge_for_upgrade)
+ gui_buffer_merge (ptr_buffer, ptr_buffer->merge_for_upgrade);
+ }
if (upgrade_set_current_buffer)
{