mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 09:13:14 +02:00
Add 2 new default bar items (input_paste and input_search), used by default input bar
This commit is contained in:
@@ -413,6 +413,7 @@ gui_keyboard_read_cb (void *data)
|
||||
{
|
||||
gui_keyboard_paste_pending = 1;
|
||||
gui_input_draw (gui_current_window->buffer, 1);
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+104
-3
@@ -42,6 +42,7 @@
|
||||
#include "gui-completion.h"
|
||||
#include "gui-filter.h"
|
||||
#include "gui-hotlist.h"
|
||||
#include "gui-keyboard.h"
|
||||
#include "gui-nicklist.h"
|
||||
#include "gui-window.h"
|
||||
|
||||
@@ -49,9 +50,10 @@
|
||||
struct t_gui_bar_item *gui_bar_items = NULL; /* first bar item */
|
||||
struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */
|
||||
char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] =
|
||||
{ "input_prompt", "input_text", "time", "buffer_count", "buffer_plugin",
|
||||
"buffer_name", "buffer_filter", "buffer_nicklist_count", "scroll", "hotlist",
|
||||
"completion", "buffer_title", "buffer_nicklist"
|
||||
{ "input_paste", "input_prompt", "input_search", "input_text", "time",
|
||||
"buffer_count", "buffer_plugin", "buffer_name", "buffer_filter",
|
||||
"buffer_nicklist_count", "scroll", "hotlist", "completion", "buffer_title",
|
||||
"buffer_nicklist"
|
||||
};
|
||||
struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL;
|
||||
struct t_hook *gui_bar_item_timer = NULL;
|
||||
@@ -617,6 +619,45 @@ gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_input_paste: default item for input paste question
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_bar_item_default_input_paste (void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
int max_width, int max_height)
|
||||
{
|
||||
char *text_paste_pending = N_("%sPaste %d lines ? [ctrl-Y] Yes [ctrl-N] No");
|
||||
char *ptr_message, *buf;
|
||||
int length;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) item;
|
||||
(void) max_width;
|
||||
(void) max_height;
|
||||
|
||||
if (!window)
|
||||
return NULL;
|
||||
|
||||
if (window != gui_current_window)
|
||||
return NULL;
|
||||
|
||||
if (!gui_keyboard_paste_pending)
|
||||
return NULL;
|
||||
|
||||
ptr_message = _(text_paste_pending);
|
||||
length = strlen (ptr_message) + 16 + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
snprintf (buf, length, ptr_message,
|
||||
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input_actions))),
|
||||
gui_keyboard_get_paste_lines ());
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_input_prompt: default item for input prompt
|
||||
*/
|
||||
@@ -657,6 +698,50 @@ gui_bar_item_default_input_prompt (void *data, struct t_gui_bar_item *item,
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_input_search: default item for input search status
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_bar_item_default_input_search (void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
int max_width, int max_height)
|
||||
{
|
||||
char *text_search = N_("Text search");
|
||||
char *text_search_exact = N_("Text search (exact)");
|
||||
char *ptr_message, *buf;
|
||||
int length;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) item;
|
||||
(void) max_width;
|
||||
(void) max_height;
|
||||
|
||||
if (!window)
|
||||
window = gui_current_window;
|
||||
|
||||
if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)
|
||||
return NULL;
|
||||
|
||||
ptr_message = (window->buffer->text_search_exact) ?
|
||||
_(text_search_exact) : _(text_search);
|
||||
length = 16 + strlen (ptr_message) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "%s%s",
|
||||
(window->buffer->text_search_found
|
||||
|| !window->buffer->input_buffer
|
||||
|| !window->buffer->input_buffer[0]) ?
|
||||
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input))) :
|
||||
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input_text_not_found))),
|
||||
ptr_message);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_input_text: default item for input text
|
||||
*/
|
||||
@@ -1218,6 +1303,13 @@ gui_bar_item_hook_signal (const char *signal, const char *item)
|
||||
void
|
||||
gui_bar_item_init ()
|
||||
{
|
||||
/* input paste */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PASTE],
|
||||
&gui_bar_item_default_input_paste, NULL);
|
||||
gui_bar_item_hook_signal ("input_paste_pending",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PASTE]);
|
||||
|
||||
/* input prompt */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT],
|
||||
@@ -1225,6 +1317,15 @@ gui_bar_item_init ()
|
||||
gui_bar_item_hook_signal ("input_prompt_changed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]);
|
||||
|
||||
/* input search */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH],
|
||||
&gui_bar_item_default_input_search, NULL);
|
||||
gui_bar_item_hook_signal ("input_search",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH]);
|
||||
gui_bar_item_hook_signal ("input_text_changed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH]);
|
||||
|
||||
/* input text */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT],
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
|
||||
enum t_gui_bar_item_weechat
|
||||
{
|
||||
GUI_BAR_ITEM_INPUT_PROMPT = 0,
|
||||
GUI_BAR_ITEM_INPUT_PASTE = 0,
|
||||
GUI_BAR_ITEM_INPUT_PROMPT,
|
||||
GUI_BAR_ITEM_INPUT_SEARCH,
|
||||
GUI_BAR_ITEM_INPUT_TEXT,
|
||||
GUI_BAR_ITEM_TIME,
|
||||
GUI_BAR_ITEM_BUFFER_COUNT,
|
||||
|
||||
+7
-1
@@ -1670,15 +1670,21 @@ gui_bar_create_default_input ()
|
||||
{
|
||||
/* create input bar */
|
||||
length = 1 /* "[" */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_PASTE])
|
||||
+ 3 /* "],[" */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT])
|
||||
+ 3 /* "],[" */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH])
|
||||
+ 2 /* "]," */
|
||||
+ strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT])
|
||||
+ 1 /* \0 */;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "[%s],%s",
|
||||
snprintf (buf, length, "[%s],[%s],[%s],%s",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PASTE],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]);
|
||||
if (gui_bar_new (NULL, GUI_BAR_DEFAULT_NAME_INPUT,
|
||||
"0", /* hidden */
|
||||
|
||||
@@ -47,6 +47,16 @@
|
||||
char *gui_input_clipboard = NULL; /* clipboard content */
|
||||
|
||||
|
||||
/*
|
||||
* gui_input_paste_pending_signal: send signal "input_paste_pending"
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_paste_pending_signal ()
|
||||
{
|
||||
hook_signal_send ("input_paste_pending", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_prompt_changed_signal: send signal "input_prompt_changed"
|
||||
*/
|
||||
@@ -77,6 +87,16 @@ gui_input_text_cursor_moved_signal ()
|
||||
hook_signal_send ("input_text_cursor_moved", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_search_signal: send signal "input_search"
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_search_signal ()
|
||||
{
|
||||
hook_signal_send ("input_search", WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_optimize_size: optimize input buffer size by adding
|
||||
* or deleting data block (predefined size)
|
||||
@@ -334,7 +354,10 @@ gui_input_return ()
|
||||
if (gui_current_window->buffer->input)
|
||||
{
|
||||
if (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
|
||||
{
|
||||
gui_window_search_stop (gui_current_window);
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
else if (gui_current_window->buffer->input_buffer_size > 0)
|
||||
{
|
||||
gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0';
|
||||
@@ -539,6 +562,7 @@ gui_input_search_text ()
|
||||
gui_window_search_restart (gui_current_window);
|
||||
gui_buffer_ask_input_refresh (gui_current_window->buffer, 1);
|
||||
}
|
||||
gui_input_search_signal ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ extern char *gui_input_clipboard;
|
||||
|
||||
/* input functions */
|
||||
|
||||
extern void gui_input_paste_pending_signal ();
|
||||
extern void gui_input_prompt_changed_signal ();
|
||||
extern void gui_input_text_changed_signal ();
|
||||
extern void gui_input_search_signal ();
|
||||
extern void gui_input_optimize_size (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_init_color_mask (struct t_gui_buffer *buffer);
|
||||
extern void gui_input_move (struct t_gui_buffer *buffer, char *target,
|
||||
|
||||
@@ -635,6 +635,7 @@ void
|
||||
gui_keyboard_paste_accept ()
|
||||
{
|
||||
gui_keyboard_paste_pending = 0;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
|
||||
|
||||
@@ -647,6 +648,7 @@ gui_keyboard_paste_cancel ()
|
||||
{
|
||||
gui_keyboard_buffer_reset ();
|
||||
gui_keyboard_paste_pending = 0;
|
||||
gui_input_paste_pending_signal ();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user