From d254f693f5da34b8e0493c99999efa0d55494a20 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 8 May 2019 06:01:01 +0200 Subject: Remove deprecated gtk_button_set_alignment call The recommended method is to set the child's `halign` property. However, because our button has two children that automatically get wrapped in a GtkAlignment container, we need to set the alignment of that child after the image and the label have been added. Also fix an assertion failure when no icon could be found for a file. --- dragon.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'dragon.c') diff --git a/dragon.c b/dragon.c index 869c118..f66fb46 100644 --- a/dragon.c +++ b/dragon.c @@ -107,8 +107,8 @@ void drag_data_get(GtkWidget *widget, } GtkButton *add_button(char *label, struct draggable_thing *dragdata, int type) { - GtkWidget *button = gtk_button_new(); - gtk_button_set_label(GTK_BUTTON(button), label); + GtkWidget *button = gtk_button_new_with_label(label); + GtkTargetList *targetlist = gtk_drag_source_get_target_list(GTK_WIDGET(button)); if (targetlist) gtk_target_list_ref(targetlist); @@ -152,13 +152,18 @@ void add_file_button(char *filename) { GIcon *icon = g_file_info_get_icon(fileinfo); GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, icon, 48, 0); - gtk_button_set_image(button, - gtk_image_new_from_pixbuf( - gtk_icon_info_load_icon(icon_info, NULL) - )); - gtk_button_set_alignment(button, 0, 0); - gtk_button_set_always_show_image(button, true); + if (icon_info) { + GtkWidget *image = gtk_image_new_from_pixbuf( + gtk_icon_info_load_icon(icon_info, NULL)); + gtk_button_set_image(button, image); + gtk_button_set_always_show_image(button, true); + } + + GList *child = g_list_first( + gtk_container_get_children(GTK_CONTAINER(button))); + if (child) + gtk_widget_set_halign(GTK_WIDGET(child->data), GTK_ALIGN_START); } void add_uri_button(char *uri) { -- cgit