mirror of
https://github.com/profanity-im/profanity.git
synced 2025-07-05 17:28:00 -04:00
Plugins: Added completer_remove
This commit is contained in:
parent
a328367eb4
commit
bfdc3b8807
@ -160,6 +160,12 @@ api_completer_add(const char *key, char **items)
|
||||
autocompleters_add(key, items);
|
||||
}
|
||||
|
||||
void
|
||||
api_completer_remove(const char *key, char **items)
|
||||
{
|
||||
autocompleters_remove(key, items);
|
||||
}
|
||||
|
||||
void
|
||||
api_notify(const char *message, const char *category, int timeout_ms)
|
||||
{
|
||||
|
@ -55,6 +55,7 @@ void api_register_timed(void *callback, int interval_seconds,
|
||||
void (*callback_func)(PluginTimedFunction *timed_function));
|
||||
|
||||
void api_completer_add(const char *key, char **items);
|
||||
void api_completer_remove(const char *key, char **items);
|
||||
|
||||
void api_log_debug(const char *message);
|
||||
void api_log_info(const char *message);
|
||||
|
@ -66,6 +66,20 @@ autocompleters_add(const char *key, char **items)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
autocompleters_remove(const char *key, char **items)
|
||||
{
|
||||
if (!g_hash_table_contains(autocompleters, key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Autocomplete ac = g_hash_table_lookup(autocompleters, key);
|
||||
int i = 0;
|
||||
for (i = 0; i < g_strv_length(items); i++) {
|
||||
autocomplete_remove(ac, items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
autocompleters_complete(const char * const input)
|
||||
{
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
void autocompleters_init(void);
|
||||
void autocompleters_add(const char *key, char **items);
|
||||
void autocompleters_remove(const char *key, char **items);
|
||||
char* autocompleters_complete(const char * const input);
|
||||
void autocompleters_reset(void);
|
||||
void autocompleters_destroy(void);
|
||||
|
@ -102,6 +102,12 @@ c_api_completer_add(const char *key, char **items)
|
||||
api_completer_add(key, items);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_completer_remove(const char *key, char **items)
|
||||
{
|
||||
api_completer_remove(key, items);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_notify(const char *message, int timeout_ms, const char *category)
|
||||
{
|
||||
@ -270,6 +276,7 @@ c_api_init(void)
|
||||
prof_register_command = c_api_register_command;
|
||||
prof_register_timed = c_api_register_timed;
|
||||
prof_completer_add = c_api_completer_add;
|
||||
prof_completer_remove = c_api_completer_remove;
|
||||
prof_notify = c_api_notify;
|
||||
prof_send_line = c_api_send_line;
|
||||
prof_get_current_recipient = c_api_get_current_recipient;
|
||||
|
@ -49,6 +49,7 @@ void (*prof_register_command)(const char *command_name, int min_args, int max_ar
|
||||
void (*prof_register_timed)(void(*callback)(void), int interval_seconds) = NULL;
|
||||
|
||||
void (*prof_completer_add)(const char *key, char **items) = NULL;
|
||||
void (*prof_completer_remove)(const char *key, char **items) = NULL;
|
||||
|
||||
void (*prof_notify)(const char *message, int timeout_ms, const char *category) = NULL;
|
||||
|
||||
|
@ -49,6 +49,7 @@ void (*prof_register_command)(const char *command_name, int min_args, int max_ar
|
||||
void (*prof_register_timed)(void(*callback)(void), int interval_seconds);
|
||||
|
||||
void (*prof_completer_add)(const char *key, char **items);
|
||||
void (*prof_completer_remove)(const char *key, char **items);
|
||||
|
||||
void (*prof_notify)(const char *message, int timeout_ms, const char *category);
|
||||
|
||||
|
@ -213,6 +213,34 @@ python_api_completer_add(PyObject *self, PyObject *args)
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_completer_remove(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *key = NULL;
|
||||
PyObject *items = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO", &key, &items)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
Py_ssize_t len = PyList_Size(items);
|
||||
char *c_items[len];
|
||||
|
||||
Py_ssize_t i = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
PyObject *item = PyList_GetItem(items, i);
|
||||
char *c_item = PyString_AsString(item);
|
||||
c_items[i] = c_item;
|
||||
}
|
||||
c_items[len] = NULL;
|
||||
|
||||
allow_python_threads();
|
||||
autocompleters_remove(key, c_items);
|
||||
disable_python_threads();
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_notify(PyObject *self, PyObject *args)
|
||||
{
|
||||
@ -664,6 +692,7 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "register_command", python_api_register_command, METH_VARARGS, "Register a command." },
|
||||
{ "register_timed", python_api_register_timed, METH_VARARGS, "Register a timed function." },
|
||||
{ "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." },
|
||||
{ "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." },
|
||||
|
Loading…
x
Reference in New Issue
Block a user