[nautilus/wip/antoniof/new-pathbar: 33/41] pathbar: Become a bin




commit ad8bd21f557eada7d9a0a36aebfa26e76da252a3
Author: António Fernandes <antoniof gnome org>
Date:   Sat Dec 18 22:29:51 2021 +0000

    pathbar: Become a bin
    
    In GTK4 we are not going to be able to subclass any widget other than
    the GtkWidget base class.
    
    But subclassing GtkWidget implies adding a lot of boilerplate to
    behave as a container.
    
    The easy way around that is going to be AdwBin.

 src/nautilus-gtk4-helpers.c | 9 +++++++++
 src/nautilus-gtk4-helpers.h | 5 +++++
 src/nautilus-pathbar.c      | 6 +++---
 src/nautilus-pathbar.h      | 2 +-
 4 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c
index 60da7672a..9b8a9947e 100644
--- a/src/nautilus-gtk4-helpers.c
+++ b/src/nautilus-gtk4-helpers.c
@@ -1,5 +1,14 @@
 #include "nautilus-gtk4-helpers.h"
 
+void
+adw_bin_set_child (AdwBin    *bin,
+                   GtkWidget *child)
+{
+    g_assert (GTK_IS_BIN (bin));
+
+    gtk_container_add (GTK_CONTAINER (bin), child);
+}
+
 void
 gtk_button_set_child (GtkButton *button,
                       GtkWidget *child)
diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h
index 201183c15..8c5358e4d 100644
--- a/src/nautilus-gtk4-helpers.h
+++ b/src/nautilus-gtk4-helpers.h
@@ -7,6 +7,11 @@
 G_BEGIN_DECLS
 #if GTK_MAJOR_VERSION < 4
 
+#define AdwBin GtkBin
+#define ADW_BIN GTK_BIN
+
+void adw_bin_set_child             (AdwBin            *bin,
+                                    GtkWidget         *child);
 void gtk_button_set_child          (GtkButton         *button,
                                     GtkWidget         *child);
 void gtk_box_append                (GtkBox            *box,
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 3d9637887..16dd51a31 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -84,7 +84,7 @@ typedef struct
 
 struct _NautilusPathBar
 {
-    GtkBox parent_instance;
+    GtkBin parent_instance;
 
     GtkWidget *scrolled;
     GtkWidget *buttons_box;
@@ -106,7 +106,7 @@ struct _NautilusPathBar
     GMenu *button_menu;
 };
 
-G_DEFINE_TYPE (NautilusPathBar, nautilus_path_bar, GTK_TYPE_BOX);
+G_DEFINE_TYPE (NautilusPathBar, nautilus_path_bar, GTK_TYPE_BIN);
 
 static void nautilus_path_bar_check_icon_theme (NautilusPathBar *self);
 static void nautilus_path_bar_update_button_appearance (ButtonData *button_data,
@@ -225,7 +225,7 @@ nautilus_path_bar_init (NautilusPathBar *self)
                                     /* hscrollbar-policy */ GTK_POLICY_EXTERNAL,
                                     /* vscrollbar-policy */ GTK_POLICY_NEVER);
     gtk_widget_set_hexpand (self->scrolled, TRUE);
-    gtk_box_append (GTK_BOX (self), self->scrolled);
+    adw_bin_set_child (ADW_BIN (self), self->scrolled);
 
     adjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (self->scrolled));
     g_signal_connect (adjustment, "changed", (GCallback) on_adjustment_changed, NULL);
diff --git a/src/nautilus-pathbar.h b/src/nautilus-pathbar.h
index d70b71572..3ac290165 100644
--- a/src/nautilus-pathbar.h
+++ b/src/nautilus-pathbar.h
@@ -22,7 +22,7 @@
 #include <gio/gio.h>
 
 #define NAUTILUS_TYPE_PATH_BAR (nautilus_path_bar_get_type ())
-G_DECLARE_FINAL_TYPE (NautilusPathBar, nautilus_path_bar, NAUTILUS, PATH_BAR, GtkBox)
+G_DECLARE_FINAL_TYPE (NautilusPathBar, nautilus_path_bar, NAUTILUS, PATH_BAR, GtkBin)
 
 void     nautilus_path_bar_set_path                       (NautilusPathBar *path_bar,
                                                            GFile           *file);


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