From 1075f07ff5924d2c40414f47bc665a2acc664730 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 15 Mar 2016 22:32:44 +0000 Subject: [PATCH] Parse plugin args with freetext parser Also allow adding to plugin autocompleters --- src/plugins/autocompleters.c | 19 ++++++++++++++----- src/plugins/callbacks.c | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/plugins/autocompleters.c b/src/plugins/autocompleters.c index 483af7ca..9acbf755 100644 --- a/src/plugins/autocompleters.c +++ b/src/plugins/autocompleters.c @@ -49,12 +49,21 @@ autocompleters_init(void) void autocompleters_add(const char *key, char **items) { - Autocomplete new_ac = autocomplete_new(); - int i = 0; - for (i = 0; i < g_strv_length(items); i++) { - autocomplete_add(new_ac, items[i]); + if (g_hash_table_contains(autocompleters, key)) { + Autocomplete existing_ac = g_hash_table_lookup(autocompleters, key); + + int i = 0; + for (i = 0; i < g_strv_length(items); i++) { + autocomplete_add(existing_ac, items[i]); + } + } else { + Autocomplete new_ac = autocomplete_new(); + int i = 0; + for (i = 0; i < g_strv_length(items); i++) { + autocomplete_add(new_ac, items[i]); + } + g_hash_table_insert(autocompleters, strdup(key), new_ac); } - g_hash_table_insert(autocompleters, strdup(key), new_ac); } char * diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index 6f796259..92673395 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -108,7 +108,7 @@ plugins_run_command(const char * const input) PluginCommand *command = p_command->data; if (g_strcmp0(split[0], command->command_name) == 0) { gboolean result; - gchar **args = parse_args(input, command->min_args, command->max_args, &result); + gchar **args = parse_args_with_freetext(input, command->min_args, command->max_args, &result); if (result == FALSE) { ui_invalid_command_usage(command->command_name, NULL); g_strfreev(split);