infobar: Add gtk_info_bar_remove_action_widget

This is mainly for completeness, since gtk_container_remove
will not work for those anymore.
This commit is contained in:
Matthias Clasen 2020-05-07 12:28:33 -04:00
parent bc6643f3c2
commit 78d20b9301
3 changed files with 39 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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);