diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 59 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 31 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 |
3 files changed, 91 insertions, 1 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index c4ace0a42..95fd7eaa5 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -501,7 +501,7 @@ command_buffer_display_localvar (void *data, COMMAND_CALLBACK(buffer) { - struct t_gui_buffer *ptr_buffer, *weechat_buffer; + struct t_gui_buffer *ptr_buffer, *ptr_buffer2, *weechat_buffer; long number, number1, number2; char *error, *value, *pos, *str_number1, *pos_number2; int i, target_buffer, error_main_buffer, num_buffers; @@ -622,6 +622,55 @@ COMMAND_CALLBACK(buffer) return WEECHAT_RC_OK; } + /* swap buffers */ + if (string_strcasecmp (argv[1], "swap") == 0) + { + COMMAND_MIN_ARGS(3, "buffer swap"); + + ptr_buffer = NULL; + ptr_buffer2 = NULL; + + /* first buffer for swap */ + number = strtol (argv[2], &error, 10); + if (error && !error[0]) + ptr_buffer = gui_buffer_search_by_number (number); + else + { + ptr_buffer = gui_buffer_search_by_full_name (argv[2]); + if (!ptr_buffer) + ptr_buffer = gui_buffer_search_by_partial_name (NULL, argv[2]); + } + + /* second buffer for swap */ + if (argc > 3) + { + number = strtol (argv[3], &error, 10); + if (error && !error[0]) + ptr_buffer2 = gui_buffer_search_by_number (number); + else + { + ptr_buffer2 = gui_buffer_search_by_full_name (argv[3]); + if (!ptr_buffer2) + ptr_buffer2 = gui_buffer_search_by_partial_name (NULL, argv[3]); + } + } + else + ptr_buffer2 = buffer; + + if (!ptr_buffer || !ptr_buffer2) + { + /* invalid buffer name/number */ + gui_chat_printf (NULL, + _("%sError: buffer not found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + return WEECHAT_RC_OK; + } + + gui_buffer_swap (ptr_buffer, ptr_buffer2); + + return WEECHAT_RC_OK; + } + /* merge buffer with another number in the list */ if (string_strcasecmp (argv[1], "merge") == 0) { @@ -5439,6 +5488,7 @@ command_init () N_("list" " || clear [<number>|<name>|-merged|-all]" " || move|merge <number>" + " || swap <number1>|<name1> [<number2>|<name2>]" " || unmerge [<number>|-all]" " || close [<n1>[-<n2>]|<name>]" " || notify <level>" @@ -5453,6 +5503,8 @@ command_init () "nothing for current buffer)\n" " move: move buffer in the list (may be relative, for " "example -1)\n" + " swap: swap two buffers (swap with current buffer if " + "only one number/name given)\n" " merge: merge current buffer to another buffer (chat " "area will be mix of both buffers)\n" " (by default ctrl-x switches between merged " @@ -5482,6 +5534,10 @@ command_init () " /buffer clear\n" " move buffer to number 5:\n" " /buffer move 5\n" + " swap buffer 1 with 3:\n" + " /buffer swap 1 3\n" + " swap buffer #weechat with current buffer:\n" + " /buffer swap #weechat\n" " merge with core buffer:\n" " /buffer merge 1\n" " unmerge buffer:\n" @@ -5496,6 +5552,7 @@ command_init () " /buffer +1"), "clear -merged|-all|%(buffers_numbers)|%(buffers_plugins_names)" " || move %(buffers_numbers)" + " || swap %(buffers_numbers)" " || merge %(buffers_numbers)" " || unmerge %(buffers_numbers)|-all" " || close %(buffers_plugins_names)" diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index be418cc5a..168649c4b 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -2495,6 +2495,37 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number) } /* + * gui_buffer_swap: swap two buffers + */ + +void +gui_buffer_swap (struct t_gui_buffer *buffer1, struct t_gui_buffer *buffer2) +{ + struct t_gui_buffer *ptr_buffer1, *ptr_buffer2; + int number1, number2; + + if (!buffer1 || !buffer2) + return; + + /* store pointers and numbers, with number1 < number2 */ + ptr_buffer1 = (buffer1->number < buffer2->number) ? buffer1 : buffer2; + ptr_buffer2 = (buffer1->number < buffer2->number) ? buffer2 : buffer1; + number1 = ptr_buffer1->number; + number2 = ptr_buffer2->number; + + /* swap buffer with itself? nothing to do! */ + if (number1 == number2) + return; + + /* move number2 before number1 */ + gui_buffer_move_to_number (ptr_buffer2, number1); + + /* move number1 before number2 */ + if (number2 > number1 + 1) + gui_buffer_move_to_number (ptr_buffer1, number2); +} + +/* * gui_buffer_merge: merge a buffer to another buffer */ diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index c0f8a5a81..fa6cd810f 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -279,6 +279,8 @@ extern void gui_buffer_set_active_buffer (struct t_gui_buffer *buffer); extern struct t_gui_buffer *gui_buffer_get_next_active_buffer (struct t_gui_buffer *buffer); extern struct t_gui_buffer *gui_buffer_get_previous_active_buffer (struct t_gui_buffer *buffer); extern void gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number); +extern void gui_buffer_swap (struct t_gui_buffer *buffer1, + struct t_gui_buffer *buffer2); extern void gui_buffer_merge (struct t_gui_buffer *buffer, struct t_gui_buffer *target_buffer); extern void gui_buffer_unmerge (struct t_gui_buffer *buffer, int number); |