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

Added autocompletion for form text-multi values

This commit is contained in:
James Booth 2014-09-17 23:21:14 +01:00
parent fa7b6f3000
commit 45ba6f1fed
3 changed files with 40 additions and 11 deletions

View File

@ -2159,6 +2159,14 @@ _form_autocomplete(char *input, int *size)
}
// handle text-multi (remove)
if ((g_strcmp0(args[0], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
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 jid-multi (remove)
}

View File

@ -115,20 +115,22 @@ autocomplete_add(Autocomplete ac, const char *item)
void
autocomplete_remove(Autocomplete ac, const char * const item)
{
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
if (ac != NULL) {
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
if (!curr) {
return;
if (!curr) {
return;
}
// reset last found if it points to the item to be removed
if (ac->last_found == curr) {
ac->last_found = NULL;
}
free(curr->data);
ac->items = g_slist_delete_link(ac->items, curr);
}
// reset last found if it points to the item to be removed
if (ac->last_found == curr) {
ac->last_found = NULL;
}
free(curr->data);
ac->items = g_slist_delete_link(ac->items, curr);
return;
}

View File

@ -225,6 +225,7 @@ form_create(xmpp_stanza_t * const form_stanza)
// handle repeated field children
xmpp_stanza_t *field_child = xmpp_stanza_get_children(field_stanza);
int value_index = 1;
while (field_child != NULL) {
child_name = xmpp_stanza_get_name(field_child);
@ -234,6 +235,13 @@ form_create(xmpp_stanza_t * const form_stanza)
if (value != NULL) {
field->values = g_slist_append(field->values, strdup(value));
xmpp_free(ctx, value);
if (field->type_t == FIELD_TEXT_MULTI) {
GString *ac_val = g_string_new("");
g_string_printf(ac_val, "val%d", value_index++);
autocomplete_add(field->value_ac, ac_val->str);
g_string_free(ac_val, TRUE);
}
}
// handle options
@ -461,6 +469,13 @@ _form_add_value(DataForm *form, const char * const tag, char *value)
FormField *field = curr->data;
if (g_strcmp0(field->var, var) == 0) {
field->values = g_slist_append(field->values, strdup(value));
if (field->type_t == FIELD_TEXT_MULTI) {
int total = g_slist_length(field->values);
GString *value_index = g_string_new("");
g_string_printf(value_index, "val%d", total);
autocomplete_add(field->value_ac, value_index->str);
g_string_free(value_index, TRUE);
}
form->modified = TRUE;
return;
}
@ -539,6 +554,10 @@ _form_remove_text_multi_value(DataForm *form, const char * const tag, int index)
free(item->data);
item->data = NULL;
field->values = g_slist_delete_link(field->values, item);
GString *value_index = g_string_new("");
g_string_printf(value_index, "val%d", index+1);
autocomplete_remove(field->value_ac, value_index->str);
g_string_free(value_index, TRUE);
form->modified = TRUE;
return TRUE;
} else {