mirror of https://github.com/GNOME/gimp.git
app: add gimp_container_remove_handlers_by_{func,data}()
... which remove all handlers matching the given callback/callback- data. temp
This commit is contained in:
parent
5a9b5c1670
commit
0891f1275a
|
@ -115,6 +115,9 @@ static gboolean gimp_container_deserialize (GimpConfig *config,
|
|||
static void gimp_container_disconnect_callback (GimpObject *object,
|
||||
gpointer data);
|
||||
|
||||
static void gimp_container_free_handler (GimpContainer *container,
|
||||
GimpContainerHandler *handler);
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GimpContainer, gimp_container, GIMP_TYPE_OBJECT,
|
||||
G_ADD_PRIVATE (GimpContainer)
|
||||
|
@ -519,6 +522,37 @@ gimp_container_disconnect_callback (GimpObject *object,
|
|||
gimp_container_remove (container, object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_free_handler_foreach_func (GimpObject *object,
|
||||
GimpContainerHandler *handler)
|
||||
{
|
||||
gulong handler_id;
|
||||
|
||||
handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
|
||||
handler->quark));
|
||||
|
||||
if (handler_id)
|
||||
{
|
||||
g_signal_handler_disconnect (object, handler_id);
|
||||
|
||||
g_object_set_qdata (G_OBJECT (object), handler->quark, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_free_handler (GimpContainer *container,
|
||||
GimpContainerHandler *handler)
|
||||
{
|
||||
D (g_print ("%s: id = %d\n", G_STRFUNC, handler->quark));
|
||||
|
||||
gimp_container_foreach (container,
|
||||
(GFunc) gimp_container_free_handler_foreach_func,
|
||||
handler);
|
||||
|
||||
g_free (handler->signame);
|
||||
g_slice_free (GimpContainerHandler, handler);
|
||||
}
|
||||
|
||||
GType
|
||||
gimp_container_get_children_type (GimpContainer *container)
|
||||
{
|
||||
|
@ -1041,23 +1075,6 @@ gimp_container_add_handler (GimpContainer *container,
|
|||
return handler->quark;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_remove_handler_foreach_func (GimpObject *object,
|
||||
GimpContainerHandler *handler)
|
||||
{
|
||||
gulong handler_id;
|
||||
|
||||
handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
|
||||
handler->quark));
|
||||
|
||||
if (handler_id)
|
||||
{
|
||||
g_signal_handler_disconnect (object, handler_id);
|
||||
|
||||
g_object_set_qdata (G_OBJECT (object), handler->quark, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_remove_handler (GimpContainer *container,
|
||||
GQuark id)
|
||||
|
@ -1083,14 +1100,65 @@ gimp_container_remove_handler (GimpContainer *container,
|
|||
return;
|
||||
}
|
||||
|
||||
D (g_print ("%s: id = %d\n", G_STRFUNC, handler->quark));
|
||||
gimp_container_free_handler (container, handler);
|
||||
|
||||
gimp_container_foreach (container,
|
||||
(GFunc) gimp_container_remove_handler_foreach_func,
|
||||
handler);
|
||||
|
||||
container->priv->handlers = g_list_remove (container->priv->handlers, handler);
|
||||
|
||||
g_free (handler->signame);
|
||||
g_slice_free (GimpContainerHandler, handler);
|
||||
container->priv->handlers = g_list_delete_link (container->priv->handlers,
|
||||
list);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_remove_handlers_by_func (GimpContainer *container,
|
||||
GCallback callback,
|
||||
gpointer callback_data)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CONTAINER (container));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
list = container->priv->handlers;
|
||||
|
||||
while (list)
|
||||
{
|
||||
GimpContainerHandler *handler = list->data;
|
||||
GList *next = g_list_next (list);
|
||||
|
||||
if (handler->callback == callback &&
|
||||
handler->callback_data == callback_data)
|
||||
{
|
||||
gimp_container_free_handler (container, handler);
|
||||
|
||||
container->priv->handlers = g_list_delete_link (
|
||||
container->priv->handlers, list);
|
||||
}
|
||||
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_remove_handlers_by_data (GimpContainer *container,
|
||||
gpointer callback_data)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CONTAINER (container));
|
||||
|
||||
list = container->priv->handlers;
|
||||
|
||||
while (list)
|
||||
{
|
||||
GimpContainerHandler *handler = list->data;
|
||||
GList *next = g_list_next (list);
|
||||
|
||||
if (handler->callback_data == callback_data)
|
||||
{
|
||||
gimp_container_free_handler (container, handler);
|
||||
|
||||
container->priv->handlers = g_list_delete_link (
|
||||
container->priv->handlers, list);
|
||||
}
|
||||
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,6 +138,13 @@ GQuark gimp_container_add_handler (GimpContainer *contain
|
|||
gpointer callback_data);
|
||||
void gimp_container_remove_handler (GimpContainer *container,
|
||||
GQuark id);
|
||||
void gimp_container_remove_handlers_by_func
|
||||
(GimpContainer *container,
|
||||
GCallback callback,
|
||||
gpointer callback_data);
|
||||
void gimp_container_remove_handlers_by_data
|
||||
(GimpContainer *container,
|
||||
gpointer callback_data);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONTAINER_H__ */
|
||||
|
|
Loading…
Reference in New Issue