From 78d20b9301dde74b7fe4c4d6899fcf35937658da Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 7 May 2020 12:28:33 -0400 Subject: [PATCH] infobar: Add gtk_info_bar_remove_action_widget This is mainly for completeness, since gtk_container_remove will not work for those anymore. --- docs/reference/gtk/gtk4-sections.txt | 1 + gtk/gtkinfobar.c | 37 ++++++++++++++++++++++++++-- gtk/gtkinfobar.h | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 6ac6044a70..ba5d96cd7b 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -1743,6 +1743,7 @@ GtkInfoBar gtk_info_bar_new gtk_info_bar_new_with_buttons gtk_info_bar_add_action_widget +gtk_info_bar_remove_action_widget gtk_info_bar_add_button gtk_info_bar_add_buttons gtk_info_bar_set_response_sensitive diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c index 485c8956e5..a8baa91f1c 100644 --- a/gtk/gtkinfobar.c +++ b/gtk/gtkinfobar.c @@ -168,7 +168,8 @@ typedef struct _ResponseData ResponseData; struct _ResponseData { - gint response_id; + int response_id; + gulong handler_id; }; enum @@ -288,6 +289,16 @@ get_response_data (GtkWidget *widget, return ad; } +static void +clear_response_data (GtkWidget *widget) +{ + ResponseData *data; + + data = get_response_data (widget, FALSE); + g_signal_handler_disconnect (widget, data->handler_id); + g_object_set_data (G_OBJECT (widget), "gtk-info-bar-reponse-data", NULL); +} + static GtkWidget * find_button (GtkInfoBar *info_bar, gint response_id) @@ -594,7 +605,7 @@ gtk_info_bar_add_action_widget (GtkInfoBar *info_bar, closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated), G_OBJECT (info_bar)); - g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE); + ad->handler_id = g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE); } else g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar"); @@ -602,6 +613,28 @@ gtk_info_bar_add_action_widget (GtkInfoBar *info_bar, gtk_container_add (GTK_CONTAINER (info_bar->action_area), child); } +/** + * gtk_info_bar_remove_action_widget: + * @info_bar: a #GtkInfoBar + * @widget: an action widget to remove + * + * Removes a widget from the action area of @info_bar, after + * it been put there by a call to gtk_info_bar_add_action_widget() + * or gtk_info_bar_add_button(). + */ +void +gtk_info_bar_remove_action_widget (GtkInfoBar *info_bar, + GtkWidget *widget) +{ + g_return_if_fail (GTK_IS_INFO_BAR (info_bar)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (gtk_widget_get_parent (widget) == info_bar->action_area); + + clear_response_data (widget); + + gtk_container_remove (GTK_CONTAINER (info_bar->action_area), widget); +} + /** * gtk_info_bar_add_button: * @info_bar: a #GtkInfoBar diff --git a/gtk/gtkinfobar.h b/gtk/gtkinfobar.h index 139b609afc..3a2997d927 100644 --- a/gtk/gtkinfobar.h +++ b/gtk/gtkinfobar.h @@ -58,6 +58,9 @@ void gtk_info_bar_add_action_widget (GtkInfoBar *info_bar, GtkWidget *child, gint response_id); GDK_AVAILABLE_IN_ALL +void gtk_info_bar_remove_action_widget (GtkInfoBar *info_bar, + GtkWidget *widget); +GDK_AVAILABLE_IN_ALL GtkWidget *gtk_info_bar_add_button (GtkInfoBar *info_bar, const gchar *button_text, gint response_id);