summaryrefslogtreecommitdiff
path: root/src/plugins/fset
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-06-01 21:44:07 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-06-25 16:35:27 +0200
commit7336c932702b817f87b118e73c724d388f40a9ee (patch)
tree065b668b62d6829315dd57304819c7fafafdf60f /src/plugins/fset
parent6be32fdce5fa642f111cce8e5d3723ed6f08a837 (diff)
downloadweechat-7336c932702b817f87b118e73c724d388f40a9ee.zip
fset: add option fset.look.unmark_after_action
Diffstat (limited to 'src/plugins/fset')
-rw-r--r--src/plugins/fset/fset-command.c79
-rw-r--r--src/plugins/fset/fset-config.c9
-rw-r--r--src/plugins/fset/fset-config.h1
-rw-r--r--src/plugins/fset/fset-option.c90
-rw-r--r--src/plugins/fset/fset-option.h8
5 files changed, 129 insertions, 58 deletions
diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c
index cd8b3cbba..5d9d82d9f 100644
--- a/src/plugins/fset/fset-command.c
+++ b/src/plugins/fset/fset-command.c
@@ -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;
}
diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c
index 6621ec0d6..014033582 100644
--- a/src/plugins/fset/fset-config.c
+++ b/src/plugins/fset/fset-config.c
@@ -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",
diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h
index abdf8d296..80fef6f4d 100644
--- a/src/plugins/fset/fset-config.h
+++ b/src/plugins/fset/fset-config.h
@@ -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;
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index 6cd4e1ecf..e3aa958cd 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -942,6 +942,96 @@ fset_option_unset_value (struct t_fset_option *fset_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.
*/
diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h
index bc7d850a8..21749cb3c 100644
--- a/src/plugins/fset/fset-option.h
+++ b/src/plugins/fset/fset-option.h
@@ -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,