diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2016-06-13 21:47:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-13 21:47:39 +0200 |
commit | 52ced0728b81421c128c5f976d79a5dd43b0ac80 (patch) | |
tree | 14d5334fcc5f47081573175eddd1ddf0397d3c19 /src/fe-common | |
parent | e5f7b786c08d14f8531f2388f26ebf8e82d1716c (diff) | |
parent | 5c8423a08cd9ffbe3363f3b0e5722e4a32157914 (diff) | |
download | irssi-52ced0728b81421c128c5f976d79a5dd43b0ac80.zip |
Merge pull request #492 from LemonBoy/enum
Enum setting implementation
Diffstat (limited to 'src/fe-common')
-rw-r--r-- | src/fe-common/core/completion.c | 12 | ||||
-rw-r--r-- | src/fe-common/core/fe-settings.c | 27 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.c | 1 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.h | 1 |
4 files changed, 40 insertions, 1 deletions
diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c index 861054b5..c87fdb50 100644 --- a/src/fe-common/core/completion.c +++ b/src/fe-common/core/completion.c @@ -691,8 +691,20 @@ static void sig_complete_set(GList **list, WINDOW_REC *window, SETTINGS_REC *rec = settings_get_record(line); if (rec != NULL) { char *value = settings_get_print(rec); + + /* show the current option first */ if (value != NULL) *list = g_list_append(*list, value); + + /* show the whole list of valid options */ + if (rec->type == SETTING_TYPE_CHOICE) { + char **tmp; + + for (tmp = rec->choices; *tmp; tmp++) { + if (g_ascii_strcasecmp(*tmp, value) != 0) + *list = g_list_append(*list, g_strdup(*tmp)); + } + } } } diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index b689cbf9..abbd45a8 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -67,6 +67,7 @@ static void set_print_pattern(const char *pattern) static void set_boolean(const char *key, const char *value) { char *stripped_value; + stripped_value = g_strdup(value); g_strstrip(stripped_value); @@ -79,7 +80,7 @@ static void set_boolean(const char *key, const char *value) else printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE); - g_free(stripped_value); + g_free(stripped_value); } static void set_int(const char *key, const char *value) @@ -99,6 +100,24 @@ static void set_int(const char *key, const char *value) settings_set_int(key, (int)longval); } +static void set_choice(const char *key, const char *value) +{ + char *stripped_value; + + stripped_value = g_strdup(value); + g_strstrip(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); +} + /* SYNTAX: SET [-clear | -default] [<key> [<value>]] */ static void cmd_set(char *data) { @@ -142,6 +161,12 @@ static void cmd_set(char *data) else set_int(key, value); break; + case SETTING_TYPE_CHOICE: + if (clear || set_default) + settings_set_choice(key, rec->choices[rec->default_value.v_int]); + else + set_choice(key, value); + break; case SETTING_TYPE_STRING: settings_set_str(key, clear ? "" : set_default ? rec->default_value.v_string : diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index b897b0c6..5c07f14c 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -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 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index de1e13f2..2b45ff6b 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -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, |