mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Store plugin window callbacks by plugin name
This commit is contained in:
parent
a779ad0764
commit
0d7b4cb4a7
@ -306,7 +306,9 @@ api_win_create(
|
||||
window->callback = callback;
|
||||
window->callback_exec = callback_exec;
|
||||
window->callback_destroy = callback_destroy;
|
||||
callbacks_add_window_handler(tag, window);
|
||||
|
||||
callbacks_add_window_handler(plugin_name, tag, window);
|
||||
|
||||
wins_new_plugin(tag);
|
||||
|
||||
// set status bar active
|
||||
|
@ -57,6 +57,12 @@ _free_window_callback(PluginWindowCallback *window_callback)
|
||||
free(window_callback);
|
||||
}
|
||||
|
||||
static void
|
||||
_free_window_callbacks(GHashTable *window_callbacks)
|
||||
{
|
||||
g_hash_table_destroy(window_callbacks);
|
||||
}
|
||||
|
||||
static void
|
||||
_free_command_help(CommandHelp *help)
|
||||
{
|
||||
@ -129,7 +135,7 @@ callbacks_init(void)
|
||||
{
|
||||
p_commands = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_command_hash);
|
||||
p_timed_functions = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_timed_function_list);
|
||||
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback);
|
||||
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callbacks);
|
||||
}
|
||||
|
||||
// TODO move to plugin destroy functions
|
||||
@ -170,16 +176,37 @@ callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_fu
|
||||
}
|
||||
|
||||
void
|
||||
callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback)
|
||||
callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback)
|
||||
{
|
||||
g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback);
|
||||
GHashTable *window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name);
|
||||
if (window_callbacks) {
|
||||
g_hash_table_insert(window_callbacks, strdup(tag), window_callback);
|
||||
} else {
|
||||
window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback);
|
||||
g_hash_table_insert(window_callbacks, strdup(tag), window_callback);
|
||||
g_hash_table_insert(p_window_callbacks, strdup(plugin_name), window_callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
callbacks_get_window_handler(const char *tag)
|
||||
{
|
||||
if (p_window_callbacks) {
|
||||
return g_hash_table_lookup(p_window_callbacks, tag);
|
||||
GList *window_callback_hashes = g_hash_table_get_values(p_window_callbacks);
|
||||
GList *curr_hash = window_callback_hashes;
|
||||
while (curr_hash) {
|
||||
GHashTable *window_callback_hash = curr_hash->data;
|
||||
PluginWindowCallback *callback = g_hash_table_lookup(window_callback_hash, tag);
|
||||
if (callback) {
|
||||
g_list_free(window_callback_hashes);
|
||||
return callback;
|
||||
}
|
||||
|
||||
curr_hash = g_list_next(curr_hash);
|
||||
}
|
||||
|
||||
g_list_free(window_callback_hashes);
|
||||
return NULL;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ void callbacks_close(void);
|
||||
|
||||
void callbacks_add_command(const char *const plugin_name, PluginCommand *command);
|
||||
void callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_function);
|
||||
void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback);
|
||||
void callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback);
|
||||
void * callbacks_get_window_handler(const char *tag);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user