From dcc2123ec4d2210c8631b181cae9d817504e8b48 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 10 Oct 2016 22:28:23 +0100 Subject: Allow filepath autocompletion in plugins closes #858 --- src/plugins/python_api.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/plugins/python_api.c') diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index f2bce2e3..0b78b055 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -339,6 +339,30 @@ python_api_completer_clear(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject* +python_api_filepath_completer_add(PyObject *self, PyObject *args) +{ + PyObject *prefix = NULL; + + if (!PyArg_ParseTuple(args, "O", &prefix)) { + Py_RETURN_NONE; + } + + char *prefix_str = python_str_or_unicode_to_string(prefix); + + char *plugin_name = _python_plugin_name(); + log_debug("Filepath autocomplete added '%s' for %s", prefix_str, plugin_name); + + allow_python_threads(); + api_filepath_completer_add(plugin_name, prefix_str); + free(prefix_str); + disable_python_threads(); + + free(plugin_name); + + Py_RETURN_NONE; +} + static PyObject* python_api_notify(PyObject *self, PyObject *args) { @@ -1063,6 +1087,7 @@ static PyMethodDef apiMethods[] = { { "completer_add", python_api_completer_add, METH_VARARGS, "Add items to an autocompleter." }, { "completer_remove", python_api_completer_remove, METH_VARARGS, "Remove items from an autocompleter." }, { "completer_clear", python_api_completer_clear, METH_VARARGS, "Remove all items from an autocompleter." }, + { "filepath_completer_add", python_api_filepath_completer_add, METH_VARARGS, "Add filepath autocompleter" }, { "send_line", python_api_send_line, METH_VARARGS, "Send a line of input." }, { "notify", python_api_notify, METH_VARARGS, "Send desktop notification." }, { "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." }, -- cgit 1.4.1-2-gfad0