about summary refs log tree commit diff stats
path: root/src/plugins/python_api.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-10-10 22:28:23 +0100
committerJames Booth <boothj5@gmail.com>2016-10-10 22:28:23 +0100
commitdcc2123ec4d2210c8631b181cae9d817504e8b48 (patch)
treea8bb9c746aa6b2739e0ef6af9ce01f9966bff1bd /src/plugins/python_api.c
parentd485588a07f9d4a477a7615fee926fcfee44b29e (diff)
downloadprofani-tty-dcc2123ec4d2210c8631b181cae9d817504e8b48.tar.gz
Allow filepath autocompletion in plugins
closes #858
Diffstat (limited to 'src/plugins/python_api.c')
-rw-r--r--src/plugins/python_api.c25
1 files changed, 25 insertions, 0 deletions
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
@@ -340,6 +340,30 @@ python_api_completer_clear(PyObject *self, PyObject *args)
 }
 
 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)
 {
     PyObject *message = NULL;
@@ -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." },