general: Use GtkButton as a container

GtkButton lost its GtkImage-related API in GTK4, and should be used as
a regular container.

Note #1: In x-content-bar.c, this requires using gtk_box_pack_start()
and gtk_container_add(), which must later be replaced, respectively,
by gtk_box_preopend() and gtk_button_add_child() when switching to
GTK4. However, it's worth refactoring the code in advance such that
we can simply find and replace funciton calls later.

Rebased and ammended by António Fernandes <antoniof@gnome.org>
This commit is contained in:
Ernestas Kulik 2018-07-10 12:17:39 +03:00 committed by António Fernandes
parent f3e1d8a46e
commit a2d5dafa05
3 changed files with 24 additions and 16 deletions

View file

@ -32,7 +32,7 @@ struct _NautilusProgressInfoWidgetPrivate
GtkWidget *details; /* GtkLabel */
GtkWidget *progress_bar;
GtkWidget *button;
GtkWidget *done_image;
GtkWidget *image;
};
enum
@ -49,7 +49,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (NautilusProgressInfoWidget, nautilus_progress_info_w
static void
info_finished (NautilusProgressInfoWidget *self)
{
gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->image),
"object-select-symbolic",
GTK_ICON_SIZE_BUTTON);
gtk_widget_set_sensitive (self->priv->button, FALSE);
}
@ -125,7 +127,9 @@ nautilus_progress_info_widget_constructed (GObject *obj)
if (nautilus_progress_info_get_is_finished (self->priv->info))
{
gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->image),
"object-select-symbolic",
GTK_ICON_SIZE_BUTTON);
}
gtk_widget_set_sensitive (self->priv->button,
@ -213,7 +217,7 @@ nautilus_progress_info_widget_class_init (NautilusProgressInfoWidgetClass *klass
gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, details);
gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, progress_bar);
gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, button);
gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, done_image);
gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, image);
}
GtkWidget *

View file

@ -157,6 +157,7 @@ nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar,
GAppInfo *app;
gboolean has_app;
guint i;
GtkWidget *box;
default_app = g_ptr_array_index (apps, n);
has_app = FALSE;
@ -187,13 +188,17 @@ nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar,
}
name = g_app_info_get_name (default_app);
button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
name,
n);
button = gtk_info_bar_add_button (GTK_INFO_BAR (bar), name, n);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
if (image != NULL)
{
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
}
gtk_box_pack_start (GTK_BOX (box), gtk_label_new (name), FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (button), box);
gtk_button_set_image (GTK_BUTTON (button), image);
gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
gtk_button_set_label (GTK_BUTTON (button), name);
gtk_widget_show (button);
}

View file

@ -51,10 +51,14 @@
<property name="receives_default">True</property>
<property name="valign">center</property>
<property name="margin_start">20</property>
<property name="image">cancel_image</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkImage" id="image">
<property name="icon-name">window-close-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
@ -84,9 +88,4 @@
</packing>
</child>
</template>
<object class="GtkImage" id="done_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-select-symbolic</property>
</object>
</interface>