diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-24 17:20:07 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-24 17:20:07 +0200 |
commit | cf4f86917478137043ca8f316ce61d26259fdfd5 (patch) | |
tree | cc03eb06640398f1c84fae956e454c6fd25d2422 /src/gui | |
parent | 16e11ef25ea13eeb77d5ebaf6df83a06bfc09afc (diff) | |
download | weechat-cf4f86917478137043ca8f316ce61d26259fdfd5.zip |
Added completion with possible values for /set, new possible values "++n" and "--n" for integers and colors
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 10 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk-color.c | 10 | ||||
-rw-r--r-- | src/gui/gui-bar.c | 54 | ||||
-rw-r--r-- | src/gui/gui-color.h | 1 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 54 |
5 files changed, 108 insertions, 21 deletions
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 @@ -249,6 +249,16 @@ gui_color_assign (t_gui_color **color, char *fg_and_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 @@ -101,6 +101,16 @@ gui_color_assign (int *color, char *color_name) } /* + * 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]) + { + new_value = CONFIG_INTEGER(ptr_bar->size) + number; + } + } + else if (strncmp (value, "--", 2) == 0) + { + 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 + { + 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: |