[nautilus/wip/antoniof/gtk4-preparation-miscellaneous: 1/3] general: Use GtkButton as a container




commit 3a6f5493d81f4ec6b6617e973453a06b7814fb65
Author: Ernestas Kulik <ernestask gnome org>
Date:   Tue Jul 10 12:17:39 2018 +0300

    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.
    
    Note #2: In file-contlict-dialog.c, gtk_button_set_image() is removed
    without replacement because the image was not used/shown anyway
    (the button has a label and always-show-image is False by default).
    
    Rebased and ammended by António Fernandes <antoniof gnome org>

 src/nautilus-file-conflict-dialog.c               |  3 ---
 src/nautilus-progress-info-widget.c               | 12 ++++++++----
 src/nautilus-x-content-bar.c                      | 17 +++++++++++------
 src/resources/ui/nautilus-progress-info-widget.ui | 11 +++++------
 4 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index 678f96323..56e4ca9d3 100644
--- a/src/nautilus-file-conflict-dialog.c
+++ b/src/nautilus-file-conflict-dialog.c
@@ -339,9 +339,6 @@ nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
     gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
 
     widget = gtk_button_new_with_label (_("Reset"));
-    gtk_button_set_image (GTK_BUTTON (widget),
-                          gtk_image_new_from_icon_name ("edit-undo",
-                                                        GTK_ICON_SIZE_MENU));
     gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6);
     g_signal_connect (widget, "clicked",
                       G_CALLBACK (reset_button_clicked_cb), dialog);
diff --git a/src/nautilus-progress-info-widget.c b/src/nautilus-progress-info-widget.c
index 3d241336f..fd70d9781 100644
--- a/src/nautilus-progress-info-widget.c
+++ b/src/nautilus-progress-info-widget.c
@@ -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 *
diff --git a/src/nautilus-x-content-bar.c b/src/nautilus-x-content-bar.c
index f37c84668..a7bbce15e 100644
--- a/src/nautilus-x-content-bar.c
+++ b/src/nautilus-x-content-bar.c
@@ -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);
     }
 
diff --git a/src/resources/ui/nautilus-progress-info-widget.ui 
b/src/resources/ui/nautilus-progress-info-widget.ui
index 72c18e850..3dda2fcd4 100644
--- a/src/resources/ui/nautilus-progress-info-widget.ui
+++ b/src/resources/ui/nautilus-progress-info-widget.ui
@@ -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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]