[nautilus/gtk4-preparation-trunk: 40/64] notebook: Don't subclass GtkNotebook




commit cb555c0147b181b8d7b6e52b3c07631d5b0e5f62
Author: António Fernandes <antoniof gnome org>
Date:   Sun Dec 19 17:02:49 2021 +0000

    notebook: Don't subclass GtkNotebook
    
    GtkNotebook is a final class in GTK 4.
    
    Drop the NautliusNotebook class and have its API act on GtkNotebook.

 src/nautilus-notebook.c             | 134 ++++++++++++++----------------------
 src/nautilus-notebook.h             |  29 ++++----
 src/nautilus-window-slot-dnd.c      |   2 +-
 src/nautilus-window.c               |  20 +++---
 src/resources/ui/nautilus-window.ui |   2 +-
 5 files changed, 77 insertions(+), 110 deletions(-)
---
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 2681a47fc..e8e93943f 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -37,43 +37,21 @@
 
 #define AFTER_ALL_TABS -1
 
-struct _NautilusNotebook
-{
-    GtkNotebook parent_instance;
-};
-
-G_DEFINE_TYPE (NautilusNotebook, nautilus_notebook, GTK_TYPE_NOTEBOOK);
-
-static void
-nautilus_notebook_dispose (GObject *object)
-{
-    G_OBJECT_CLASS (nautilus_notebook_parent_class)->dispose (object);
-}
-
-static void
-nautilus_notebook_class_init (NautilusNotebookClass *klass)
-{
-    GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-    object_class->dispose = nautilus_notebook_dispose;
-}
-
 static gint
-find_tab_num_at_pos (NautilusNotebook *notebook,
-                     gint              abs_x,
-                     gint              abs_y)
+find_tab_num_at_pos (GtkNotebook *notebook,
+                     gint         abs_x,
+                     gint         abs_y)
 {
     int page_num = 0;
-    GtkNotebook *nb = GTK_NOTEBOOK (notebook);
     GtkWidget *page;
     GtkAllocation allocation;
 
-    while ((page = gtk_notebook_get_nth_page (nb, page_num)))
+    while ((page = gtk_notebook_get_nth_page (notebook, page_num)))
     {
         GtkWidget *tab;
         gint max_x, max_y;
 
-        tab = gtk_notebook_get_tab_label (nb, page);
+        tab = gtk_notebook_get_tab_label (notebook, page);
         g_return_val_if_fail (tab != NULL, -1);
 
         if (!gtk_widget_get_mapped (GTK_WIDGET (tab)))
@@ -119,32 +97,31 @@ on_page_added (GtkNotebook *notebook,
     gtk_notebook_set_tab_detachable (notebook, child, TRUE);
 }
 
-static void
-nautilus_notebook_init (NautilusNotebook *notebook)
+void
+nautilus_notebook_setup (GtkNotebook *notebook)
 {
-    gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
-    gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
-    gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
+    gtk_notebook_set_scrollable (notebook, TRUE);
+    gtk_notebook_set_show_border (notebook, FALSE);
+    gtk_notebook_set_show_tabs (notebook, FALSE);
 
     g_signal_connect (notebook, "page-removed", G_CALLBACK (on_page_removed), NULL);
     g_signal_connect (notebook, "page-added", G_CALLBACK (on_page_added), NULL);
 }
 
 gboolean
-nautilus_notebook_contains_slot (NautilusNotebook   *notebook,
+nautilus_notebook_contains_slot (GtkNotebook        *notebook,
                                  NautilusWindowSlot *slot)
 {
-    GtkNotebook *container = GTK_NOTEBOOK (notebook);
     GtkWidget *child;
     gint n_pages;
     gboolean found = FALSE;
 
     g_return_val_if_fail (slot != NULL, FALSE);
 
-    n_pages = gtk_notebook_get_n_pages (container);
+    n_pages = gtk_notebook_get_n_pages (notebook);
     for (gint i = 0; i < n_pages; i++)
     {
-        child = gtk_notebook_get_nth_page (container, i);
+        child = gtk_notebook_get_nth_page (notebook, i);
         if ((gpointer) child == (gpointer) slot)
         {
             found = TRUE;
@@ -156,10 +133,10 @@ nautilus_notebook_contains_slot (NautilusNotebook   *notebook,
 }
 
 gboolean
-nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook,
-                                   gint              x,
-                                   gint              y,
-                                   gint             *position)
+nautilus_notebook_get_tab_clicked (GtkNotebook *notebook,
+                                   gint         x,
+                                   gint         y,
+                                   gint        *position)
 {
     gint tab_num;
 
@@ -173,16 +150,16 @@ nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook,
 }
 
 void
-nautilus_notebook_sync_loading (NautilusNotebook   *notebook,
+nautilus_notebook_sync_loading (GtkNotebook        *notebook,
                                 NautilusWindowSlot *slot)
 {
     GtkWidget *tab_label, *spinner, *icon;
     gboolean active, allow_stop;
 
-    g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+    g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
     g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
 
-    tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook),
+    tab_label = gtk_notebook_get_tab_label (notebook,
                                             GTK_WIDGET (slot));
     g_return_if_fail (GTK_IS_WIDGET (tab_label));
 
@@ -214,7 +191,7 @@ nautilus_notebook_sync_loading (NautilusNotebook   *notebook,
 }
 
 void
-nautilus_notebook_sync_tab_label (NautilusNotebook   *notebook,
+nautilus_notebook_sync_tab_label (GtkNotebook        *notebook,
                                   NautilusWindowSlot *slot)
 {
     GtkWidget *hbox, *label;
@@ -222,10 +199,10 @@ nautilus_notebook_sync_tab_label (NautilusNotebook   *notebook,
     GFile *location;
     const gchar *title_name;
 
-    g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+    g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
     g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
 
-    hbox = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), GTK_WIDGET (slot));
+    hbox = gtk_notebook_get_tab_label (notebook, GTK_WIDGET (slot));
     g_return_if_fail (GTK_IS_WIDGET (hbox));
 
     label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
@@ -258,7 +235,7 @@ nautilus_notebook_sync_tab_label (NautilusNotebook   *notebook,
 }
 
 static GtkWidget *
-build_tab_label (NautilusNotebook   *notebook,
+build_tab_label (GtkNotebook        *notebook,
                  NautilusWindowSlot *slot)
 {
     GtkWidget *box;
@@ -315,20 +292,19 @@ build_tab_label (NautilusNotebook   *notebook,
 }
 
 int
-nautilus_notebook_add_tab (NautilusNotebook   *notebook,
+nautilus_notebook_add_tab (GtkNotebook        *notebook,
                            NautilusWindowSlot *slot,
                            int                 position,
                            gboolean            jump_to)
 {
-    GtkNotebook *gnotebook = GTK_NOTEBOOK (notebook);
     GtkWidget *tab_label;
 
-    g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), -1);
+    g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1);
     g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), -1);
 
     tab_label = build_tab_label (notebook, slot);
 
-    position = gtk_notebook_insert_page (GTK_NOTEBOOK (notebook),
+    position = gtk_notebook_insert_page (notebook,
                                          GTK_WIDGET (slot),
                                          tab_label,
                                          position);
@@ -344,46 +320,40 @@ nautilus_notebook_add_tab (NautilusNotebook   *notebook,
 
     if (jump_to)
     {
-        gtk_notebook_set_current_page (gnotebook, position);
+        gtk_notebook_set_current_page (notebook, position);
     }
 
     return position;
 }
 
 void
-nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook,
-                                                  int               offset)
+nautilus_notebook_reorder_current_child_relative (GtkNotebook *notebook,
+                                                  int          offset)
 {
-    GtkNotebook *gnotebook;
     GtkWidget *child;
     int page;
 
-    g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+    g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
     if (!nautilus_notebook_can_reorder_current_child_relative (notebook, offset))
     {
         return;
     }
 
-    gnotebook = GTK_NOTEBOOK (notebook);
-
-    page = gtk_notebook_get_current_page (gnotebook);
-    child = gtk_notebook_get_nth_page (gnotebook, page);
-    gtk_notebook_reorder_child (gnotebook, child, page + offset);
+    page = gtk_notebook_get_current_page (notebook);
+    child = gtk_notebook_get_nth_page (notebook, page);
+    gtk_notebook_reorder_child (notebook, child, page + offset);
 }
 
 static gboolean
-nautilus_notebook_is_valid_relative_position (NautilusNotebook *notebook,
-                                              int               offset)
+nautilus_notebook_is_valid_relative_position (GtkNotebook *notebook,
+                                              int          offset)
 {
-    GtkNotebook *gnotebook;
     int page;
     int n_pages;
 
-    gnotebook = GTK_NOTEBOOK (notebook);
-
-    page = gtk_notebook_get_current_page (gnotebook);
-    n_pages = gtk_notebook_get_n_pages (gnotebook) - 1;
+    page = gtk_notebook_get_current_page (notebook);
+    n_pages = gtk_notebook_get_n_pages (notebook) - 1;
     if (page < 0 ||
         (offset < 0 && page < -offset) ||
         (offset > 0 && page > n_pages - offset))
@@ -395,27 +365,27 @@ nautilus_notebook_is_valid_relative_position (NautilusNotebook *notebook,
 }
 
 gboolean
-nautilus_notebook_can_reorder_current_child_relative (NautilusNotebook *notebook,
-                                                      int               offset)
+nautilus_notebook_can_reorder_current_child_relative (GtkNotebook *notebook,
+                                                      int          offset)
 {
-    g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), FALSE);
+    g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE);
 
     return nautilus_notebook_is_valid_relative_position (notebook, offset);
 }
 
 void
-nautilus_notebook_next_page (NautilusNotebook *notebook)
+nautilus_notebook_next_page (GtkNotebook *notebook)
 {
     gint current_page, n_pages;
 
-    g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+    g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
-    current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-    n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+    current_page = gtk_notebook_get_current_page (notebook);
+    n_pages = gtk_notebook_get_n_pages (notebook);
 
     if (current_page < n_pages - 1)
     {
-        gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
+        gtk_notebook_next_page (notebook);
     }
     else
     {
@@ -427,23 +397,23 @@ nautilus_notebook_next_page (NautilusNotebook *notebook)
 
         if (wrap_around)
         {
-            gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
+            gtk_notebook_set_current_page (notebook, 0);
         }
     }
 }
 
 void
-nautilus_notebook_prev_page (NautilusNotebook *notebook)
+nautilus_notebook_prev_page (GtkNotebook *notebook)
 {
     gint current_page;
 
-    g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+    g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
-    current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+    current_page = gtk_notebook_get_current_page (notebook);
 
     if (current_page > 0)
     {
-        gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
+        gtk_notebook_prev_page (notebook);
     }
     else
     {
@@ -455,7 +425,7 @@ nautilus_notebook_prev_page (NautilusNotebook *notebook)
 
         if (wrap_around)
         {
-            gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), -1);
+            gtk_notebook_set_current_page (notebook, -1);
         }
     }
 }
diff --git a/src/nautilus-notebook.h b/src/nautilus-notebook.h
index ad227d183..bbc17b00d 100644
--- a/src/nautilus-notebook.h
+++ b/src/nautilus-notebook.h
@@ -31,32 +31,29 @@
 
 G_BEGIN_DECLS
 
-#define NAUTILUS_TYPE_NOTEBOOK         (nautilus_notebook_get_type ())
-G_DECLARE_FINAL_TYPE (NautilusNotebook, nautilus_notebook, NAUTILUS, NOTEBOOK, GtkNotebook)
-
-int            nautilus_notebook_add_tab       (NautilusNotebook *nb,
+int            nautilus_notebook_add_tab       (GtkNotebook *nb,
                                                 NautilusWindowSlot *slot,
                                                 int position,
                                                 gboolean jump_to);
        
-void           nautilus_notebook_sync_tab_label (NautilusNotebook *nb,
+void           nautilus_notebook_sync_tab_label (GtkNotebook *nb,
                                                  NautilusWindowSlot *slot);
-void           nautilus_notebook_sync_loading   (NautilusNotebook *nb,
+void           nautilus_notebook_sync_loading   (GtkNotebook *nb,
                                                  NautilusWindowSlot *slot);
 
-void           nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook,
+void           nautilus_notebook_reorder_current_child_relative (GtkNotebook *notebook,
                                                                  int offset);
-gboolean        nautilus_notebook_can_reorder_current_child_relative (NautilusNotebook *notebook,
+gboolean        nautilus_notebook_can_reorder_current_child_relative (GtkNotebook *notebook,
                                                                      int offset);
-void            nautilus_notebook_prev_page (NautilusNotebook *notebook);
-void            nautilus_notebook_next_page (NautilusNotebook *notebook);
+void            nautilus_notebook_prev_page (GtkNotebook *notebook);
+void            nautilus_notebook_next_page (GtkNotebook *notebook);
 
-gboolean        nautilus_notebook_contains_slot (NautilusNotebook   *notebook,
+gboolean        nautilus_notebook_contains_slot (GtkNotebook   *notebook,
                                                  NautilusWindowSlot *slot);
 
-gboolean        nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook,
-                                                   gint              x,
-                                                   gint              y,
-                                                   gint             *position);
-
+gboolean        nautilus_notebook_get_tab_clicked (GtkNotebook *notebook,
+                                                   gint         x,
+                                                   gint         y,
+                                                   gint        *position);
+void            nautilus_notebook_setup           (GtkNotebook *notebook);
 G_END_DECLS
diff --git a/src/nautilus-window-slot-dnd.c b/src/nautilus-window-slot-dnd.c
index 8f5bd3383..e0b79308d 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -64,7 +64,7 @@ switch_tab (NautilusDragSlotProxyInfo *drag_info)
         return;
     }
 
-    notebook = gtk_widget_get_ancestor (GTK_WIDGET (drag_info->target_slot), NAUTILUS_TYPE_NOTEBOOK);
+    notebook = gtk_widget_get_ancestor (GTK_WIDGET (drag_info->target_slot), GTK_TYPE_NOTEBOOK);
     n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
 
     for (idx = 0; idx < n_pages; idx++)
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index d821fc899..a178bcbcb 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -351,7 +351,7 @@ action_tab_previous (GSimpleAction *action,
 {
     NautilusWindow *window = user_data;
 
-    nautilus_notebook_prev_page (NAUTILUS_NOTEBOOK (window->notebook));
+    nautilus_notebook_prev_page (GTK_NOTEBOOK (window->notebook));
 }
 
 static void
@@ -361,7 +361,7 @@ action_tab_next (GSimpleAction *action,
 {
     NautilusWindow *window = user_data;
 
-    nautilus_notebook_next_page (NAUTILUS_NOTEBOOK (window->notebook));
+    nautilus_notebook_next_page (GTK_NOTEBOOK (window->notebook));
 }
 
 static void
@@ -371,7 +371,7 @@ action_tab_move_left (GSimpleAction *action,
 {
     NautilusWindow *window = user_data;
 
-    nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->notebook), -1);
+    nautilus_notebook_reorder_current_child_relative (GTK_NOTEBOOK (window->notebook), -1);
 }
 
 static void
@@ -381,7 +381,7 @@ action_tab_move_right (GSimpleAction *action,
 {
     NautilusWindow *window = user_data;
 
-    nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->notebook), 1);
+    nautilus_notebook_reorder_current_child_relative (GTK_NOTEBOOK (window->notebook), 1);
 }
 
 static void
@@ -555,7 +555,7 @@ nautilus_window_initialize_slot (NautilusWindow     *window,
     g_signal_handlers_block_by_func (window->notebook,
                                      G_CALLBACK (notebook_switch_page_cb),
                                      window);
-    nautilus_notebook_add_tab (NAUTILUS_NOTEBOOK (window->notebook),
+    nautilus_notebook_add_tab (GTK_NOTEBOOK (window->notebook),
                                slot,
                                (flags & NAUTILUS_OPEN_FLAG_SLOT_APPEND) != 0 ?
                                -1 :
@@ -808,9 +808,9 @@ nautilus_window_sync_allow_stop (NautilusWindow     *window,
 
         /* Avoid updating the notebook if we are calling on dispose or
          * on removal of a notebook tab */
-        if (nautilus_notebook_contains_slot (NAUTILUS_NOTEBOOK (window->notebook), slot))
+        if (nautilus_notebook_contains_slot (GTK_NOTEBOOK (window->notebook), slot))
         {
-            nautilus_notebook_sync_loading (NAUTILUS_NOTEBOOK (window->notebook), slot);
+            nautilus_notebook_sync_loading (GTK_NOTEBOOK (window->notebook), slot);
         }
     }
 }
@@ -1794,7 +1794,7 @@ notebook_button_press_cb (GtkGestureMultiPress *gesture,
     notebook = GTK_NOTEBOOK (window->notebook);
 
     if (n_press != 1 ||
-        !nautilus_notebook_get_tab_clicked (NAUTILUS_NOTEBOOK (window->notebook), x, y, &tab_clicked))
+        !nautilus_notebook_get_tab_clicked (notebook, x, y, &tab_clicked))
     {
         return;
     }
@@ -2396,7 +2396,7 @@ nautilus_window_sync_title (NautilusWindow     *window,
         gtk_window_set_title (GTK_WINDOW (window), nautilus_window_slot_get_title (slot));
     }
 
-    nautilus_notebook_sync_tab_label (NAUTILUS_NOTEBOOK (window->notebook), slot);
+    nautilus_notebook_sync_tab_label (GTK_NOTEBOOK (window->notebook), slot);
 }
 
 #ifdef GDK_WINDOWING_WAYLAND
@@ -2628,8 +2628,8 @@ nautilus_window_init (NautilusWindow *window)
     GtkWindowGroup *window_group;
 
     g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
-    g_type_ensure (NAUTILUS_TYPE_NOTEBOOK);
     gtk_widget_init_template (GTK_WIDGET (window));
+    nautilus_notebook_setup (GTK_NOTEBOOK (window->notebook));
 
     gtk_popover_bind_model (GTK_POPOVER (window->tab_menu),
                             window->tab_menu_model,
diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index d16e6dcf3..c9f2b4eff 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -58,7 +58,7 @@
               <object class="GtkOverlay" id="main_view">
                 <property name="visible">True</property>
                 <child>
-                  <object class="NautilusNotebook" id="notebook">
+                  <object class="GtkNotebook" id="notebook">
                     <property name="visible">True</property>
                     <property name="show-tabs">False</property>
                     <property name="show-border">False</property>


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