1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Added autocompletion for form list-single values

This commit is contained in:
James Booth 2014-09-17 22:51:52 +01:00
parent 9bfc499078
commit e42a0847a2
3 changed files with 56 additions and 0 deletions

View File

@ -1406,6 +1406,14 @@ cmd_reset_autocomplete()
autocomplete_reset(join_property_ac);
autocomplete_reset(room_ac);
autocomplete_reset(form_ac);
if (ui_current_win_type() == WIN_MUC_CONFIG) {
ProfWin *window = wins_get_current();
if (window && window->form) {
form_reset_autocompleters(window->form);
}
}
bookmark_autocomplete_reset();
}
@ -2130,6 +2138,14 @@ _form_autocomplete(char *input, int *size)
}
// handle list-single (set)
if ((g_strcmp0(args[0], "set") == 0) && field_type == FIELD_LIST_SINGLE) {
Autocomplete ac = form_get_value_ac(form, tag);
found = autocomplete_param_with_ac(input, size, beginning->str, ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
}
}
// handle list-multi (add, remove)

View File

@ -207,6 +207,7 @@ form_create(xmpp_stanza_t * const form_stanza)
field->label = _get_attr(field_stanza, "label");
field->type = _get_attr(field_stanza, "type");
field->type_t = _get_field_type(field->type);
field->value_ac = autocomplete_new();
field->var = _get_attr(field_stanza, "var");
@ -241,6 +242,10 @@ form_create(xmpp_stanza_t * const form_stanza)
option->label = _get_attr(field_child, "label");
option->value = _get_property(field_child, "value");
if (field->type_t == FIELD_LIST_SINGLE) {
autocomplete_add(field->value_ac, option->value);
}
field->options = g_slist_append(field->options, option);
}
@ -355,6 +360,7 @@ _free_field(FormField *field)
free(field->description);
g_slist_free_full(field->values, free);
g_slist_free_full(field->options, (GDestroyNotify)_free_option);
autocomplete_free(field->value_ac);
free(field);
}
}
@ -610,6 +616,35 @@ _form_get_field_by_tag(DataForm *form, const char * const tag)
return NULL;
}
static Autocomplete
_form_get_value_ac(DataForm *form, const char * const tag)
{
char *var = g_hash_table_lookup(form->tag_to_var, tag);
if (var != NULL) {
GSList *curr = form->fields;
while (curr != NULL) {
FormField *field = curr->data;
if (g_strcmp0(field->var, var) == 0) {
return field->value_ac;
}
curr = g_slist_next(curr);
}
}
return NULL;
}
static void
_form_reset_autocompleters(DataForm *form)
{
autocomplete_reset(form->tag_ac);
GSList *curr_field = form->fields;
while (curr_field) {
FormField *field = curr_field->data;
autocomplete_reset(field->value_ac);
curr_field = g_slist_next(curr_field);
}
}
void
form_init_module(void)
{
@ -624,5 +659,7 @@ form_init_module(void)
form_field_contains_option = _form_field_contains_option;
form_tag_exists = _form_tag_exists;
form_get_value_count = _form_get_value_count;
form_get_value_ac = _form_get_value_ac;
form_get_field_by_tag = _form_get_field_by_tag;
form_reset_autocompleters = _form_reset_autocompleters;
}

View File

@ -115,6 +115,7 @@ typedef struct form_field_t {
gboolean required;
GSList *values;
GSList *options;
Autocomplete value_ac;
} FormField;
typedef struct data_form_t {
@ -219,5 +220,7 @@ form_field_type_t (*form_get_field_type)(DataForm *form, const char * const tag)
gboolean (*form_field_contains_option)(DataForm *form, const char * const tag, char *value);
int (*form_get_value_count)(DataForm *form, const char * const tag);
FormField* (*form_get_field_by_tag)(DataForm *form, const char * const tag);
Autocomplete (*form_get_value_ac)(DataForm *form, const char * const tag);
void (*form_reset_autocompleters)(DataForm *form);
#endif