diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index d33f9703f..a4ef78358 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -451,7 +451,7 @@ config_file_new_option (struct t_config_file *config_file, case CONFIG_OPTION_TYPE_COLOR: new_option->string_values = NULL; new_option->min = min; - new_option->max = min; + new_option->max = gui_color_get_number () - 1; new_option->default_value = malloc (sizeof (int)); if (!gui_color_assign (new_option->default_value, default_value)) *((int *)new_option->default_value) = 0; @@ -820,7 +820,7 @@ int config_file_option_set (struct t_config_option *option, char *value, int run_callback) { - int value_int, i, rc, length_option; + int value_int, i, rc, length_option, new_value_ok; long number; char *error, *option_full_name; @@ -872,13 +872,38 @@ config_file_option_set (struct t_config_option *option, char *value, if (option->string_values) { value_int = -1; - for (i = 0; option->string_values[i]; i++) + if (strncmp (value, "++", 2) == 0) { - if (string_strcasecmp (option->string_values[i], - value) == 0) + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - value_int = i; - break; + number = number % (option->max + 1); + value_int = (*((int *)option->value) + number) % + (option->max + 1); + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (*((int *)option->value) + (option->max + 1) - number) % + (option->max + 1); + } + } + else + { + for (i = 0; option->string_values[i]; i++) + { + if (string_strcasecmp (option->string_values[i], + value) == 0) + { + value_int = i; + break; + } } } if (value_int >= 0) @@ -894,15 +919,48 @@ config_file_option_set (struct t_config_option *option, char *value, } else { - error = NULL; - number = strtol (value, &error, 10); - if (error && !error[0]) + new_value_ok = 0; + if (strncmp (value, "++", 2) == 0) { - if (number == *((int *)option->value)) + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + value_int = *((int *)option->value) + number; + if (value_int <= option->max) + new_value_ok = 1; + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + value_int = *((int *)option->value) - number; + if (value_int >= option->min) + new_value_ok = 1; + } + } + else + { + error = NULL; + number = strtol (value, &error, 10); + if (error && !error[0]) + { + value_int = number; + if ((value_int >= option->min) + && (value_int <= option->max)) + new_value_ok = 1; + } + } + if (new_value_ok) + { + if (value_int == *((int *)option->value)) rc = 1; else { - *((int *)option->value) = number; + *((int *)option->value) = value_int; rc = 2; } } @@ -927,7 +985,34 @@ config_file_option_set (struct t_config_option *option, char *value, option->value = NULL; break; case CONFIG_OPTION_TYPE_COLOR: - if (gui_color_assign (&value_int, value)) + value_int = -1; + if (strncmp (value, "++", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (*((int *)option->value) + number) % + (option->max + 1); + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (*((int *)option->value) + (option->max + 1) - number) % + (option->max + 1); + } + } + else + { + gui_color_assign (&value_int, value); + } + if (value_int >= 0) { if (value_int == *((int *)option->value)) rc = 1; diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 45d709e0c..c1b767b5d 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -248,6 +248,16 @@ gui_color_assign (t_gui_color **color, char *fg_and_bg) free (color_bg); }*/ +/* + * gui_color_get_number: get number of available colors + */ + +int +gui_color_get_number () +{ + return GUI_CURSES_NUM_WEECHAT_COLORS; +} + /* * gui_color_get_name: get color name */ diff --git a/src/gui/gtk/gui-gtk-color.c b/src/gui/gtk/gui-gtk-color.c index cb04d3d1a..8fc19e099 100644 --- a/src/gui/gtk/gui-gtk-color.c +++ b/src/gui/gtk/gui-gtk-color.c @@ -100,6 +100,16 @@ gui_color_assign (int *color, char *color_name) return 0; } +/* + * gui_color_get_number: get number of available colors + */ + +int +gui_color_get_number () +{ + return 0; +} + /* * gui_color_get_name: get color name */ diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index bb46535f9..29a6c834a 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -376,6 +376,7 @@ gui_bar_config_check_size (void *data, struct t_config_option *option, struct t_gui_bar *ptr_bar; long number; char *error; + int new_value; /* make C compiler happy */ (void) data; @@ -383,24 +384,47 @@ gui_bar_config_check_size (void *data, struct t_config_option *option, ptr_bar = gui_bar_search_with_option_name (option->name); if (ptr_bar) { - error = NULL; - number = strtol (value, &error, 10); - if (error && !error[0]) + new_value = -1; + if (strncmp (value, "++", 2) == 0) { - if (number < 0) - return 0; - - if ((number != 0) && - ((CONFIG_INTEGER(ptr_bar->size) == 0) - || (number > CONFIG_INTEGER(ptr_bar->size)))) + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - if (!gui_bar_check_size_add (ptr_bar, - number - CONFIG_INTEGER(ptr_bar->size))) - return 0; + new_value = CONFIG_INTEGER(ptr_bar->size) + number; } - - return 1; } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + new_value = CONFIG_INTEGER(ptr_bar->size) - number; + } + } + else + { + error = NULL; + number = strtol (value, &error, 10); + if (error && !error[0]) + { + new_value = number; + } + } + if (new_value < 0) + return 0; + + if ((new_value > 0) && + ((CONFIG_INTEGER(ptr_bar->size) == 0) + || (new_value > CONFIG_INTEGER(ptr_bar->size)))) + { + if (!gui_bar_check_size_add (ptr_bar, + new_value - CONFIG_INTEGER(ptr_bar->size))) + return 0; + } + + return 1; } return 0; @@ -422,7 +446,7 @@ gui_bar_config_change_size (void *data, struct t_config_option *option) if (ptr_bar) { gui_bar_window_set_current_size (ptr_bar, - CONFIG_INTEGER(ptr_bar->size_max)); + CONFIG_INTEGER(ptr_bar->size)); gui_window_refresh_needed = 1; } } diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index 513d77206..448dac134 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -154,6 +154,7 @@ extern void gui_color_free (struct t_gui_color *color); extern int gui_color_search (char *color_name); extern int gui_color_assign (int *color, char *color_name); +extern int gui_color_get_number (); extern char *gui_color_get_name (int num_color); extern void gui_color_init_pairs (); extern void gui_color_rebuild_weechat (); diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 5abcb5b0c..9acb3160f 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -637,7 +637,7 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) { char *pos_space, *option_full_name, *color_name, *pos_section, *pos_option; char *file, *section, *value_string; - int length; + int length, i, num_colors; struct t_config_file *ptr_config; struct t_config_section *ptr_section, *section_found; struct t_config_option *option_found; @@ -687,12 +687,18 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) switch (option_found->type) { case CONFIG_OPTION_TYPE_BOOLEAN: + gui_completion_list_add (completion, "on", + 0, WEECHAT_LIST_POS_SORT); + gui_completion_list_add (completion, "off", + 0, WEECHAT_LIST_POS_SORT); + gui_completion_list_add (completion, "toggle", + 0, WEECHAT_LIST_POS_END); if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE) gui_completion_list_add (completion, "on", - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); else gui_completion_list_add (completion, "off", - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); break; case CONFIG_OPTION_TYPE_INTEGER: length = 64; @@ -700,19 +706,42 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) if (value_string) { if (option_found->string_values) + { + for (i = 0; option_found->string_values[i]; i++) + { + gui_completion_list_add (completion, + option_found->string_values[i], + 0, WEECHAT_LIST_POS_SORT); + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); snprintf (value_string, length, "%s", option_found->string_values[CONFIG_INTEGER(option_found)]); + } else + { + if (CONFIG_INTEGER(option_found) > option_found->min) + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (CONFIG_INTEGER(option_found) < option_found->max) + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_BEGINNING); snprintf (value_string, length, "%d", CONFIG_INTEGER(option_found)); + } gui_completion_list_add (completion, value_string, - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); free (value_string); } break; case CONFIG_OPTION_TYPE_STRING: + gui_completion_list_add (completion, + "\"\"", + 0, WEECHAT_LIST_POS_BEGINNING); length = strlen (CONFIG_STRING(option_found)) + 2 + 1; value_string = malloc (length); if (value_string) @@ -722,17 +751,30 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) CONFIG_STRING(option_found)); gui_completion_list_add (completion, value_string, - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); free (value_string); } break; case CONFIG_OPTION_TYPE_COLOR: + num_colors = gui_color_get_number (); + for (i = 0; i < num_colors; i++) + { + color_name = gui_color_get_name (i); + if (color_name) + gui_completion_list_add (completion, + color_name, + 0, WEECHAT_LIST_POS_SORT); + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); color_name = gui_color_get_name (CONFIG_INTEGER(option_found)); if (color_name) { gui_completion_list_add (completion, color_name, - 0, WEECHAT_LIST_POS_SORT); + 0, WEECHAT_LIST_POS_BEGINNING); } break; case CONFIG_NUM_OPTION_TYPES: