mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Store plugin completers by plugin name
This commit is contained in:
parent
fd218ac3e4
commit
71178b3696
@ -163,19 +163,19 @@ api_register_timed(const char *const plugin_name, void *callback, int interval_s
|
|||||||
void
|
void
|
||||||
api_completer_add(const char *const plugin_name, const char *key, char **items)
|
api_completer_add(const char *const plugin_name, const char *key, char **items)
|
||||||
{
|
{
|
||||||
autocompleters_add(key, items);
|
autocompleters_add(plugin_name, key, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
api_completer_remove(const char *const plugin_name, const char *key, char **items)
|
api_completer_remove(const char *const plugin_name, const char *key, char **items)
|
||||||
{
|
{
|
||||||
autocompleters_remove(key, items);
|
autocompleters_remove(plugin_name, key, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
api_completer_clear(const char *const plugin_name, const char *key)
|
api_completer_clear(const char *const plugin_name, const char *key)
|
||||||
{
|
{
|
||||||
autocompleters_clear(key);
|
autocompleters_clear(plugin_name, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -38,56 +38,71 @@
|
|||||||
|
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
|
|
||||||
static GHashTable *autocompleters;
|
static GHashTable *plugin_to_acs;
|
||||||
|
|
||||||
|
static void
|
||||||
|
_free_autocompleters(GHashTable *key_to_ac)
|
||||||
|
{
|
||||||
|
g_hash_table_destroy(key_to_ac);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocompleters_init(void)
|
autocompleters_init(void)
|
||||||
{
|
{
|
||||||
autocompleters = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)autocomplete_free);
|
plugin_to_acs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_autocompleters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocompleters_add(const char *key, char **items)
|
autocompleters_add(const char *const plugin_name, const char *key, char **items)
|
||||||
{
|
{
|
||||||
if (g_hash_table_contains(autocompleters, key)) {
|
GHashTable *key_to_ac = g_hash_table_lookup(plugin_to_acs, plugin_name);
|
||||||
Autocomplete existing_ac = g_hash_table_lookup(autocompleters, key);
|
if (key_to_ac) {
|
||||||
|
if (g_hash_table_contains(key_to_ac, key)) {
|
||||||
int i = 0;
|
Autocomplete existing_ac = g_hash_table_lookup(key_to_ac, key);
|
||||||
for (i = 0; i < g_strv_length(items); i++) {
|
autocomplete_add_all(existing_ac, items);
|
||||||
autocomplete_add(existing_ac, items[i]);
|
} else {
|
||||||
|
Autocomplete new_ac = autocomplete_new();
|
||||||
|
autocomplete_add_all(new_ac, items);
|
||||||
|
g_hash_table_insert(key_to_ac, strdup(key), new_ac);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
key_to_ac = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)autocomplete_free);
|
||||||
Autocomplete new_ac = autocomplete_new();
|
Autocomplete new_ac = autocomplete_new();
|
||||||
int i = 0;
|
autocomplete_add_all(new_ac, items);
|
||||||
for (i = 0; i < g_strv_length(items); i++) {
|
g_hash_table_insert(key_to_ac, strdup(key), new_ac);
|
||||||
autocomplete_add(new_ac, items[i]);
|
g_hash_table_insert(plugin_to_acs, strdup(plugin_name), key_to_ac);
|
||||||
}
|
|
||||||
g_hash_table_insert(autocompleters, strdup(key), new_ac);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocompleters_remove(const char *key, char **items)
|
autocompleters_remove(const char *const plugin_name, const char *key, char **items)
|
||||||
{
|
{
|
||||||
if (!g_hash_table_contains(autocompleters, key)) {
|
GHashTable *key_to_ac = g_hash_table_lookup(plugin_to_acs, plugin_name);
|
||||||
|
if (!key_to_ac) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete ac = g_hash_table_lookup(autocompleters, key);
|
if (!g_hash_table_contains(key_to_ac, key)) {
|
||||||
int i = 0;
|
return;
|
||||||
for (i = 0; i < g_strv_length(items); i++) {
|
|
||||||
autocomplete_remove(ac, items[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Autocomplete ac = g_hash_table_lookup(key_to_ac, key);
|
||||||
|
autocomplete_remove_all(ac, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocompleters_clear(const char *key)
|
autocompleters_clear(const char *const plugin_name, const char *key)
|
||||||
{
|
{
|
||||||
if (!g_hash_table_contains(autocompleters, key)) {
|
GHashTable *key_to_ac = g_hash_table_lookup(plugin_to_acs, plugin_name);
|
||||||
|
if (!key_to_ac) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete ac = g_hash_table_lookup(autocompleters, key);
|
if (!g_hash_table_contains(key_to_ac, key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Autocomplete ac = g_hash_table_lookup(key_to_ac, key);
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,17 +111,26 @@ autocompleters_complete(const char * const input)
|
|||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
GList *keys = g_hash_table_get_keys(autocompleters);
|
GList *ac_hashes = g_hash_table_get_values(plugin_to_acs);
|
||||||
GList *curr = keys;
|
GList *curr_hash = ac_hashes;
|
||||||
while (curr) {
|
while (curr_hash) {
|
||||||
result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(autocompleters, curr->data), TRUE);
|
GHashTable *key_to_ac = curr_hash->data;
|
||||||
if (result) {
|
|
||||||
g_list_free(keys);
|
GList *keys = g_hash_table_get_keys(key_to_ac);
|
||||||
return result;
|
GList *curr = keys;
|
||||||
|
while (curr) {
|
||||||
|
result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(key_to_ac, curr->data), TRUE);
|
||||||
|
if (result) {
|
||||||
|
g_list_free(keys);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
curr = g_list_next(curr);
|
g_list_free(keys);
|
||||||
|
|
||||||
|
curr_hash = g_list_next(curr_hash);
|
||||||
}
|
}
|
||||||
g_list_free(keys);
|
g_list_free(ac_hashes);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -114,17 +138,24 @@ autocompleters_complete(const char * const input)
|
|||||||
void
|
void
|
||||||
autocompleters_reset(void)
|
autocompleters_reset(void)
|
||||||
{
|
{
|
||||||
GList *acs = g_hash_table_get_values(autocompleters);
|
GList *ac_hashes = g_hash_table_get_values(plugin_to_acs);
|
||||||
GList *curr = acs;
|
GList *curr_hash = ac_hashes;
|
||||||
while (curr) {
|
while (curr_hash) {
|
||||||
autocomplete_reset(curr->data);
|
GList *acs = g_hash_table_get_values(curr_hash->data);
|
||||||
curr = g_list_next(curr);
|
GList *curr = acs;
|
||||||
|
while (curr) {
|
||||||
|
autocomplete_reset(curr->data);
|
||||||
|
curr = g_list_next(curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_free(acs);
|
||||||
|
curr_hash = g_list_next(curr_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free(acs);
|
g_list_free(ac_hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void autocompleters_destroy(void)
|
void autocompleters_destroy(void)
|
||||||
{
|
{
|
||||||
g_hash_table_destroy(autocompleters);
|
g_hash_table_destroy(plugin_to_acs);
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
void autocompleters_init(void);
|
void autocompleters_init(void);
|
||||||
void autocompleters_add(const char *key, char **items);
|
void autocompleters_add(const char *const plugin_name, const char *key, char **items);
|
||||||
void autocompleters_remove(const char *key, char **items);
|
void autocompleters_remove(const char *const plugin_name, const char *key, char **items);
|
||||||
void autocompleters_clear(const char *key);
|
void autocompleters_clear(const char *const plugin_name, const char *key);
|
||||||
char* autocompleters_complete(const char * const input);
|
char* autocompleters_complete(const char * const input);
|
||||||
void autocompleters_reset(void);
|
void autocompleters_reset(void);
|
||||||
void autocompleters_destroy(void);
|
void autocompleters_destroy(void);
|
||||||
|
@ -117,6 +117,15 @@ autocomplete_add(Autocomplete ac, const char *item)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
autocomplete_add_all(Autocomplete ac, char **items)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < g_strv_length(items); i++) {
|
||||||
|
autocomplete_add(ac, items[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocomplete_remove(Autocomplete ac, const char *const item)
|
autocomplete_remove(Autocomplete ac, const char *const item)
|
||||||
{
|
{
|
||||||
@ -139,6 +148,15 @@ autocomplete_remove(Autocomplete ac, const char *const item)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
autocomplete_remove_all(Autocomplete ac, char **items)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < g_strv_length(items); i++) {
|
||||||
|
autocomplete_remove(ac, items[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GSList*
|
GSList*
|
||||||
autocomplete_create_list(Autocomplete ac)
|
autocomplete_create_list(Autocomplete ac)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,9 @@ void autocomplete_clear(Autocomplete ac);
|
|||||||
void autocomplete_free(Autocomplete ac);
|
void autocomplete_free(Autocomplete ac);
|
||||||
|
|
||||||
void autocomplete_add(Autocomplete ac, const char *item);
|
void autocomplete_add(Autocomplete ac, const char *item);
|
||||||
|
void autocomplete_add_all(Autocomplete ac, char **items);
|
||||||
void autocomplete_remove(Autocomplete ac, const char *const item);
|
void autocomplete_remove(Autocomplete ac, const char *const item);
|
||||||
|
void autocomplete_remove_all(Autocomplete ac, char **items);
|
||||||
|
|
||||||
// find the next item prefixed with search string
|
// find the next item prefixed with search string
|
||||||
gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote);
|
gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote);
|
||||||
|
Loading…
Reference in New Issue
Block a user