[nautilus/wip/exalm/libhandy: 802/802] window: Port to AdwTabView and AdwTabBar




commit a995f4f1b3d286ab8f639f9f141bf34a2f62c8ab
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Sep 9 02:46:32 2020 +0500

    window: Port to AdwTabView and AdwTabBar

 src/meson.build                     |   2 -
 src/nautilus-notebook.c             | 441 ------------------------------------
 src/nautilus-notebook.h             |  59 -----
 src/nautilus-window-slot-dnd.c      |  38 +---
 src/nautilus-window-slot.c          |  44 +++-
 src/nautilus-window.c               | 389 +++++++++++++++----------------
 src/nautilus-window.h               |   2 +-
 src/resources/ui/nautilus-window.ui |  18 +-
 8 files changed, 241 insertions(+), 752 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 4c171bd6d..793d3de91 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -94,8 +94,6 @@ libnautilus_sources = [
   'nautilus-location-entry.h',
   'nautilus-mime-actions.c',
   'nautilus-mime-actions.h',
-  'nautilus-notebook.c',
-  'nautilus-notebook.h',
   'nautilus-pathbar.c',
   'nautilus-pathbar.h',
   'nautilus-places-view.c',
diff --git a/src/nautilus-window-slot-dnd.c b/src/nautilus-window-slot-dnd.c
index ccec73b60..8c1399786 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -26,7 +26,6 @@
 #if 0 && NAUTILUS_DND_NEEDS_GTK4_REIMPLEMENTATION
 #include <config.h>
 
-#include "nautilus-notebook.h"
 #include "nautilus-application.h"
 #include "nautilus-files-view-dnd.h"
 #include "nautilus-window-slot-dnd.h"
@@ -50,35 +49,9 @@ typedef struct
     NautilusWindowSlot *target_slot;
     GtkWidget *widget;
 
-    gboolean is_notebook;
     guint switch_location_timer;
 } NautilusDragSlotProxyInfo;
 
-static void
-switch_tab (NautilusDragSlotProxyInfo *drag_info)
-{
-    GtkWidget *notebook, *slot;
-    gint idx, n_pages;
-
-    if (drag_info->target_slot == NULL)
-    {
-        return;
-    }
-
-    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++)
-    {
-        slot = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), idx);
-        if (NAUTILUS_WINDOW_SLOT (slot) == drag_info->target_slot)
-        {
-            gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), idx);
-            break;
-        }
-    }
-}
-
 static void
 switch_location (NautilusDragSlotProxyInfo *drag_info)
 {
@@ -107,14 +80,7 @@ slot_proxy_switch_location_timer (gpointer user_data)
 
     drag_info->switch_location_timer = 0;
 
-    if (drag_info->is_notebook)
-    {
-        switch_tab (drag_info);
-    }
-    else
-    {
-        switch_location (drag_info);
-    }
+    switch_location (drag_info);
 
     return FALSE;
 }
@@ -520,8 +486,6 @@ nautilus_drag_slot_proxy_init (GtkWidget          *widget,
     g_object_set_data_full (G_OBJECT (widget), "drag-slot-proxy-data", drag_info,
                             drag_info_free);
 
-    drag_info->is_notebook = (g_object_get_data (G_OBJECT (widget), "nautilus-notebook-tab") != NULL);
-
     if (target_file != NULL)
     {
         drag_info->target_file = nautilus_file_ref (target_file);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 7e94ffcab..ec42129bc 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -62,6 +62,8 @@ enum
     PROP_SELECTION,
     PROP_LOCATION,
     PROP_TOOLTIP,
+    PROP_ALLOW_STOP,
+    PROP_TITLE,
     NUM_PROPERTIES
 };
 
@@ -863,6 +865,18 @@ nautilus_window_slot_get_property (GObject    *object,
         }
         break;
 
+        case PROP_ALLOW_STOP:
+        {
+            g_value_set_boolean (value, nautilus_window_slot_get_allow_stop (self));
+        }
+        break;
+
+        case PROP_TITLE:
+        {
+            g_value_set_string (value, nautilus_window_slot_get_title (self));
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -926,6 +940,7 @@ nautilus_window_slot_constructed (GObject *object)
                             G_BINDING_DEFAULT);
 
     self->title = g_strdup (_("Loading…"));
+    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
 }
 
 static void
@@ -3055,6 +3070,20 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
                              NULL,
                              G_PARAM_READWRITE);
 
+    properties[PROP_ALLOW_STOP] =
+        g_param_spec_boolean ("allow-stop",
+                              "Allow stop",
+                              "Whether the slot allows stopping the loading",
+                              FALSE,
+                              G_PARAM_READABLE);
+
+    properties[PROP_TITLE] =
+        g_param_spec_string ("title",
+                             "Title",
+                             "The title of the slot",
+                             NULL,
+                             G_PARAM_READABLE);
+
     g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 }
 
@@ -3147,6 +3176,8 @@ nautilus_window_slot_update_title (NautilusWindowSlot *self)
     if (do_sync)
     {
         nautilus_window_sync_title (window, self);
+
+        g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
     }
 
     if (title != NULL)
@@ -3172,6 +3203,8 @@ nautilus_window_slot_set_allow_stop (NautilusWindowSlot *self,
 
     window = nautilus_window_slot_get_window (self);
     nautilus_window_sync_allow_stop (window, self);
+
+    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALLOW_STOP]);
 }
 
 void
@@ -3372,14 +3405,15 @@ nautilus_window_slot_set_active (NautilusWindowSlot *self,
 
         if (active)
         {
-            int page_num;
+            AdwTabView *tab_view;
+            AdwTabPage *page;
 
             window = self->window;
-            page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nautilus_window_get_notebook (window)),
-                                              GTK_WIDGET (self));
-            g_assert (page_num >= 0);
 
-            gtk_notebook_set_current_page (GTK_NOTEBOOK (nautilus_window_get_notebook (window)), page_num);
+            tab_view = nautilus_window_get_tab_view (window);
+            page = adw_tab_view_get_page (tab_view, GTK_WIDGET (self));
+
+            adw_tab_view_set_selected_page (tab_view, page);
 
             /* sync window to new slot */
             nautilus_window_sync_allow_stop (window, self);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 9214a56ab..02bdf0e51 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -61,7 +61,6 @@
 #include "nautilus-location-entry.h"
 #include "nautilus-metadata.h"
 #include "nautilus-mime-actions.h"
-#include "nautilus-notebook.h"
 #include "nautilus-pathbar.h"
 #include "nautilus-profile.h"
 #include "nautilus-properties-window.h"
@@ -84,6 +83,9 @@ static GtkWidget *nautilus_window_ensure_location_entry (NautilusWindow *window)
 static void nautilus_window_back_or_forward (NautilusWindow *window,
                                              gboolean        back,
                                              guint           distance);
+static void close_slot (NautilusWindow     *window,
+                        NautilusWindowSlot *slot,
+                        gboolean            remove_tab);
 
 /* Sanity check: highest mouse button value I could find was 14. 5 is our
  * lower threshold (well-documented to be the one of the button events for the
@@ -100,7 +102,8 @@ struct _NautilusWindow
 {
     AdwApplicationWindow parent_instance;
 
-    GtkWidget *notebook;
+    AdwTabView *tab_view;
+    AdwTabPage *menu_page;
 
     /* available slots, and active slot.
      * Both of them may never be NULL.
@@ -146,8 +149,6 @@ struct _NautilusWindow
     guint sidebar_width_handler_id;
     gulong bookmarks_id;
 
-    GtkWidget *tab_menu;
-
     GQueue *tab_data_queue;
 };
 
@@ -177,13 +178,15 @@ action_close_current_view (GSimpleAction *action,
                            GVariant      *state,
                            gpointer       user_data)
 {
-    NautilusWindow *window;
-    NautilusWindowSlot *slot;
+    NautilusWindow *window = user_data;
+    AdwTabPage *page = window->menu_page;
 
-    window = NAUTILUS_WINDOW (user_data);
-    slot = nautilus_window_get_active_slot (window);
+    if (page == NULL)
+    {
+        page = adw_tab_view_get_selected_page (window->tab_view);
+    }
 
-    nautilus_window_slot_close (window, slot);
+    adw_tab_view_close_page (window->tab_view, page);
 }
 
 static void
@@ -335,34 +338,20 @@ action_enter_location (GSimpleAction *action,
     nautilus_window_ensure_location_entry (window);
 }
 
-static void
-action_tab_previous (GSimpleAction *action,
-                     GVariant      *state,
-                     gpointer       user_data)
-{
-    NautilusWindow *window = user_data;
-
-    nautilus_notebook_prev_page (GTK_NOTEBOOK (window->notebook));
-}
-
-static void
-action_tab_next (GSimpleAction *action,
-                 GVariant      *state,
-                 gpointer       user_data)
-{
-    NautilusWindow *window = user_data;
-
-    nautilus_notebook_next_page (GTK_NOTEBOOK (window->notebook));
-}
-
 static void
 action_tab_move_left (GSimpleAction *action,
                       GVariant      *state,
                       gpointer       user_data)
 {
     NautilusWindow *window = user_data;
+    AdwTabPage *page = window->menu_page;
 
-    nautilus_notebook_reorder_current_child_relative (GTK_NOTEBOOK (window->notebook), -1);
+    if (page == NULL)
+    {
+        page = adw_tab_view_get_selected_page (window->tab_view);
+    }
+
+    adw_tab_view_reorder_backward (window->tab_view, page);
 }
 
 static void
@@ -371,8 +360,14 @@ action_tab_move_right (GSimpleAction *action,
                        gpointer       user_data)
 {
     NautilusWindow *window = user_data;
+    AdwTabPage *page = window->menu_page;
+
+    if (page == NULL)
+    {
+        page = adw_tab_view_get_selected_page (window->tab_view);
+    }
 
-    nautilus_notebook_reorder_current_child_relative (GTK_NOTEBOOK (window->notebook), 1);
+    adw_tab_view_reorder_forward (window->tab_view, page);
 }
 
 static void
@@ -381,15 +376,14 @@ action_go_to_tab (GSimpleAction *action,
                   gpointer       user_data)
 {
     NautilusWindow *window = NAUTILUS_WINDOW (user_data);
-    GtkNotebook *notebook;
     gint16 num;
 
-    notebook = GTK_NOTEBOOK (window->notebook);
-
     num = g_variant_get_int32 (value);
-    if (num < gtk_notebook_get_n_pages (notebook))
+    if (num < adw_tab_view_get_n_pages (window->tab_view))
     {
-        gtk_notebook_set_current_page (notebook, num);
+        AdwTabPage *page = adw_tab_view_get_nth_page (window->tab_view, num);
+
+        adw_tab_view_set_selected_page (window->tab_view, page);
     }
 }
 
@@ -487,15 +481,45 @@ on_slot_location_changed (NautilusWindowSlot *slot,
 }
 
 static void
-notebook_switch_page_cb (GtkNotebook    *notebook,
-                         GtkWidget      *page,
-                         unsigned int    page_num,
-                         NautilusWindow *window)
+tab_view_setup_menu_cb (AdwTabView     *tab_view,
+                        AdwTabPage     *page,
+                        NautilusWindow *window)
+{
+    GAction *move_tab_left_action;
+    GAction *move_tab_right_action;
+    int position, n_pages;
+
+    if (page)
+    {
+        position = adw_tab_view_get_page_position (tab_view, page);
+        n_pages = adw_tab_view_get_n_pages (tab_view);
+    }
+
+    move_tab_left_action = g_action_map_lookup_action (G_ACTION_MAP (window),
+                                                       "tab-move-left");
+    move_tab_right_action = g_action_map_lookup_action (G_ACTION_MAP (window),
+                                                        "tab-move-right");
+
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (move_tab_left_action),
+                                 page == NULL || position > 0);
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (move_tab_right_action),
+                                 page == NULL || position < n_pages - 1);
+
+    window->menu_page = page;
+}
+
+static void
+tab_view_notify_selected_page_cb (AdwTabView     *tab_view,
+                                  GParamSpec     *pspec,
+                                  NautilusWindow *window)
 {
+    AdwTabPage *page;
     NautilusWindowSlot *slot;
     GtkWidget *widget;
 
-    widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), page_num);
+    page = adw_tab_view_get_selected_page (tab_view);
+    widget = adw_tab_page_get_child (page);
+
     g_assert (widget != NULL);
 
     /* find slot corresponding to the target page */
@@ -533,28 +557,80 @@ nautilus_window_create_and_init_slot (NautilusWindow    *window,
     return slot;
 }
 
+static gboolean
+location_to_tooltip (GBinding           *binding,
+                     const GValue       *input,
+                     GValue             *output,
+                     NautilusWindowSlot *slot)
+{
+    GFile *location = g_value_get_object (input);
+    g_autofree gchar *location_name = NULL;
+
+    if (!location)
+    {
+        return TRUE;
+    }
+
+    /* Set the tooltip on the label's parent (the tab label hbox),
+     * so it covers all of the tab label.
+     */
+    location_name = g_file_get_parse_name (location);
+
+    if (eel_uri_is_search (location_name))
+    {
+        g_value_set_string (output, nautilus_window_slot_get_title (slot));
+    }
+    else
+    {
+        g_value_set_string (output, location_name);
+    }
+
+    return TRUE;
+}
+
 void
 nautilus_window_initialize_slot (NautilusWindow     *window,
                                  NautilusWindowSlot *slot,
                                  NautilusOpenFlags   flags)
 {
+    AdwTabPage *page;
+
     g_assert (NAUTILUS_IS_WINDOW (window));
     g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
 
     connect_slot (window, slot);
 
-    g_signal_handlers_block_by_func (window->notebook,
-                                     G_CALLBACK (notebook_switch_page_cb),
-                                     window);
-    nautilus_notebook_add_tab (GTK_NOTEBOOK (window->notebook),
-                               slot,
-                               (flags & NAUTILUS_OPEN_FLAG_SLOT_APPEND) != 0 ?
-                               -1 :
-                               gtk_notebook_get_current_page (GTK_NOTEBOOK (window->notebook)) + 1,
-                               FALSE);
-    g_signal_handlers_unblock_by_func (window->notebook,
-                                       G_CALLBACK (notebook_switch_page_cb),
-                                       window);
+    if ((flags & NAUTILUS_OPEN_FLAG_SLOT_APPEND) != 0)
+    {
+        page = adw_tab_view_append (window->tab_view, GTK_WIDGET (slot));
+    }
+    else
+    {
+        AdwTabPage *current = adw_tab_view_get_selected_page (window->tab_view);
+
+        if (current)
+        {
+            int position = adw_tab_view_get_page_position (window->tab_view, current) + 1;
+
+            page = adw_tab_view_insert (window->tab_view, GTK_WIDGET (slot), position);
+        }
+        else
+        {
+            page = adw_tab_view_prepend (window->tab_view, GTK_WIDGET (slot));
+        }
+    }
+
+    g_object_bind_property (slot, "allow-stop",
+                            page, "loading",
+                            G_BINDING_SYNC_CREATE);
+    g_object_bind_property (slot, "title",
+                            page, "title",
+                            G_BINDING_SYNC_CREATE);
+    g_object_bind_property_full (slot, "location",
+                                 page, "tooltip",
+                                 G_BINDING_SYNC_CREATE,
+                                 (GBindingTransformFunc) location_to_tooltip,
+                                 NULL, window, NULL);
 
     window->slots = g_list_append (window->slots, slot);
     g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
@@ -680,14 +756,10 @@ location_entry_location_changed_callback (GtkWidget      *widget,
 static void
 close_slot (NautilusWindow     *window,
             NautilusWindowSlot *slot,
-            gboolean            remove_from_notebook)
+            gboolean            remove_tab)
 {
-    int page_num;
-    GtkNotebook *notebook;
-
     g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
 
-
     DEBUG ("Closing slot %p", slot);
 
     disconnect_slot (window, slot);
@@ -696,15 +768,12 @@ close_slot (NautilusWindow     *window,
 
     g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
 
-    notebook = GTK_NOTEBOOK (window->notebook);
-
-    if (remove_from_notebook)
+    if (remove_tab)
     {
-        page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
-        g_assert (page_num >= 0);
+        AdwTabPage *page = adw_tab_view_get_page (window->tab_view,
+                                                  GTK_WIDGET (slot));
 
-        /* this will call gtk_widget_destroy on the slot */
-        gtk_notebook_remove_page (notebook, page_num);
+        adw_tab_view_close_page (window->tab_view, page);
     }
 }
 
@@ -791,22 +860,15 @@ nautilus_window_sync_allow_stop (NautilusWindow     *window,
         {
             update_cursor (window);
         }
-
-        /* Avoid updating the notebook if we are calling on dispose or
-         * on removal of a notebook tab */
-        if (nautilus_notebook_contains_slot (GTK_NOTEBOOK (window->notebook), slot))
-        {
-            nautilus_notebook_sync_loading (GTK_NOTEBOOK (window->notebook), slot);
-        }
     }
 }
 
-GtkWidget *
-nautilus_window_get_notebook (NautilusWindow *window)
+AdwTabView *
+nautilus_window_get_tab_view (NautilusWindow *window)
 {
     g_return_val_if_fail (NAUTILUS_IS_WINDOW (window), NULL);
 
-    return window->notebook;
+    return window->tab_view;
 }
 
 static gboolean
@@ -1754,70 +1816,6 @@ on_path_bar_open_location (NautilusWindow    *window,
     nautilus_window_open_location_full (window, location, open_flags, NULL, NULL);
 }
 
-static void
-notebook_popup_menu_show (NautilusWindow *window,
-                          GtkWidget      *tab)
-{
-    GtkPopover *popover = GTK_POPOVER (window->tab_menu);
-    GtkAllocation allocation;
-    gdouble x, y;
-
-    gtk_widget_get_allocation (tab, &allocation);
-    gtk_widget_translate_coordinates (tab, GTK_WIDGET (window),
-                                      allocation.x, allocation.y, &x, &y);
-    allocation.x = x;
-    allocation.y = y;
-    gtk_popover_set_pointing_to (popover, (GdkRectangle *) &allocation);
-    gtk_popover_popup (popover);
-}
-
-static void
-notebook_button_press_cb (GtkGestureClick *gesture,
-                          gint             n_press,
-                          gdouble          x,
-                          gdouble          y,
-                          gpointer         user_data)
-{
-    NautilusWindow *window;
-    GtkNotebook *notebook;
-    gint tab_clicked;
-    GtkWidget *tab_widget;
-    guint button;
-    GdkModifierType state;
-
-    if (n_press != 1)
-    {
-        return;
-    }
-
-    window = NAUTILUS_WINDOW (user_data);
-    notebook = GTK_NOTEBOOK (window->notebook);
-
-    tab_widget = nautilus_notebook_get_tab_clicked (notebook, x, y, &tab_clicked);
-    if (tab_widget == NULL)
-    {
-        return;
-    }
-
-    button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
-    state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture));
-
-    if (button == GDK_BUTTON_SECONDARY &&
-        (state & gtk_accelerator_get_default_mod_mask ()) == 0)
-    {
-        /* switch to the page before opening the menu */
-        gtk_notebook_set_current_page (notebook, tab_clicked);
-        notebook_popup_menu_show (window, tab_widget);
-    }
-    else if (button == GDK_BUTTON_MIDDLE)
-    {
-        GtkWidget *slot;
-
-        slot = gtk_notebook_get_nth_page (notebook, tab_clicked);
-        nautilus_window_slot_close (window, NAUTILUS_WINDOW_SLOT (slot));
-    }
-}
-
 GtkWidget *
 nautilus_window_get_toolbar (NautilusWindow *window)
 {
@@ -1850,16 +1848,31 @@ setup_toolbar (NautilusWindow *window)
                              G_CALLBACK (location_entry_cancel_callback), window, 0);
 }
 
+static gboolean
+tab_view_close_page_cb (AdwTabView     *view,
+                        AdwTabPage     *page,
+                        NautilusWindow *window)
+{
+    NautilusWindowSlot *slot;
+
+    slot = NAUTILUS_WINDOW_SLOT (adw_tab_page_get_child (page));
+
+    nautilus_window_slot_close (window, slot);
+
+    return GDK_EVENT_PROPAGATE;
+}
+
 static void
-notebook_page_removed_cb (GtkNotebook *notebook,
-                          GtkWidget   *page,
-                          guint        page_num,
-                          gpointer     user_data)
+tab_view_page_detached_cb (AdwTabView     *tab_view,
+                           AdwTabPage     *page,
+                           gint            position,
+                           NautilusWindow *window)
 {
-    NautilusWindow *window = user_data;
-    NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page);
+    NautilusWindowSlot *slot;
     gboolean dnd_slot;
 
+    slot = NAUTILUS_WINDOW_SLOT (adw_tab_page_get_child (page));
+
     dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
     if (!dnd_slot)
     {
@@ -1870,16 +1883,16 @@ notebook_page_removed_cb (GtkNotebook *notebook,
 }
 
 static void
-notebook_page_added_cb (GtkNotebook *notebook,
-                        GtkWidget   *page,
-                        guint        page_num,
-                        gpointer     user_data)
+tab_view_page_attached_cb (AdwTabView     *tab_view,
+                           AdwTabPage     *page,
+                           gint            position,
+                           NautilusWindow *window)
 {
-    NautilusWindow *window = user_data;
-    NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page);
-    NautilusWindowSlot *dummy_slot;
+    NautilusWindowSlot *slot, *dummy_slot;
     gboolean dnd_slot;
 
+    slot = NAUTILUS_WINDOW_SLOT (adw_tab_page_get_child (page));
+
     dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
     if (!dnd_slot)
     {
@@ -1904,58 +1917,44 @@ notebook_page_added_cb (GtkNotebook *notebook,
     gtk_widget_show (GTK_WIDGET (window));
 }
 
-static GtkNotebook *
-notebook_create_window_cb (GtkNotebook *notebook,
-                           GtkWidget   *page,
-                           gint         x,
-                           gint         y,
-                           gpointer     user_data)
+static AdwTabView *
+tab_view_create_window_cb (AdwTabView     *tab_view,
+                           NautilusWindow *window)
 {
     NautilusApplication *app;
     NautilusWindow *new_window;
-    NautilusWindowSlot *slot;
-
-    if (!NAUTILUS_IS_WINDOW_SLOT (page))
-    {
-        return NULL;
-    }
 
     app = NAUTILUS_APPLICATION (g_application_get_default ());
     new_window = nautilus_application_create_window (app);
     gtk_window_set_display (GTK_WINDOW (new_window),
-                            gtk_widget_get_display (GTK_WIDGET (notebook)));
+                            gtk_widget_get_display (GTK_WIDGET (tab_view)));
 
-    slot = NAUTILUS_WINDOW_SLOT (page);
-    g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
-                       GINT_TO_POINTER (TRUE));
+    gtk_window_present (GTK_WINDOW (new_window));
 
-    return GTK_NOTEBOOK (new_window->notebook);
+    return new_window->tab_view;
 }
 
 static void
-setup_notebook (NautilusWindow *window)
+setup_tab_view (NautilusWindow *window)
 {
-    GtkEventController *controller;
-
-    g_signal_connect (window->notebook, "switch-page",
-                      G_CALLBACK (notebook_switch_page_cb),
+    g_signal_connect (window->tab_view, "close-page",
+                      G_CALLBACK (tab_view_close_page_cb),
                       window);
-    g_signal_connect (window->notebook, "create-window",
-                      G_CALLBACK (notebook_create_window_cb),
+    g_signal_connect (window->tab_view, "setup-menu",
+                      G_CALLBACK (tab_view_setup_menu_cb),
                       window);
-    g_signal_connect (window->notebook, "page-added",
-                      G_CALLBACK (notebook_page_added_cb),
+    g_signal_connect (window->tab_view, "notify::selected-page",
+                      G_CALLBACK (tab_view_notify_selected_page_cb),
                       window);
-    g_signal_connect (window->notebook, "page-removed",
-                      G_CALLBACK (notebook_page_removed_cb),
+    g_signal_connect (window->tab_view, "create-window",
+                      G_CALLBACK (tab_view_create_window_cb),
+                      window);
+    g_signal_connect (window->tab_view, "page-attached",
+                      G_CALLBACK (tab_view_page_attached_cb),
+                      window);
+    g_signal_connect (window->tab_view, "page-detached",
+                      G_CALLBACK (tab_view_page_detached_cb),
                       window);
-
-    controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
-    gtk_widget_add_controller (GTK_WIDGET (window->notebook), controller);
-    gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
-    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (controller), 0);
-    g_signal_connect (controller, "pressed",
-                      G_CALLBACK (notebook_button_press_cb), window);
 }
 
 const GActionEntry win_entries[] =
@@ -1978,8 +1977,6 @@ const GActionEntry win_entries[] =
     { "close-current-view", action_close_current_view },
     { "go-home", action_go_home },
     { "go-starred", action_go_starred },
-    { "tab-previous", action_tab_previous },
-    { "tab-next", action_tab_next },
     { "tab-move-left", action_tab_move_left },
     { "tab-move-right", action_tab_move_right },
     { "prompt-root-location", action_prompt_for_location_root },
@@ -2025,8 +2022,6 @@ nautilus_window_initialize_actions (NautilusWindow *window)
     nautilus_application_set_accelerator (app, "win.up", "<alt>Up");
     nautilus_application_set_accelerators (app, "win.go-home", ACCELS ("<alt>Home", "HomePage", "Start"));
     nautilus_application_set_accelerator (app, "win.go-starred", "Favorites");
-    nautilus_application_set_accelerator (app, "win.tab-previous", "<control>Page_Up");
-    nautilus_application_set_accelerator (app, "win.tab-next", "<control>Page_Down");
     nautilus_application_set_accelerator (app, "win.tab-move-left", "<shift><control>Page_Up");
     nautilus_application_set_accelerator (app, "win.tab-move-right", "<shift><control>Page_Down");
     nautilus_application_set_accelerators (app, "win.prompt-root-location", ACCELS ("slash", "KP_Divide"));
@@ -2078,7 +2073,7 @@ nautilus_window_constructed (GObject *self)
                                  NAUTILUS_WINDOW_DEFAULT_WIDTH,
                                  NAUTILUS_WINDOW_DEFAULT_HEIGHT);
 
-    setup_notebook (window);
+    setup_tab_view (window);
     nautilus_window_set_up_sidebar (window);
 
 
@@ -2140,8 +2135,6 @@ nautilus_window_dispose (GObject *object)
 
     DEBUG ("Destroying window");
 
-    g_clear_pointer (&window->tab_menu, gtk_widget_unparent);
-
     /* close all slots safely */
     slots_copy = g_list_copy (window->slots);
     if (window->active_slot != NULL)
@@ -2346,8 +2339,6 @@ nautilus_window_sync_title (NautilusWindow     *window,
     {
         gtk_window_set_title (GTK_WINDOW (window), nautilus_window_slot_get_title (slot));
     }
-
-    nautilus_notebook_sync_tab_label (GTK_NOTEBOOK (window->notebook), slot);
 }
 
 #ifdef GDK_WINDOWING_WAYLAND
@@ -2581,7 +2572,6 @@ nautilus_window_init (NautilusWindow *window)
 
     g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
     gtk_widget_init_template (GTK_WIDGET (window));
-    nautilus_notebook_setup (GTK_NOTEBOOK (window->notebook));
 
     window->places_sidebar = nautilus_gtk_places_sidebar_new ();
     g_object_set (window->places_sidebar,
@@ -2603,8 +2593,6 @@ nautilus_window_init (NautilusWindow *window)
                              window,
                              G_CONNECT_SWAPPED);
 
-    gtk_widget_set_parent (window->tab_menu, GTK_WIDGET (window));
-
     g_signal_connect (window, "notify::is-maximized",
                       G_CALLBACK (on_is_maximized_changed), NULL);
 
@@ -2674,8 +2662,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, content_paned);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, sidebar);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, main_view);
-    gtk_widget_class_bind_template_child (wclass, NautilusWindow, notebook);
-    gtk_widget_class_bind_template_child (wclass, NautilusWindow, tab_menu);
+    gtk_widget_class_bind_template_child (wclass, NautilusWindow, tab_view);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, in_app_notification_undo);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, in_app_notification_undo_label);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, in_app_notification_undo_undo_button);
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 72fc5d987..e7928e373 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -80,7 +80,7 @@ void     nautilus_window_hide_sidebar         (NautilusWindow *window);
 void     nautilus_window_show_sidebar         (NautilusWindow *window);
 void nautilus_window_reset_menus (NautilusWindow *window);
 
-GtkWidget *         nautilus_window_get_notebook (NautilusWindow *window);
+AdwTabView * nautilus_window_get_tab_view (NautilusWindow *window);
 
 void     nautilus_window_show_about_dialog    (NautilusWindow *window);
 
diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index e5b7d2834..b410f054e 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -25,9 +25,6 @@
       </item>
     </section>
   </menu>
-  <object class="GtkPopoverMenu" id="tab_menu">
-    <property name="menu-model">tab_menu_model</property>
-  </object>
   <template class="NautilusWindow" parent="AdwApplicationWindow">
     <property name="show-menubar">False</property>
     <property name="title" translatable="yes">_Files</property>
@@ -54,9 +51,18 @@
             <child>
               <object class="GtkOverlay" id="main_view">
                 <property name="child">
-                  <object class="GtkNotebook" id="notebook">
-                    <property name="show-tabs">False</property>
-                    <property name="show-border">False</property>
+                  <object class="GtkBox">
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="AdwTabBar">
+                        <property name="view">tab_view</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="AdwTabView" id="tab_view">
+                        <property name="menu-model">tab_menu_model</property>
+                      </object>
+                    </child>
                   </object>
                 </property>
                 <child type="overlay">


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