From 8230a284452df723c5656252f06b460df650491f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Nov 2015 22:31:53 +0000 Subject: [PATCH] Added /account autocomplete for startscript property --- src/command/command.c | 53 +++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 31d063e6..06c44ce2 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -77,6 +77,8 @@ static gboolean _cmd_execute(ProfWin *window, const char *const command, const c static char* _cmd_complete_parameters(ProfWin *window, const char *const input); +static char* _script_autocomplete_func(const char *const prefix); + static char* _sub_autocomplete(ProfWin *window, const char *const input); static char* _notify_autocomplete(ProfWin *window, const char *const input); static char* _theme_autocomplete(ProfWin *window, const char *const input); @@ -3246,39 +3248,37 @@ _theme_autocomplete(ProfWin *window, const char *const input) return NULL; } +static char* +_script_autocomplete_func(const char *const prefix) +{ + if (script_show_ac == NULL) { + script_show_ac = autocomplete_new(); + GSList *scripts = scripts_list(); + GSList *curr = scripts; + while (curr) { + autocomplete_add(script_show_ac, curr->data); + curr = g_slist_next(curr); + } + g_slist_free_full(scripts, g_free); + } + + return autocomplete_complete(script_show_ac, prefix, FALSE); +} + + static char* _script_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; if ((strncmp(input, "/script show ", 13) == 0) && (strlen(input) > 13)) { - if (script_show_ac == NULL) { - script_show_ac = autocomplete_new(); - GSList *scripts = scripts_list(); - GSList *curr = scripts; - while (curr) { - autocomplete_add(script_show_ac, curr->data); - curr = g_slist_next(curr); - } - g_slist_free_full(scripts, g_free); - } - result = autocomplete_param_with_ac(input, "/script show", script_show_ac, TRUE); + result = autocomplete_param_with_func(input, "/script show", _script_autocomplete_func); if (result) { return result; } } if ((strncmp(input, "/script run ", 12) == 0) && (strlen(input) > 12)) { - if (script_show_ac == NULL) { - script_show_ac = autocomplete_new(); - GSList *scripts = scripts_list(); - GSList *curr = scripts; - while (curr) { - autocomplete_add(script_show_ac, curr->data); - curr = g_slist_next(curr); - } - g_slist_free_full(scripts, g_free); - } - result = autocomplete_param_with_ac(input, "/script run", script_show_ac, TRUE); + result = autocomplete_param_with_func(input, "/script run", _script_autocomplete_func); if (result) { return result; } @@ -4019,6 +4019,15 @@ _account_autocomplete(ProfWin *window, const char *const input) g_strfreev(args); return found; } + } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "startscript")) == 0) { + g_string_append(beginning, " "); + g_string_append(beginning, args[2]); + found = autocomplete_param_with_func(input, beginning->str, _script_autocomplete_func); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } #ifdef HAVE_LIBGPGME } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) { g_string_append(beginning, " ");