summaryrefslogtreecommitdiff
path: root/src/plugins/fset/fset-option.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-07-06 19:00:16 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-07-08 13:28:40 +0200
commit66cb9f6ea2e534887e73c885d3f131710c48382d (patch)
tree1d21dafd605395a57078f9d82d8f525bad588bb6 /src/plugins/fset/fset-option.c
parent8f9d88edd0106c92daf1ce624638f037f7e8fe0d (diff)
downloadweechat-66cb9f6ea2e534887e73c885d3f131710c48382d.zip
core: add option type "enum" (closes #1973)
The type "enum" replaces type "integer" when used with string values. For compatibility, any option created with type "integer" and string values is automatically created to "enum" on creation, with no error.
Diffstat (limited to 'src/plugins/fset/fset-option.c')
-rw-r--r--src/plugins/fset/fset-option.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index a8fdf2057..2a227c932 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -48,11 +48,11 @@ struct t_hook *fset_option_timer_hook = NULL;
/* types */
char *fset_option_type_string[FSET_OPTION_NUM_TYPES] =
-{ N_("boolean"), N_("integer"), N_("string"), N_("color") };
+{ N_("boolean"), N_("integer"), N_("string"), N_("color"), N_("enum") };
char *fset_option_type_string_short[FSET_OPTION_NUM_TYPES] =
-{ "bool", "int", "str", "col" };
+{ "bool", "int", "str", "col", "enum" };
char *fset_option_type_string_tiny[FSET_OPTION_NUM_TYPES] =
-{ "b", "i", "s", "c" };
+{ "b", "i", "s", "c", "e" };
/*
@@ -170,6 +170,18 @@ fset_option_set_value_string (struct t_config_option *option,
*value_string = strdup (*((int *)value) ? "on" : "off");
break;
case FSET_OPTION_TYPE_INTEGER:
+ snprintf (str_value, sizeof (str_value), "%d", *((int *)value));
+ *value_string = strdup (str_value);
+ break;
+ case FSET_OPTION_TYPE_STRING:
+ *value_string = strdup (
+ (default_value) ? weechat_config_string_default (option) : weechat_config_string (option));
+ break;
+ case FSET_OPTION_TYPE_COLOR:
+ *value_string = strdup (
+ (default_value) ? weechat_config_color_default (option) : weechat_config_color (option));
+ break;
+ case FSET_OPTION_TYPE_ENUM:
ptr_string_values = weechat_config_option_get_pointer (
option, "string_values");
if (ptr_string_values)
@@ -179,18 +191,9 @@ fset_option_set_value_string (struct t_config_option *option,
}
else
{
- snprintf (str_value, sizeof (str_value), "%d", *((int *)value));
- *value_string = strdup (str_value);
+ *value_string = strdup ("");
}
break;
- case FSET_OPTION_TYPE_STRING:
- *value_string = strdup (
- (default_value) ? weechat_config_string_default (option) : weechat_config_string (option));
- break;
- case FSET_OPTION_TYPE_COLOR:
- *value_string = strdup (
- (default_value) ? weechat_config_color_default (option) : weechat_config_color (option));
- break;
case FSET_OPTION_NUM_TYPES:
break;
}
@@ -1114,7 +1117,7 @@ fset_option_toggle_value (struct t_fset_option *fset_option,
}
/*
- * Adds a value to an integer/color option.
+ * Adds a value to an integer/enum/color option.
*/
void
@@ -1126,7 +1129,8 @@ fset_option_add_value (struct t_fset_option *fset_option,
if (!fset_option || !option
|| ((fset_option->type != FSET_OPTION_TYPE_INTEGER)
- && (fset_option->type != FSET_OPTION_TYPE_COLOR)))
+ && (fset_option->type != FSET_OPTION_TYPE_COLOR)
+ && (fset_option->type != FSET_OPTION_TYPE_ENUM)))
return;
snprintf (str_value, sizeof (str_value),