mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Move the validation of the CHOICE setting value
Also, use a FORMAT to show the error message.
This commit is contained in:
parent
6f795f020d
commit
9a30ab53df
@ -387,15 +387,11 @@ gboolean settings_set_choice(const char *key, const char *value)
|
||||
|
||||
rec = settings_get_record(key);
|
||||
|
||||
if (rec != NULL && strarray_find(rec->choices, value) < 0) {
|
||||
char *msg = g_strjoinv(",", rec->choices);
|
||||
g_warning("Invalid value for '%s', must be one of: %s", key, msg);
|
||||
g_free(msg);
|
||||
|
||||
if (rec != NULL && strarray_find(rec->choices, value) < 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
settings_set_str(key, value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,15 @@ static void set_choice(const char *key, const char *value)
|
||||
|
||||
stripped_value = g_strdup(value);
|
||||
g_strstrip(stripped_value);
|
||||
settings_set_choice(key, stripped_value);
|
||||
|
||||
if (settings_set_choice(key, stripped_value) == FALSE) {
|
||||
SETTINGS_REC *rec = settings_get_record(key);
|
||||
char *msg = g_strjoinv(",", rec->choices);
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_CHOICE, msg);
|
||||
g_free(msg);
|
||||
}
|
||||
|
||||
g_free(stripped_value);
|
||||
}
|
||||
|
||||
|
@ -221,6 +221,7 @@ FORMAT_REC fecommon_core_formats[] = {
|
||||
{ "invalid_level", "Invalid message level", 0 },
|
||||
{ "invalid_size", "Invalid size", 0 },
|
||||
{ "invalid_charset", "Invalid charset: $0", 1, { 0 } },
|
||||
{ "invalid_choice", "Invalid choice, must be one of $0", 1, { 0 } },
|
||||
{ "eval_max_recurse", "/eval hit maximum recursion limit", 0 },
|
||||
{ "program_not_found", "Could not find file or file is not executable", 0 },
|
||||
{ "no_server_defined", "No servers defined for this network, see /help server for how to add one", 0 },
|
||||
|
@ -190,6 +190,7 @@ enum {
|
||||
TXT_INVALID_LEVEL,
|
||||
TXT_INVALID_SIZE,
|
||||
TXT_INVALID_CHARSET,
|
||||
TXT_INVALID_CHOICE,
|
||||
TXT_EVAL_MAX_RECURSE,
|
||||
TXT_PROGRAM_NOT_FOUND,
|
||||
TXT_NO_SERVER_DEFINED,
|
||||
|
Loading…
Reference in New Issue
Block a user