summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-06-01 20:53:17 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-06-25 16:35:27 +0200
commitb2373ffba7bbc13cc6eb2f365ec5badb6ff74d1a (patch)
treeefe4fb52c43565f2d88dde62e9978e929c9e1d76
parent2671a72da3c94684bd458c83aa314d0816a79113 (diff)
downloadweechat-b2373ffba7bbc13cc6eb2f365ec5badb6ff74d1a.zip
fset: add mark on options to run an action on multiple options
-rw-r--r--src/plugins/fset/fset-buffer.c73
-rw-r--r--src/plugins/fset/fset-command.c273
-rw-r--r--src/plugins/fset/fset-config.c59
-rw-r--r--src/plugins/fset/fset-config.h4
-rw-r--r--src/plugins/fset/fset-mouse.c1
-rw-r--r--src/plugins/fset/fset-option.c88
-rw-r--r--src/plugins/fset/fset-option.h12
7 files changed, 417 insertions, 93 deletions
diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c
index 4f8c89746..bc3b92c23 100644
--- a/src/plugins/fset/fset-buffer.c
+++ b/src/plugins/fset/fset-buffer.c
@@ -45,21 +45,30 @@ void
fset_buffer_set_title ()
{
int num_options;
- char str_title[1024];
+ char str_marked[32], str_title[1024];
if (!fset_buffer)
return;
+ str_marked[0] = '\0';
+ if (fset_option_count_marked > 0)
+ {
+ snprintf (str_marked, sizeof (str_marked),
+ " (*: %d)",
+ fset_option_count_marked);
+ }
+
num_options = weechat_arraylist_size (fset_options);
snprintf (str_title, sizeof (str_title),
- _("%s | %d/%d | "
+ _("%s | %d/%d%s | "
"Key(input): alt+'-'(-)=subtract 1, alt+'+'(+)=add 1, "
"alt+f,alt+r(r)=reset, alf+f,alt+u(u)=unset, "
"alt+enter(s)=set, alt+f,alt+a(a)=append"),
(fset_option_filter) ? fset_option_filter : "*",
(num_options > 0) ? fset_buffer_selected_line + 1 : 0,
- num_options);
+ num_options,
+ str_marked);
weechat_buffer_set (fset_buffer, "title", str_title);
}
@@ -104,7 +113,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option)
const char *ptr_field, *ptr_parent_value;
int selected_line;
int default_value_undef, value_undef, value_changed;
- int type, add_quotes, add_quotes_parent;
+ int type, marked, add_quotes, add_quotes_parent;
struct t_config_option *ptr_option_color_value;
selected_line = (y == fset_buffer_selected_line) ? 1 : 0;
@@ -435,6 +444,30 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option)
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"string_values", str_field);
+ /* marked */
+ marked = weechat_hdata_integer (fset_hdata_fset_option,
+ fset_option, "marked");
+ snprintf (str_field, sizeof (str_field),
+ "%s",
+ (marked) ?
+ weechat_config_string (fset_config_look_marked_string) :
+ weechat_config_string (fset_config_look_unmarked_string));
+ weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
+ "__marked", str_field);
+ snprintf (str_field, sizeof (str_field),
+ "%s%s",
+ (marked) ?
+ weechat_color (weechat_config_string (fset_config_color_marked[selected_line])) :
+ weechat_color (weechat_config_string (fset_config_color_unmarked[selected_line])),
+ (marked) ?
+ weechat_config_string (fset_config_look_marked_string) :
+ weechat_config_string (fset_config_look_unmarked_string));
+ weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
+ "_marked", str_field);
+ fset_buffer_fills_field (str_field, sizeof (str_field), "marked", 2);
+ weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
+ "marked", str_field);
+
/* set other variables depending on the value */
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"default_value_undef",
@@ -502,9 +535,12 @@ fset_buffer_set_current_line (int line)
old_line = fset_buffer_selected_line;
fset_buffer_selected_line = line;
- fset_buffer_display_line (
- old_line,
- weechat_arraylist_get (fset_options, old_line));
+ if (old_line != fset_buffer_selected_line)
+ {
+ fset_buffer_display_line (
+ old_line,
+ weechat_arraylist_get (fset_options, old_line));
+ }
fset_buffer_display_line (
fset_buffer_selected_line,
weechat_arraylist_get (fset_options, fset_buffer_selected_line));
@@ -642,6 +678,7 @@ fset_buffer_input_cb (const void *pointer, void *data,
{ "u", "unset" },
{ "s", "set" },
{ "a", "append" },
+ { ",", "mark 1" },
{ NULL, NULL } };
char str_command[64];
int i;
@@ -699,6 +736,7 @@ fset_buffer_close_cb (const void *pointer, void *data,
fset_buffer = NULL;
fset_buffer_selected_line = 0;
weechat_arraylist_clear (fset_options);
+ fset_option_count_marked = 0;
return WEECHAT_RC_OK;
}
@@ -729,15 +767,18 @@ fset_buffer_set_callbacks ()
void
fset_buffer_set_keys ()
{
- char *keys[][2] = { { "meta- ", "toggle" },
- { "meta--", "add -1" },
- { "meta-+", "add 1" },
- { "meta-fmeta-r", "reset" },
- { "meta-fmeta-u", "unset" },
- { "meta-ctrl-J", "set" },
- { "meta-ctrl-M", "set" },
- { "meta-fmeta-a", "append" },
- { NULL, NULL } };
+ char *keys[][2] = { { "meta- ", "toggle" },
+ { "meta--", "add -1" },
+ { "meta-+", "add 1" },
+ { "meta-fmeta-r", "reset" },
+ { "meta-fmeta-u", "unset" },
+ { "meta-ctrl-J", "set" },
+ { "meta-ctrl-M", "set" },
+ { "meta-fmeta-a", "append" },
+ { "meta-,", "mark 1" },
+ { "meta2-a", "mark -1" },
+ { "meta2-b", "mark 1" },
+ { NULL, NULL } };
char str_key[64], str_command[64];
int i;
diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c
index ae095d6fa..7bf1aa818 100644
--- a/src/plugins/fset/fset-command.c
+++ b/src/plugins/fset/fset-command.c
@@ -33,6 +33,46 @@
/*
+ * Gets the currently selected fset_option pointer and the associated
+ * config_option pointer.
+ */
+
+void
+fset_command_get_option (struct t_fset_option **fset_option,
+ struct t_config_option **config_option)
+{
+
+ *config_option = NULL;
+
+ *fset_option = weechat_arraylist_get (fset_options,
+ fset_buffer_selected_line);
+ if (*fset_option)
+ *config_option = weechat_config_get ((*fset_option)->name);
+}
+
+/*
+ * Gets an integer argument given to the /fset command.
+ */
+
+int
+fset_command_get_int_arg (int argc, char **argv, int arg_number,
+ int default_value)
+{
+ long value;
+ char *error;
+
+ value = default_value;
+ if (argc > arg_number)
+ {
+ error = NULL;
+ value = strtol (argv[arg_number], &error, 10);
+ if (!error || error[0])
+ value = default_value;
+ }
+ return (int)value;
+}
+
+/*
* Callback for command "/fset".
*/
@@ -41,9 +81,8 @@ 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;
- long value;
- char *error, str_value[128], str_input[4096], str_pos[32];
+ int num_options, line, append, use_mute, add_quotes, input_pos, value, i;
+ char str_input[4096], str_pos[32];
struct t_fset_option *ptr_fset_option;
struct t_config_option *ptr_option;
@@ -84,14 +123,7 @@ fset_command_fset (const void *pointer, void *data,
{
if (fset_buffer)
{
- value = 1;
- if (argc > 2)
- {
- error = NULL;
- value = strtol (argv[2], &error, 10);
- if (!error || error[0])
- value = 1;
- }
+ value = fset_command_get_int_arg (argc, argv, 2, 1);
num_options = weechat_arraylist_size (fset_options);
if (num_options > 0)
{
@@ -112,14 +144,7 @@ fset_command_fset (const void *pointer, void *data,
{
if (fset_buffer)
{
- value = 1;
- if (argc > 2)
- {
- error = NULL;
- value = strtol (argv[2], &error, 10);
- if (!error || error[0])
- value = 1;
- }
+ value = fset_command_get_int_arg (argc, argv, 2, 1);
num_options = weechat_arraylist_size (fset_options);
if (num_options > 0)
{
@@ -142,11 +167,10 @@ fset_command_fset (const void *pointer, void *data,
{
if (argc < 3)
WEECHAT_COMMAND_ERROR;
- error = NULL;
- value = strtol (argv[2], &error, 10);
- if (!error || error[0])
+ value = fset_command_get_int_arg (argc, argv, 3, -1);
+ if (value < 0)
WEECHAT_COMMAND_ERROR;
- fset_buffer_set_current_line ((int)value);
+ fset_buffer_set_current_line (value);
fset_buffer_check_line_outside_window ();
}
return WEECHAT_RC_OK;
@@ -154,41 +178,57 @@ fset_command_fset (const void *pointer, void *data,
if (argv[1][0] == '-')
{
- ptr_fset_option = weechat_arraylist_get (fset_options,
- fset_buffer_selected_line);
- if (!ptr_fset_option)
- WEECHAT_COMMAND_ERROR;
- ptr_option = weechat_config_get (ptr_fset_option->name);
- if (!ptr_option)
- WEECHAT_COMMAND_ERROR;
-
if (weechat_strcasecmp (argv[1], "-toggle") == 0)
{
- if (ptr_fset_option->type == FSET_OPTION_TYPE_BOOLEAN)
- weechat_config_option_set (ptr_option, "toggle", 1);
+ if (fset_option_count_marked > 0)
+ {
+ num_options = weechat_arraylist_size (fset_options);
+ for (i = 0; i < num_options; i++)
+ {
+ ptr_fset_option = weechat_arraylist_get (fset_options, i);
+ if (ptr_fset_option->marked)
+ {
+ ptr_option = weechat_config_get (ptr_fset_option->name);
+ if (ptr_option)
+ fset_option_toggle_value (ptr_fset_option, ptr_option);
+ }
+ }
+ }
+ 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);
+ }
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "-add") == 0)
{
- if ((ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)
- || (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR))
+ value = fset_command_get_int_arg (argc, argv, 2, 0);
+ if (value == 0)
+ WEECHAT_COMMAND_ERROR;
+
+ if (fset_option_count_marked > 0)
{
- value = 1;
- if (argc > 2)
+ num_options = weechat_arraylist_size (fset_options);
+ for (i = 0; i < num_options; i++)
{
- error = NULL;
- value = strtol (argv[2], &error, 10);
- if (!error || error[0])
- value = 1;
+ ptr_fset_option = weechat_arraylist_get (fset_options, i);
+ if (ptr_fset_option->marked)
+ {
+ ptr_option = weechat_config_get (ptr_fset_option->name);
+ if (ptr_option)
+ fset_option_add_value (ptr_fset_option, ptr_option, value);
+ }
}
- if (value != 0)
+ }
+ else
+ {
+ fset_command_get_option (&ptr_fset_option, &ptr_option);
+ if (ptr_fset_option && ptr_option)
{
- snprintf (str_value, sizeof (str_value),
- "%s%ld",
- (value > 0) ? "++" : "--",
- (value > 0) ? value : value * -1);
- weechat_config_option_set (ptr_option, str_value, 1);
+ fset_option_add_value (ptr_fset_option, ptr_option, value);
}
}
return WEECHAT_RC_OK;
@@ -196,40 +236,108 @@ fset_command_fset (const void *pointer, void *data,
if (weechat_strcasecmp (argv[1], "-reset") == 0)
{
- weechat_config_option_reset (ptr_option, 1);
+ if (fset_option_count_marked > 0)
+ {
+ num_options = weechat_arraylist_size (fset_options);
+ for (i = 0; i < num_options; i++)
+ {
+ ptr_fset_option = weechat_arraylist_get (fset_options, i);
+ if (ptr_fset_option->marked)
+ {
+ ptr_option = weechat_config_get (ptr_fset_option->name);
+ if (ptr_option)
+ fset_option_reset_value (ptr_fset_option, ptr_option);
+ }
+ }
+ }
+ 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);
+ }
+ }
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "-unset") == 0)
{
- weechat_config_option_unset (ptr_option);
+ if (fset_option_count_marked > 0)
+ {
+ num_options = weechat_arraylist_size (fset_options);
+ for (i = 0; i < num_options; i++)
+ {
+ ptr_fset_option = weechat_arraylist_get (fset_options, i);
+ if (ptr_fset_option->marked)
+ {
+ ptr_option = weechat_config_get (ptr_fset_option->name);
+ if (ptr_option)
+ fset_option_unset_value (ptr_fset_option, ptr_option);
+ }
+ }
+ }
+ 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);
+ }
+ }
return WEECHAT_RC_OK;
}
if ((weechat_strcasecmp (argv[1], "-set") == 0)
|| (weechat_strcasecmp (argv[1], "-append") == 0))
{
- 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);
+ 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);
+ }
+ 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 ();
+ fset_option_set_max_length_fields_all ();
+ fset_buffer_refresh (0);
+ }
return WEECHAT_RC_OK;
}
@@ -257,7 +365,7 @@ fset_command_run_set_cb (const void *pointer, void *data,
{
char **argv, *old_filter, *result, str_number[64];
const char *ptr_condition;
- int rc, argc, old_buffer_selected_line, condition_ok;
+ int rc, argc, old_count_marked, old_buffer_selected_line, condition_ok;
struct t_arraylist *old_options;
struct t_hashtable *old_max_length_field, *eval_extra_vars, *eval_options;
@@ -294,6 +402,7 @@ fset_command_run_set_cb (const void *pointer, void *data,
/* backup current options/max length field/selected line/filter */
old_options = fset_options;
fset_options = fset_option_get_arraylist_options ();
+ old_count_marked = fset_option_count_marked;
old_max_length_field = fset_option_max_length_field;
fset_option_max_length_field = fset_option_get_hashtable_max_length_field ();
old_filter = (fset_option_filter) ? strdup (fset_option_filter) : NULL;
@@ -360,6 +469,7 @@ fset_command_run_set_cb (const void *pointer, void *data,
{
weechat_arraylist_free (fset_options);
fset_options = old_options;
+ fset_option_count_marked = old_count_marked;
weechat_hashtable_free (fset_option_max_length_field);
fset_option_max_length_field = old_max_length_field;
fset_option_set_filter (old_filter);
@@ -395,6 +505,7 @@ fset_command_init ()
" || -unset"
" || -set"
" || -append"
+ " || -mark [<number>]"
" || filter"),
N_(" -bar: add the fset bar\n"
"-refresh: force the refresh of the \"fset\" bar item\n"
@@ -410,7 +521,10 @@ fset_command_init ()
"option (move the cursor at the beginning of value)\n"
" -append: add the /set command to append something in the value "
"of option (move the cursor at the end of value)\n"
- " filter: set a new filter to see only matching options; allowed "
+ " -mark: toggle mark on the option and move \"number\" lines "
+ "(up/down, default is 1: one line down)\n"
+ " filter: set a new filter to see only matching options (this "
+ "filter can be used as input in fset buffer as well); allowed "
"formats are:\n"
" * show all options (no filter)\n"
" f:xxx show only configuration file \"xxx\"\n"
@@ -452,7 +566,19 @@ fset_command_init ()
"${_type}, ...\n"
" - option data, raw format (no colors/spaces):\n"
" - same names prefixed by two underscores, for example: "
- "${__name}, ${__type}, ..."),
+ "${__name}, ${__type}, ...\n"
+ "\n"
+ "Keys on fset buffer:\n"
+ " alt+space toggle boolean value\n"
+ " alt+'-' subtract 1 from value (integer/color)\n"
+ " alt+'+' add 1 to value (integer/color)\n"
+ " alt+f, alt+r reset value\n"
+ " alt+f, alt+u unset value\n"
+ " alt+enter set value\n"
+ " alt+f, alt+a append to value\n"
+ " alt+',' mark/unmark option and move one line down\n"
+ " shift+down mark/unmark option and move one line down\n"
+ " shift+up mark/unmark option and move one line up"),
"-bar"
" || -refresh"
" || -up 1|2|3|4|5"
@@ -464,6 +590,7 @@ fset_command_init ()
" || -unset"
" || -set"
" || -append"
+ " || -mark"
" || *|f:|s:|d|d:|d=|d==|=|==",
&fset_command_fset, NULL, NULL);
weechat_hook_command_run ("/set", &fset_command_run_set_cb, NULL, NULL);
diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c
index 1bbe884eb..6621ec0d6 100644
--- a/src/plugins/fset/fset-config.c
+++ b/src/plugins/fset/fset-config.c
@@ -35,7 +35,9 @@ struct t_config_file *fset_config_file = NULL;
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_unmarked_string;
struct t_config_option *fset_config_look_use_keys;
struct t_config_option *fset_config_look_use_mute;
@@ -53,6 +55,7 @@ struct t_config_option *fset_config_color_help_description;
struct t_config_option *fset_config_color_help_name;
struct t_config_option *fset_config_color_help_quotes;
struct t_config_option *fset_config_color_help_string_values;
+struct t_config_option *fset_config_color_marked[2];
struct t_config_option *fset_config_color_max[2];
struct t_config_option *fset_config_color_min[2];
struct t_config_option *fset_config_color_name[2];
@@ -61,6 +64,7 @@ struct t_config_option *fset_config_color_parent_value[2];
struct t_config_option *fset_config_color_quotes[2];
struct t_config_option *fset_config_color_string_values[2];
struct t_config_option *fset_config_color_type[2];
+struct t_config_option *fset_config_color_unmarked[2];
struct t_config_option *fset_config_color_value[2];
struct t_config_option *fset_config_color_value_changed[2];
struct t_config_option *fset_config_color_value_undef[2];
@@ -215,9 +219,7 @@ fset_config_init ()
"with the /set argument); an empty string disables the catch of "
"/set command; with value \"1\", the fset buffer is always used "
"with /set command"),
- NULL, 0, 0,
- "${count} >= 1",
- NULL, 0,
+ NULL, 0, 0, "${count} >= 1", NULL, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
@@ -230,6 +232,15 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_help_bar_cb, NULL, NULL,
NULL, NULL, NULL);
+ fset_config_look_marked_string = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "marked_string", "string",
+ N_("string displayed when an option is marked (to do an action on "
+ "multiple options)"),
+ NULL, 0, 0, "*", NULL, 0,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
fset_config_look_show_plugin_description = weechat_config_new_option (
fset_config_file, ptr_section,
"show_plugin_description", "boolean",
@@ -238,6 +249,14 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_show_plugin_description_cb, NULL, NULL,
NULL, NULL, NULL);
+ fset_config_look_unmarked_string = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "unmarked_string", "string",
+ N_("string displayed when an option is not marked"),
+ NULL, 0, 0, " ", NULL, 0,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
fset_config_look_use_keys = weechat_config_new_option (
fset_config_file, ptr_section,
"use_keys", "boolean",
@@ -276,7 +295,7 @@ fset_config_init ()
N_("format of each line with an option "
"(note: content is evaluated, see /help fset)"),
NULL, 0, 0,
- " ${name} ${type} ${value2}",
+ "${marked} ${name} ${type} ${value2}",
NULL, 0,
NULL, NULL, NULL,
&fset_config_change_format, NULL, NULL,
@@ -377,6 +396,22 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_color, NULL, NULL,
NULL, NULL, NULL);
+ fset_config_color_marked[0] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "marked", "color",
+ N_("color for marked string"),
+ NULL, 0, 0, "brown", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_color, NULL, NULL,
+ NULL, NULL, NULL);
+ fset_config_color_marked[1] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "marked_selected", "color",
+ N_("color for marked string on the selected line"),
+ NULL, 0, 0, "yellow", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_color, NULL, NULL,
+ NULL, NULL, NULL);
fset_config_color_max[0] = weechat_config_new_option (
fset_config_file, ptr_section,
"max", "color",
@@ -505,6 +540,22 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_color, NULL, NULL,
NULL, NULL, NULL);
+ fset_config_color_unmarked[0] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "unmarked", "color",
+ N_("color for unmarked string"),
+ NULL, 0, 0, "default", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_color, NULL, NULL,
+ NULL, NULL, NULL);
+ fset_config_color_unmarked[1] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "unmarked_selected", "color",
+ N_("color for unmarked string on the selected line"),
+ NULL, 0, 0, "white", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_color, NULL, NULL,
+ NULL, NULL, NULL);
fset_config_color_value[0] = weechat_config_new_option (
fset_config_file, ptr_section,
"value", "color",
diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h
index a66407fd8..abdf8d296 100644
--- a/src/plugins/fset/fset-config.h
+++ b/src/plugins/fset/fset-config.h
@@ -26,7 +26,9 @@ extern struct t_config_file *fset_config_file;
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_unmarked_string;
extern struct t_config_option *fset_config_look_use_keys;
extern struct t_config_option *fset_config_look_use_mute;
@@ -40,6 +42,7 @@ extern struct t_config_option *fset_config_color_help_description;
extern struct t_config_option *fset_config_color_help_name;
extern struct t_config_option *fset_config_color_help_quotes;
extern struct t_config_option *fset_config_color_help_string_values;
+extern struct t_config_option *fset_config_color_marked[2];
extern struct t_config_option *fset_config_color_max[2];
extern struct t_config_option *fset_config_color_min[2];
extern struct t_config_option *fset_config_color_name[2];
@@ -48,6 +51,7 @@ extern struct t_config_option *fset_config_color_parent_value[2];
extern struct t_config_option *fset_config_color_quotes[2];
extern struct t_config_option *fset_config_color_string_values[2];
extern struct t_config_option *fset_config_color_type[2];
+extern struct t_config_option *fset_config_color_unmarked[2];
extern struct t_config_option *fset_config_color_value[2];
extern struct t_config_option *fset_config_color_value_changed[2];
extern struct t_config_option *fset_config_color_value_undef[2];
diff --git a/src/plugins/fset/fset-mouse.c b/src/plugins/fset/fset-mouse.c
index 9791859b2..2e81dac1a 100644
--- a/src/plugins/fset/fset-mouse.c
+++ b/src/plugins/fset/fset-mouse.c
@@ -92,6 +92,7 @@ fset_focus_cb (const void *pointer, void *data, struct t_hashtable *info)
weechat_hashtable_set (info, "fset_option_max", ptr_fset_option->max);
weechat_hashtable_set (info, "fset_option_description", ptr_fset_option->description);
weechat_hashtable_set (info, "fset_option_string_values", ptr_fset_option->string_values);
+ weechat_hashtable_set (info, "fset_option_marked", (ptr_fset_option->marked) ? "1" : "0");
return info;
}
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index 270b9ba67..7b137139b 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -31,6 +31,7 @@
struct t_arraylist *fset_options = NULL;
+int fset_option_count_marked = 0;
struct t_hashtable *fset_option_max_length_field = NULL;
char *fset_option_filter = NULL;
@@ -528,6 +529,13 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option)
/* string_values */
fset_option_set_max_length_field (
"string_values", weechat_strlen_screen (fset_option->string_values));
+
+ /* marked */
+ fset_option_set_max_length_field (
+ "marked", weechat_strlen_screen (
+ (fset_option->marked) ?
+ weechat_config_string (fset_config_look_marked_string) :
+ weechat_config_string (fset_config_look_unmarked_string)));
}
/*
@@ -603,6 +611,7 @@ fset_option_alloc (struct t_config_file *config_file,
new_fset_option->max = NULL;
new_fset_option->description = NULL;
new_fset_option->string_values = NULL;
+ new_fset_option->marked = 0;
fset_option_set_values (new_fset_option, option);
if (!fset_option_match_filters (ptr_config_name, ptr_section_name,
new_fset_option))
@@ -790,6 +799,7 @@ fset_option_get_options ()
int num_options;
weechat_arraylist_clear (fset_options);
+ fset_option_count_marked = 0;
weechat_hashtable_remove_all (fset_option_max_length_field);
ptr_config = weechat_hdata_get_list (fset_hdata_config_file,
@@ -857,6 +867,78 @@ fset_option_filter_options (const char *filter)
}
/*
+ * Toggles a boolean option.
+ */
+
+void
+fset_option_toggle_value (struct t_fset_option *fset_option,
+ struct t_config_option *option)
+{
+ if (!fset_option || !option
+ || (fset_option->type != FSET_OPTION_TYPE_BOOLEAN))
+ return;
+
+ weechat_config_option_set (option, "toggle", 1);
+}
+
+/*
+ * Adds a value to an integer/color option.
+ */
+
+void
+fset_option_add_value (struct t_fset_option *fset_option,
+ struct t_config_option *option,
+ int value)
+{
+ char str_value[128];
+
+ if (!fset_option || !option
+ || ((fset_option->type != FSET_OPTION_TYPE_INTEGER)
+ && (fset_option->type != FSET_OPTION_TYPE_COLOR)))
+ return;
+
+ snprintf (str_value, sizeof (str_value),
+ "%s%d",
+ (value > 0) ? "++" : "--",
+ (value > 0) ? value : value * -1);
+ weechat_config_option_set (option, str_value, 1);
+}
+
+/*
+ * Resets the value of an option.
+ */
+
+void
+fset_option_reset_value (struct t_fset_option *fset_option,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) fset_option;
+
+ if (!option)
+ return;
+
+ weechat_config_option_reset (option, 1);
+}
+
+/*
+ * Unsets the value of an option.
+ */
+
+void
+fset_option_unset_value (struct t_fset_option *fset_option,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) fset_option;
+
+ if (!option)
+ return;
+
+ weechat_config_option_unset (option);
+}
+
+/*
* Callback for config option changed.
*/
@@ -961,6 +1043,7 @@ fset_option_hdata_option_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_fset_option, max, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_fset_option, description, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_fset_option, string_values, STRING, 0, NULL, NULL);
+ WEECHAT_HDATA_VAR(struct t_fset_option, marked, INTEGER, 0, NULL, NULL);
}
return hdata;
}
@@ -1012,6 +1095,8 @@ fset_option_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "string_values", fset_option->description))
return 0;
+ if (!weechat_infolist_new_var_integer (ptr_item, "marked", fset_option->marked))
+ return 0;
return 1;
}
@@ -1044,6 +1129,7 @@ fset_option_print_log ()
weechat_log_printf (" max . . . . . . . . . : '%s'", ptr_fset_option->max);
weechat_log_printf (" description . . . . . : '%s'", ptr_fset_option->description);
weechat_log_printf (" string_values . . . . : '%s'", ptr_fset_option->string_values);
+ weechat_log_printf (" marked. . . . . . . . : %d", ptr_fset_option->marked);
}
}
@@ -1059,6 +1145,7 @@ int
fset_option_init ()
{
fset_options = fset_option_get_arraylist_options ();
+ fset_option_count_marked = 0;
fset_option_max_length_field = fset_option_get_hashtable_max_length_field ();
return 1;
@@ -1076,6 +1163,7 @@ fset_option_end ()
weechat_arraylist_free (fset_options);
fset_options = NULL;
}
+ fset_option_count_marked = 0;
if (fset_option_max_length_field)
{
weechat_hashtable_free (fset_option_max_length_field);
diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h
index 60a88604c..bc7d850a8 100644
--- a/src/plugins/fset/fset-option.h
+++ b/src/plugins/fset/fset-option.h
@@ -44,11 +44,13 @@ struct t_fset_option
char *max; /* max value */
char *description; /* option description */
char *string_values; /* string values for option */
+ int marked; /* option marked for group oper. */
struct t_fset_option *prev_option; /* link to previous option */
struct t_fset_option *next_option; /* link to next option */
};
extern struct t_arraylist *fset_options;
+extern int fset_option_count_marked;
extern struct t_hashtable *fset_option_max_length_field;
extern char *fset_option_filter;
extern char *fset_option_type_string[];
@@ -59,12 +61,22 @@ extern int fset_option_valid (struct t_fset_option *option);
extern struct t_fset_option *fset_option_search_by_name (const char *name,
int *line);
extern int fset_option_value_is_changed (struct t_fset_option *option);
+extern void fset_option_set_max_length_fields_all ();
extern void fset_option_free (struct t_fset_option *fset_option);
extern struct t_arraylist *fset_option_get_arraylist_options ();
extern struct t_hashtable *fset_option_get_hashtable_max_length_field ();
extern void fset_option_get_options ();
extern void fset_option_set_filter (const char *filter);
extern void fset_option_filter_options (const char *filter);
+extern void fset_option_toggle_value (struct t_fset_option *fset_option,
+ struct t_config_option *option);
+extern void fset_option_add_value (struct t_fset_option *fset_option,
+ struct t_config_option *option,
+ int value);
+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 int fset_option_config_cb (const void *pointer,
void *data,
const char *option,