1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

fset: add option fset.look.unmark_after_action

This commit is contained in:
Sébastien Helleu
2017-06-01 21:44:07 +02:00
parent 6be32fdce5
commit 7336c93270
5 changed files with 129 additions and 58 deletions
+21 -58
View File
@@ -81,8 +81,7 @@ fset_command_fset (const void *pointer, void *data,
struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
int num_options, line, append, use_mute, add_quotes, input_pos, value, i;
char str_input[4096], str_pos[32];
int num_options, line, append, value, i;
struct t_fset_option *ptr_fset_option;
struct t_config_option *ptr_option;
@@ -168,12 +167,12 @@ fset_command_fset (const void *pointer, void *data,
if (argc < 3)
WEECHAT_COMMAND_ERROR;
if (weechat_strcasecmp (argv[2], "end") == 0)
value = weechat_arraylist_size (fset_options) - 1;
line = weechat_arraylist_size (fset_options) - 1;
else
value = fset_command_get_int_arg (argc, argv, 2, -1);
if (value < 0)
line = fset_command_get_int_arg (argc, argv, 2, -1);
if (line < 0)
WEECHAT_COMMAND_ERROR;
fset_buffer_set_current_line (value);
fset_buffer_set_current_line (line);
fset_buffer_check_line_outside_window ();
}
return WEECHAT_RC_OK;
@@ -196,12 +195,13 @@ fset_command_fset (const void *pointer, void *data,
fset_option_toggle_value (ptr_fset_option, ptr_option);
}
}
if (weechat_config_boolean (fset_config_look_unmark_after_action))
fset_option_unmark_all ();
}
else
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
fset_option_toggle_value (ptr_fset_option, ptr_option);
fset_option_toggle_value (ptr_fset_option, ptr_option);
}
return WEECHAT_RC_OK;
}
@@ -225,14 +225,13 @@ fset_command_fset (const void *pointer, void *data,
fset_option_add_value (ptr_fset_option, ptr_option, value);
}
}
if (weechat_config_boolean (fset_config_look_unmark_after_action))
fset_option_unmark_all ();
}
else
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
{
fset_option_add_value (ptr_fset_option, ptr_option, value);
}
fset_option_add_value (ptr_fset_option, ptr_option, value);
}
return WEECHAT_RC_OK;
}
@@ -252,14 +251,13 @@ fset_command_fset (const void *pointer, void *data,
fset_option_reset_value (ptr_fset_option, ptr_option);
}
}
if (weechat_config_boolean (fset_config_look_unmark_after_action))
fset_option_unmark_all ();
}
else
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
{
fset_option_reset_value (ptr_fset_option, ptr_option);
}
fset_option_reset_value (ptr_fset_option, ptr_option);
}
return WEECHAT_RC_OK;
}
@@ -279,14 +277,13 @@ fset_command_fset (const void *pointer, void *data,
fset_option_unset_value (ptr_fset_option, ptr_option);
}
}
if (weechat_config_boolean (fset_config_look_unmark_after_action))
fset_option_unmark_all ();
}
else
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
{
fset_option_unset_value (ptr_fset_option, ptr_option);
}
fset_option_unset_value (ptr_fset_option, ptr_option);
}
return WEECHAT_RC_OK;
}
@@ -295,50 +292,16 @@ fset_command_fset (const void *pointer, void *data,
|| (weechat_strcasecmp (argv[1], "-append") == 0))
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
{
append = (weechat_strcasecmp (argv[1], "-append") == 0) ? 1 : 0;
use_mute = weechat_config_boolean (fset_config_look_use_mute);
add_quotes = (ptr_fset_option->value
&& (ptr_fset_option->type == FSET_OPTION_TYPE_STRING)) ? 1 : 0;
snprintf (str_input, sizeof (str_input),
"%s/set %s %s%s%s",
(use_mute) ? "/mute " : "",
ptr_fset_option->name,
(add_quotes) ? "\"" : "",
(ptr_fset_option->value) ? ptr_fset_option->value : FSET_OPTION_VALUE_NULL,
(add_quotes) ? "\"" : "");
weechat_buffer_set (buffer, "input", str_input);
input_pos = ((use_mute) ? 6 : 0) + /* "/mute " */
5 + /* "/set " */
weechat_utf8_strlen (ptr_fset_option->name) + 1 +
((add_quotes) ? 1 : 0) +
((append) ? weechat_utf8_strlen (
(ptr_fset_option->value) ?
ptr_fset_option->value : FSET_OPTION_VALUE_NULL) : 0);
snprintf (str_pos, sizeof (str_pos), "%d", input_pos);
weechat_buffer_set (buffer, "input_pos", str_pos);
}
append = (weechat_strcasecmp (argv[1], "-append") == 0) ? 1 : 0;
fset_option_set (ptr_fset_option, ptr_option, buffer, append);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "-mark") == 0)
{
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option && ptr_option)
{
value = fset_command_get_int_arg (argc, argv, 2, 1);
ptr_fset_option->marked ^= 1;
fset_option_count_marked += (ptr_fset_option->marked) ? 1 : -1;
num_options = weechat_arraylist_size (fset_options);
line = fset_buffer_selected_line + value;
if (line < 0)
line = 0;
else if (line >= num_options)
line = num_options - 1;
fset_buffer_set_current_line (line);
fset_buffer_check_line_outside_window ();
}
value = fset_command_get_int_arg (argc, argv, 2, 1);
fset_option_toggle_mark (ptr_fset_option, ptr_option, value);
return WEECHAT_RC_OK;
}
+9
View File
@@ -37,6 +37,7 @@ struct t_config_option *fset_config_look_condition_catch_set;
struct t_config_option *fset_config_look_help_bar;
struct t_config_option *fset_config_look_marked_string;
struct t_config_option *fset_config_look_show_plugin_description;
struct t_config_option *fset_config_look_unmark_after_action;
struct t_config_option *fset_config_look_unmarked_string;
struct t_config_option *fset_config_look_use_keys;
struct t_config_option *fset_config_look_use_mute;
@@ -249,6 +250,14 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_show_plugin_description_cb, NULL, NULL,
NULL, NULL, NULL);
fset_config_look_unmark_after_action = weechat_config_new_option (
fset_config_file, ptr_section,
"unmark_after_action", "boolean",
N_("unmark all options after an action on marked options"),
NULL, 0, 0, "on", NULL, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
fset_config_look_unmarked_string = weechat_config_new_option (
fset_config_file, ptr_section,
"unmarked_string", "string",
+1
View File
@@ -28,6 +28,7 @@ extern struct t_config_option *fset_config_look_condition_catch_set;
extern struct t_config_option *fset_config_look_help_bar;
extern struct t_config_option *fset_config_look_marked_string;
extern struct t_config_option *fset_config_look_show_plugin_description;
extern struct t_config_option *fset_config_look_unmark_after_action;
extern struct t_config_option *fset_config_look_unmarked_string;
extern struct t_config_option *fset_config_look_use_keys;
extern struct t_config_option *fset_config_look_use_mute;
+90
View File
@@ -941,6 +941,96 @@ fset_option_unset_value (struct t_fset_option *fset_option,
weechat_config_option_unset (option);
}
/*
* Sets the value of an option.
*/
void
fset_option_set (struct t_fset_option *fset_option,
struct t_config_option *option,
struct t_gui_buffer *buffer,
int append)
{
int use_mute, add_quotes, input_pos;
char str_input[4096], str_pos[32];
/* make C compiler happy */
(void) option;
if (!fset_option)
return;
use_mute = weechat_config_boolean (fset_config_look_use_mute);
add_quotes = (fset_option->value
&& (fset_option->type == FSET_OPTION_TYPE_STRING)) ? 1 : 0;
snprintf (str_input, sizeof (str_input),
"%s/set %s %s%s%s",
(use_mute) ? "/mute " : "",
fset_option->name,
(add_quotes) ? "\"" : "",
(fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL,
(add_quotes) ? "\"" : "");
weechat_buffer_set (buffer, "input", str_input);
input_pos = ((use_mute) ? 6 : 0) + /* "/mute " */
5 + /* "/set " */
weechat_utf8_strlen (fset_option->name) + 1 +
((add_quotes) ? 1 : 0) +
((append) ? weechat_utf8_strlen (
(fset_option->value) ?
fset_option->value : FSET_OPTION_VALUE_NULL) : 0);
snprintf (str_pos, sizeof (str_pos), "%d", input_pos);
weechat_buffer_set (buffer, "input_pos", str_pos);
}
/*
* Marks/unmarks an option.
*/
void
fset_option_toggle_mark (struct t_fset_option *fset_option,
struct t_config_option *option,
int value)
{
int num_options, line;
/* make C compiler happy */
(void) option;
if (!fset_option)
return;
fset_option->marked ^= 1;
fset_option_count_marked += (fset_option->marked) ? 1 : -1;
num_options = weechat_arraylist_size (fset_options);
line = fset_buffer_selected_line + value;
if (line < 0)
line = 0;
else if (line >= num_options)
line = num_options - 1;
fset_buffer_set_current_line (line);
fset_buffer_check_line_outside_window ();
}
/*
* Unmarks all options.
*/
void
fset_option_unmark_all ()
{
int num_options, i;
struct t_fset_option *ptr_fset_option;
num_options = weechat_arraylist_size (fset_options);
for (i = 0; i < num_options; i++)
{
ptr_fset_option = weechat_arraylist_get (fset_options, i);
ptr_fset_option->marked = 0;
}
fset_option_count_marked = 0;
fset_buffer_refresh (0);
}
/*
* Callback for config option changed.
*/
+8
View File
@@ -77,6 +77,14 @@ extern void fset_option_reset_value (struct t_fset_option *fset_option,
struct t_config_option *option);
extern void fset_option_unset_value (struct t_fset_option *fset_option,
struct t_config_option *option);
extern void fset_option_set (struct t_fset_option *fset_option,
struct t_config_option *option,
struct t_gui_buffer *buffer,
int append);
extern void fset_option_toggle_mark (struct t_fset_option *fset_option,
struct t_config_option *option,
int value);
extern void fset_option_unmark_all ();
extern int fset_option_config_cb (const void *pointer,
void *data,
const char *option,