1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Refactor form field and form autocompleters

This commit is contained in:
James Booth 2014-10-19 01:09:53 +01:00
parent 23ff88f27f
commit 7973e0b683

View File

@ -88,7 +88,7 @@ static char * _statuses_autocomplete(char *input, int *size);
static char * _alias_autocomplete(char *input, int *size);
static char * _join_autocomplete(char *input, int *size);
static char * _log_autocomplete(char *input, int *size);
static char * _form_autocomplete(char *input, int *size);
static char * _form_field_autocomplete(char *input, int *size);
static char * _occupants_autocomplete(char *input, int *size);
static char * _kick_autocomplete(char *input, int *size);
static char * _ban_autocomplete(char *input, int *size);
@ -1338,9 +1338,6 @@ cmd_init(void)
autocomplete_add(form_ac, "submit");
autocomplete_add(form_ac, "cancel");
autocomplete_add(form_ac, "show");
autocomplete_add(form_ac, "set");
autocomplete_add(form_ac, "add");
autocomplete_add(form_ac, "remove");
autocomplete_add(form_ac, "help");
form_field_multi_ac = autocomplete_new();
@ -1823,8 +1820,8 @@ _cmd_complete_parameters(char *input, int *size)
}
}
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac };
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", "/form" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, form_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE);
@ -1883,8 +1880,8 @@ _cmd_complete_parameters(char *input, int *size)
g_hash_table_destroy(ac_funcs);
input[*size] = '\0';
if (g_str_has_prefix(input, "/field") || g_str_has_prefix(input, "/form")) {
result = _form_autocomplete(input, size);
if (g_str_has_prefix(input, "/field")) {
result = _form_field_autocomplete(input, size);
if (result != NULL) {
ui_replace_input(input, result, size);
g_free(result);
@ -2286,18 +2283,20 @@ _theme_autocomplete(char *input, int *size)
}
static char *
_form_autocomplete(char *input, int *size)
_form_field_autocomplete(char *input, int *size)
{
char *found = NULL;
ProfWin *current = wins_get_current();
if (current != NULL) {
DataForm *form = current->form;
if (form != NULL) {
input[*size] = '\0';
if (g_str_has_prefix(input, "/field")) {
if (form == NULL) {
return NULL;
}
input[*size] = '\0';
gchar **split = g_strsplit(input, " ", 0);
if (g_strv_length(split) == 3) {
char *field_tag = split[0]+1;
if (form_tag_exists(form, field_tag)) {
@ -2346,18 +2345,8 @@ _form_autocomplete(char *input, int *size)
}
}
}
g_strfreev(split);
if (found) {
return found;
}
} else {
found = autocomplete_param_with_ac(input, size, "/form", form_ac, TRUE);
if (found != NULL) {
return found;
}
}
}
}
return found;
}