1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added autocompletion for jid-multi form fields

This commit is contained in:
James Booth 2014-09-17 23:34:48 +01:00
parent 45ba6f1fed
commit a905ce18a3
3 changed files with 29 additions and 9 deletions

View File

@ -2169,6 +2169,14 @@ _form_autocomplete(char *input, int *size)
}
// handle jid-multi (remove)
if ((g_strcmp0(args[0], "remove") == 0) && field_type == FIELD_JID_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;
}
}
}
found = autocomplete_param_with_ac(input, size, "/form set", form->tag_ac, TRUE);

View File

@ -99,16 +99,18 @@ autocomplete_length(Autocomplete ac)
void
autocomplete_add(Autocomplete ac, const char *item)
{
char *item_cpy;
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
if (ac != NULL) {
char *item_cpy;
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
// if item already exists
if (curr != NULL) {
return;
// if item already exists
if (curr != NULL) {
return;
}
item_cpy = strdup(item);
ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
}
item_cpy = strdup(item);
ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
return;
}

View File

@ -234,7 +234,6 @@ form_create(xmpp_stanza_t * const form_stanza)
char *value = xmpp_stanza_get_text(field_child);
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("");
@ -242,6 +241,11 @@ form_create(xmpp_stanza_t * const form_stanza)
autocomplete_add(field->value_ac, ac_val->str);
g_string_free(ac_val, TRUE);
}
if (field->type_t == FIELD_JID_MULTI) {
autocomplete_add(field->value_ac, value);
}
xmpp_free(ctx, value);
}
// handle options
@ -502,6 +506,9 @@ _form_add_unique_value(DataForm *form, const char * const tag, char *value)
}
field->values = g_slist_append(field->values, strdup(value));
if (field->type_t == FIELD_JID_MULTI) {
autocomplete_add(field->value_ac, value);
}
form->modified = TRUE;
return TRUE;
}
@ -526,6 +533,9 @@ _form_remove_value(DataForm *form, const char * const tag, char *value)
free(found->data);
found->data = NULL;
field->values = g_slist_delete_link(field->values, found);
if (field->type_t == FIELD_JID_MULTI) {
autocomplete_remove(field->value_ac, value);
}
form->modified = TRUE;
return TRUE;
} else {