mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 11:13:12 +02:00
buffer: add property input_get_any_user_data in buffer (issue #2066)
This allows buffers to get any user input, including commands, that are sent to the buffer callback instead of being executed on the buffer.
This commit is contained in:
+89
-17
@@ -131,7 +131,13 @@ COMMAND_CALLBACK(allbuf)
|
||||
{
|
||||
ptr_buffer = (struct t_gui_buffer *)arraylist_get (all_buffers, i);
|
||||
if (gui_buffer_valid (ptr_buffer))
|
||||
(void) input_data (ptr_buffer, argv_eol[1], NULL, 0);
|
||||
{
|
||||
(void) input_data (ptr_buffer,
|
||||
argv_eol[1],
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
}
|
||||
|
||||
arraylist_free (all_buffers);
|
||||
@@ -1642,7 +1648,11 @@ COMMAND_CALLBACK(color)
|
||||
if (string_strcmp (argv[1], "-o") == 0)
|
||||
{
|
||||
gui_color_info_term_colors (str_color, sizeof (str_color));
|
||||
(void) input_data (buffer, str_color, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
str_color,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -1837,7 +1847,11 @@ COMMAND_CALLBACK(command)
|
||||
{
|
||||
for (i = 0; commands[i]; i++)
|
||||
{
|
||||
(void) input_data (buffer, commands[i], NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
commands[i],
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
string_free_split_command (commands);
|
||||
}
|
||||
@@ -2221,7 +2235,11 @@ COMMAND_CALLBACK(debug)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "time");
|
||||
gettimeofday (&time_start, NULL);
|
||||
(void) input_data (buffer, argv_eol[2], NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
argv_eol[2],
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
gettimeofday (&time_end, NULL);
|
||||
debug_display_time_elapsed (&time_start, &time_end, argv_eol[2], 1);
|
||||
return WEECHAT_RC_OK;
|
||||
@@ -2418,7 +2436,11 @@ COMMAND_CALLBACK(eval)
|
||||
options);
|
||||
if (result)
|
||||
{
|
||||
(void) input_data (buffer, result, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
result,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
free (result);
|
||||
}
|
||||
else
|
||||
@@ -2441,7 +2463,11 @@ COMMAND_CALLBACK(eval)
|
||||
result = eval_expression (ptr_args, pointers, NULL, options);
|
||||
if (result)
|
||||
{
|
||||
(void) input_data (buffer, result, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
result,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
free (result);
|
||||
}
|
||||
else
|
||||
@@ -3638,7 +3664,13 @@ COMMAND_CALLBACK(input)
|
||||
gui_input_insert (buffer, argv_eol[2]);
|
||||
}
|
||||
else if (string_strcmp (argv[1], "send") == 0)
|
||||
(void) input_data (buffer, argv_eol[2], NULL, 0);
|
||||
{
|
||||
(void) input_data (buffer,
|
||||
argv_eol[2],
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
else if (string_strcmp (argv[1], "undo") == 0)
|
||||
gui_input_undo (buffer);
|
||||
else if (string_strcmp (argv[1], "redo") == 0)
|
||||
@@ -3679,10 +3711,22 @@ COMMAND_CALLBACK(input)
|
||||
gui_hotlist_restore_all_buffers ();
|
||||
/* since WeeChat 3.8: "/buffer set unread" */
|
||||
else if (string_strcmp (argv[1], "set_unread_current_buffer") == 0)
|
||||
(void) input_data (buffer, "/buffer set unread", NULL, 0);
|
||||
{
|
||||
(void) input_data (buffer,
|
||||
"/buffer set unread",
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
/* since WeeChat 3.8: "/allbuf /buffer set unread" */
|
||||
else if (string_strcmp (argv[1], "set_unread") == 0)
|
||||
(void) input_data (buffer, "/allbuf /buffer set unread", NULL, 0);
|
||||
{
|
||||
(void) input_data (buffer,
|
||||
"/allbuf /buffer set unread",
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
/* since WeeChat 3.8: "/buffer switch" */
|
||||
else if (string_strcmp (argv[1], "switch_active_buffer") == 0)
|
||||
gui_buffer_switch_active_buffer (buffer);
|
||||
@@ -5019,7 +5063,11 @@ command_plugin_list_input (struct t_gui_buffer *buffer,
|
||||
|
||||
if (send_to_buffer)
|
||||
{
|
||||
(void) input_data (buffer, *buf, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
*buf,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5775,7 +5823,8 @@ command_repeat_exec (struct t_command_repeat *command_repeat)
|
||||
(void) input_data (ptr_buffer,
|
||||
cmd_eval,
|
||||
command_repeat->commands_allowed,
|
||||
0); /* split_newline */
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
free (cmd_eval);
|
||||
}
|
||||
|
||||
@@ -7078,7 +7127,11 @@ command_upgrade_display (struct t_gui_buffer *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
(void) input_data (buffer, string, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
string,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -7327,7 +7380,11 @@ COMMAND_CALLBACK(uptime)
|
||||
minutes,
|
||||
seconds,
|
||||
str_first_start);
|
||||
(void) input_data (buffer, string, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
string,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
else if ((argc >= 2) && (string_strcmp (argv[1], "-ol") == 0))
|
||||
{
|
||||
@@ -7340,7 +7397,11 @@ COMMAND_CALLBACK(uptime)
|
||||
minutes,
|
||||
seconds,
|
||||
util_get_time_string (&weechat_first_start_time));
|
||||
(void) input_data (buffer, string, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
string,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -7391,7 +7452,11 @@ command_version_display (struct t_gui_buffer *buffer,
|
||||
_("compiled on"),
|
||||
version_get_compilation_date (),
|
||||
version_get_compilation_time ());
|
||||
(void) input_data (buffer, string, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
string,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -7401,7 +7466,11 @@ command_version_display (struct t_gui_buffer *buffer,
|
||||
"compiled on",
|
||||
version_get_compilation_date (),
|
||||
version_get_compilation_time ());
|
||||
(void) input_data (buffer, string, NULL, 0);
|
||||
(void) input_data (buffer,
|
||||
string,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -9605,7 +9674,10 @@ command_exec_list (const char *command_list)
|
||||
if (command_eval)
|
||||
{
|
||||
(void) input_data (gui_buffer_search_main (),
|
||||
command_eval, NULL, 0);
|
||||
command_eval,
|
||||
NULL,
|
||||
0, /* split_newline */
|
||||
0); /* user_data */
|
||||
free (command_eval);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-5
@@ -246,7 +246,7 @@ end:
|
||||
|
||||
int
|
||||
input_data (struct t_gui_buffer *buffer, const char *data,
|
||||
const char *commands_allowed, int split_newline)
|
||||
const char *commands_allowed, int split_newline, int user_data)
|
||||
{
|
||||
char *pos, *buf, str_buffer[128], *new_data, *buffer_full_name;
|
||||
const char *ptr_data, *ptr_data_for_buffer;
|
||||
@@ -331,8 +331,20 @@ input_data (struct t_gui_buffer *buffer, const char *data,
|
||||
else
|
||||
{
|
||||
/* input string is a command */
|
||||
rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data,
|
||||
commands_allowed);
|
||||
if (user_data && buffer->input_get_any_user_data)
|
||||
{
|
||||
/*
|
||||
* if data is sent from user and buffer catches any user data:
|
||||
* send it to callback
|
||||
*/
|
||||
input_exec_data (buffer, ptr_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* execute command on buffer */
|
||||
rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data,
|
||||
commands_allowed);
|
||||
}
|
||||
}
|
||||
|
||||
if (pos)
|
||||
@@ -384,7 +396,8 @@ input_data_timer_cb (const void *pointer, void *data, int remaining_calls)
|
||||
ptr_buffer,
|
||||
timer_args[1],
|
||||
timer_args[2],
|
||||
(string_strcmp (timer_args[3], "1") == 0) ? 1 : 0);
|
||||
(string_strcmp (timer_args[3], "1") == 0) ? 1 : 0,
|
||||
0); /* user_data */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +430,7 @@ input_data_delayed (struct t_gui_buffer *buffer, const char *data,
|
||||
char **timer_args, *new_commands_allowed;
|
||||
|
||||
if (delay < 1)
|
||||
return input_data (buffer, data, commands_allowed, split_newline);
|
||||
return input_data (buffer, data, commands_allowed, split_newline, 0);
|
||||
|
||||
timer_args = malloc (4 * sizeof (*timer_args));
|
||||
if (!timer_args)
|
||||
|
||||
@@ -31,7 +31,8 @@ extern int input_exec_command (struct t_gui_buffer *buffer,
|
||||
const char *string,
|
||||
const char *commands_allowed);
|
||||
extern int input_data (struct t_gui_buffer *buffer, const char *data,
|
||||
const char *commands_allowed, int split_newline);
|
||||
const char *commands_allowed, int split_newline,
|
||||
int user_data);
|
||||
extern int input_data_delayed (struct t_gui_buffer *buffer, const char *data,
|
||||
const char *commands_allowed, int split_newline,
|
||||
long delay);
|
||||
|
||||
@@ -228,7 +228,7 @@ signal_exec_command (int signal_index, const char *command)
|
||||
if (signal_upper)
|
||||
free (signal_upper);
|
||||
(void) input_data (gui_buffer_search_main (),
|
||||
command_eval, NULL, 0);
|
||||
command_eval, NULL, 0, 0);
|
||||
free (command_eval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,6 +540,8 @@ upgrade_weechat_read_buffer (struct t_infolist *infolist)
|
||||
|
||||
/* input */
|
||||
ptr_buffer->input = infolist_integer (infolist, "input");
|
||||
ptr_buffer->input_get_any_user_data =
|
||||
infolist_integer (infolist, "input_get_any_user_data");
|
||||
ptr_buffer->input_get_unknown_commands =
|
||||
infolist_integer (infolist, "input_get_unknown_commands");
|
||||
ptr_buffer->input_get_empty =
|
||||
|
||||
+32
-4
@@ -101,7 +101,7 @@ char *gui_buffer_properties_get_integer[] =
|
||||
"nicklist_display_groups", "nicklist_count", "nicklist_visible_count",
|
||||
"nicklist_groups_count", "nicklist_groups_visible_count",
|
||||
"nicklist_nicks_count", "nicklist_nicks_visible_count",
|
||||
"input", "input_get_unknown_commands",
|
||||
"input", "input_get_any_user_data", "input_get_unknown_commands",
|
||||
"input_get_empty", "input_multiline", "input_size", "input_length",
|
||||
"input_pos", "input_1st_display", "num_history", "text_search",
|
||||
"text_search_direction", "text_search_exact", "text_search_regex",
|
||||
@@ -128,8 +128,8 @@ char *gui_buffer_properties_set[] =
|
||||
"highlight_words_del", "highlight_disable_regex", "highlight_regex",
|
||||
"highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks",
|
||||
"hotlist_max_level_nicks_add", "hotlist_max_level_nicks_del",
|
||||
"input", "input_pos", "input_get_unknown_commands", "input_get_empty",
|
||||
"input_multiline",
|
||||
"input", "input_pos", "input_get_any_user_data", "input_get_unknown_commands",
|
||||
"input_get_empty", "input_multiline",
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -898,6 +898,7 @@ gui_buffer_new_props_with_id (long long id,
|
||||
new_buffer->input_callback = input_callback;
|
||||
new_buffer->input_callback_pointer = input_callback_pointer;
|
||||
new_buffer->input_callback_data = input_callback_data;
|
||||
new_buffer->input_get_any_user_data = 0;
|
||||
new_buffer->input_get_unknown_commands = 0;
|
||||
new_buffer->input_get_empty = 0;
|
||||
new_buffer->input_multiline = 0;
|
||||
@@ -1470,6 +1471,8 @@ gui_buffer_get_integer (struct t_gui_buffer *buffer, const char *property)
|
||||
return buffer->nicklist_nicks_visible_count;
|
||||
else if (strcmp (property, "input") == 0)
|
||||
return buffer->input;
|
||||
else if (strcmp (property, "input_get_any_user_data") == 0)
|
||||
return buffer->input_get_any_user_data;
|
||||
else if (strcmp (property, "input_get_unknown_commands") == 0)
|
||||
return buffer->input_get_unknown_commands;
|
||||
else if (strcmp (property, "input_get_empty") == 0)
|
||||
@@ -2246,6 +2249,20 @@ gui_buffer_remove_hotlist_max_level_nicks (struct t_gui_buffer *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets flag "input_get_any_user_data" for a buffer.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_buffer_set_input_get_any_user_data (struct t_gui_buffer *buffer,
|
||||
int input_get_any_user_data)
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
buffer->input_get_any_user_data = (input_get_any_user_data) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets flag "input_get_unknown_commands" for a buffer.
|
||||
*/
|
||||
@@ -2258,8 +2275,8 @@ gui_buffer_set_input_get_unknown_commands (struct t_gui_buffer *buffer,
|
||||
return;
|
||||
|
||||
buffer->input_get_unknown_commands = (input_get_unknown_commands) ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Sets flag "input_get_empty" for a buffer.
|
||||
*/
|
||||
@@ -2676,6 +2693,13 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
if (error && !error[0])
|
||||
gui_input_set_pos (buffer, number);
|
||||
}
|
||||
else if (strcmp (property, "input_get_any_user_data") == 0)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
if (error && !error[0])
|
||||
gui_buffer_set_input_get_any_user_data (buffer, number);
|
||||
}
|
||||
else if (strcmp (property, "input_get_unknown_commands") == 0)
|
||||
{
|
||||
error = NULL;
|
||||
@@ -5171,6 +5195,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data,
|
||||
HDATA_VAR(struct t_gui_buffer, input_callback, POINTER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_callback_pointer, POINTER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_callback_data, POINTER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_get_any_user_data, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_get_unknown_commands, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_get_empty, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, input_multiline, INTEGER, 0, NULL, NULL);
|
||||
@@ -5386,6 +5411,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "input", buffer->input))
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "input_get_any_user_data", buffer->input_get_any_user_data))
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "input_get_unknown_commands", buffer->input_get_unknown_commands))
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "input_get_empty", buffer->input_get_empty))
|
||||
@@ -5623,6 +5650,7 @@ gui_buffer_print_log ()
|
||||
log_printf (" input_callback. . . . . : %p", ptr_buffer->input_callback);
|
||||
log_printf (" input_callback_pointer. : %p", ptr_buffer->input_callback_pointer);
|
||||
log_printf (" input_callback_data . . : %p", ptr_buffer->input_callback_data);
|
||||
log_printf (" input_get_any_user_data : %d", ptr_buffer->input_get_any_user_data);
|
||||
log_printf (" input_get_unknown_cmd . : %d", ptr_buffer->input_get_unknown_commands);
|
||||
log_printf (" input_get_empty . . . . : %d", ptr_buffer->input_get_empty);
|
||||
log_printf (" input_multiline . . . . : %d", ptr_buffer->input_multiline);
|
||||
|
||||
@@ -186,6 +186,7 @@ struct t_gui_buffer
|
||||
const void *input_callback_pointer; /* pointer for callback */
|
||||
void *input_callback_data; /* data for callback */
|
||||
/* to this buffer */
|
||||
int input_get_any_user_data; /* get any user data, including cmds */
|
||||
int input_get_unknown_commands; /* 1 if unknown commands are sent to */
|
||||
/* input_callback */
|
||||
int input_get_empty; /* 1 if empty input is sent to */
|
||||
|
||||
+1
-1
@@ -333,7 +333,7 @@ gui_input_send_data_to_buffer (struct t_gui_buffer *buffer, char *data)
|
||||
gui_input_text_changed_modifier_and_signal (buffer,
|
||||
0, /* save undo */
|
||||
1); /* stop completion */
|
||||
(void) input_data (buffer, data, NULL, 1);
|
||||
(void) input_data (buffer, data, NULL, 1, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+2
-2
@@ -2161,7 +2161,7 @@ gui_key_focus_command (const char *key, int context,
|
||||
command,
|
||||
ptr_buffer->full_name);
|
||||
}
|
||||
(void) input_data (ptr_buffer, command, NULL, 0);
|
||||
(void) input_data (ptr_buffer, command, NULL, 0, 0);
|
||||
free (command);
|
||||
}
|
||||
}
|
||||
@@ -2537,7 +2537,7 @@ gui_key_pressed (const char *key_str)
|
||||
for (i = 0; commands[i]; i++)
|
||||
{
|
||||
(void) input_data (gui_current_window->buffer,
|
||||
commands[i], NULL, 0);
|
||||
commands[i], NULL, 0, 0);
|
||||
}
|
||||
string_free_split (commands);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user