1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05: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) // 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) // handle jid-multi (remove)
} }

View File

@ -115,6 +115,7 @@ autocomplete_add(Autocomplete ac, const char *item)
void void
autocomplete_remove(Autocomplete ac, const char * const item) autocomplete_remove(Autocomplete ac, const char * const item)
{ {
if (ac != NULL) {
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp); GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
if (!curr) { if (!curr) {
@ -128,6 +129,7 @@ autocomplete_remove(Autocomplete ac, const char * const item)
free(curr->data); free(curr->data);
ac->items = g_slist_delete_link(ac->items, curr); ac->items = g_slist_delete_link(ac->items, curr);
}
return; return;
} }

View File

@ -225,6 +225,7 @@ form_create(xmpp_stanza_t * const form_stanza)
// handle repeated field children // handle repeated field children
xmpp_stanza_t *field_child = xmpp_stanza_get_children(field_stanza); xmpp_stanza_t *field_child = xmpp_stanza_get_children(field_stanza);
int value_index = 1;
while (field_child != NULL) { while (field_child != NULL) {
child_name = xmpp_stanza_get_name(field_child); child_name = xmpp_stanza_get_name(field_child);
@ -234,6 +235,13 @@ form_create(xmpp_stanza_t * const form_stanza)
if (value != NULL) { if (value != NULL) {
field->values = g_slist_append(field->values, strdup(value)); field->values = g_slist_append(field->values, strdup(value));
xmpp_free(ctx, 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 // handle options
@ -461,6 +469,13 @@ _form_add_value(DataForm *form, const char * const tag, char *value)
FormField *field = curr->data; FormField *field = curr->data;
if (g_strcmp0(field->var, var) == 0) { if (g_strcmp0(field->var, var) == 0) {
field->values = g_slist_append(field->values, strdup(value)); 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; form->modified = TRUE;
return; return;
} }
@ -539,6 +554,10 @@ _form_remove_text_multi_value(DataForm *form, const char * const tag, int index)
free(item->data); free(item->data);
item->data = NULL; item->data = NULL;
field->values = g_slist_delete_link(field->values, item); 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; form->modified = TRUE;
return TRUE; return TRUE;
} else { } else {