From 6246c8b94074d0fa28aa36d4412b834c8657b819 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 18 Oct 2014 23:16:19 +0100 Subject: [PATCH] Add fields to command autocompleter on switch/previous/next --- src/command/command.c | 35 +++++++++++++++++++++++++++++++++++ src/command/command.h | 4 ++++ src/ui/core.c | 27 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/src/command/command.c b/src/command/command.c index 03dc6e01..2a3afb24 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -53,6 +53,7 @@ #include "contact.h" #include "roster_list.h" #include "jid.h" +#include "xmpp/form.h" #include "log.h" #include "muc.h" #ifdef HAVE_LIBOTR @@ -1420,6 +1421,40 @@ cmd_autocomplete_add(char *value) } } +void +cmd_autocomplete_add_form_fields(DataForm *form) +{ + if (form) { + GSList *fields = autocomplete_create_list(form->tag_ac); + GSList *curr_field = fields; + while (curr_field) { + GString *field_str = g_string_new("/"); + g_string_append(field_str, curr_field->data); + cmd_autocomplete_add(field_str->str); + g_string_free(field_str, TRUE); + curr_field = g_slist_next(curr_field); + } + g_slist_free_full(fields, free); + } +} + +void +cmd_autocomplete_remove_form_fields(DataForm *form) +{ + if (form) { + GSList *fields = autocomplete_create_list(form->tag_ac); + GSList *curr_field = fields; + while (curr_field) { + GString *field_str = g_string_new("/"); + g_string_append(field_str, curr_field->data); + cmd_autocomplete_remove(field_str->str); + g_string_free(field_str, TRUE); + curr_field = g_slist_next(curr_field); + } + g_slist_free_full(fields, free); + } +} + void cmd_autocomplete_remove(char *value) { diff --git a/src/command/command.h b/src/command/command.h index a2ded657..13cf2d00 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -37,6 +37,8 @@ #include +#include "xmpp/form.h" + GHashTable *commands; void cmd_init(void); @@ -46,6 +48,8 @@ void cmd_autocomplete(char *input, int *size); void cmd_reset_autocomplete(void); void cmd_autocomplete_add(char *value); void cmd_autocomplete_remove(char *value); +void cmd_autocomplete_add_form_fields(DataForm *form); +void cmd_autocomplete_remove_form_fields(DataForm *form); void cmd_alias_add(char *value); void cmd_alias_remove(char *value); diff --git a/src/ui/core.c b/src/ui/core.c index 899cc3fb..837cac3d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -726,7 +726,16 @@ static gboolean _ui_switch_win(const int i) { if (ui_win_exists(i)) { + ProfWin *old_current = wins_get_current(); + if (old_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_remove_form_fields(old_current->form); + } + ProfWin *new_current = wins_get_by_num(i); + if (new_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_add_form_fields(new_current->form); + } + wins_set_current_by_num(i); new_current->unread = 0; @@ -751,7 +760,16 @@ _ui_switch_win(const int i) static void _ui_previous_win(void) { + ProfWin *old_current = wins_get_current(); + if (old_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_remove_form_fields(old_current->form); + } + ProfWin *new_current = wins_get_previous(); + if (new_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_add_form_fields(new_current->form); + } + int i = wins_get_num(new_current); wins_set_current_by_num(i); @@ -773,7 +791,16 @@ _ui_previous_win(void) static void _ui_next_win(void) { + ProfWin *old_current = wins_get_current(); + if (old_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_remove_form_fields(old_current->form); + } + ProfWin *new_current = wins_get_next(); + if (new_current->type == WIN_MUC_CONFIG) { + cmd_autocomplete_add_form_fields(new_current->form); + } + int i = wins_get_num(new_current); wins_set_current_by_num(i);