[nautilus/wip/exalm/libhandy: 9/13] window: Refine slot removal code




commit a5f0623364c6729ce41a3e0b67281d7c4d817b49
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jul 13 12:40:48 2022 +0100

    window: Refine slot removal code
    
    `clost_slot()` does not necessarily closes the tab. This happens only
    if the 3rd parameter is TRUE. This is misleading.
    
    Now that there is only 1 case where the 3rd parameter is TRUE, let's
    extract the tab-closing part out and rename the function accordingly.
    
    Also, swap its parameters in order to make it `g_list_foreach()`-able.

 src/nautilus-window.c | 50 +++++++++++++++-----------------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 8694964ca..5ee191769 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -655,34 +655,17 @@ location_entry_location_changed_callback (GtkWidget      *widget,
 }
 
 static void
-close_slot (NautilusWindow     *window,
-            NautilusWindowSlot *slot,
-            gboolean            remove_from_notebook)
+remove_slot_from_window (NautilusWindowSlot *slot,
+                         NautilusWindow     *window)
 {
-    int page_num;
-    GtkNotebook *notebook;
-
-    g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
-
+    g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
+    g_return_if_fail (NAUTILUS_WINDOW (window));
 
-    DEBUG ("Closing slot %p", slot);
+    DEBUG ("Removing slot %p", slot);
 
     disconnect_slot (window, slot);
-
     window->slots = g_list_remove (window->slots, slot);
-
     g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
-
-    notebook = GTK_NOTEBOOK (window->notebook);
-
-    if (remove_from_notebook)
-    {
-        page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
-        g_assert (page_num >= 0);
-
-        /* this will call gtk_widget_destroy on the slot */
-        gtk_notebook_remove_page (notebook, page_num);
-    }
 }
 
 void
@@ -1006,6 +989,8 @@ nautilus_window_slot_close (NautilusWindow     *window,
                             NautilusWindowSlot *slot)
 {
     NautilusNavigationState *data;
+    GtkNotebook *notebook = GTK_NOTEBOOK (window->notebook);
+    int page_num;
 
     DEBUG ("Requesting to remove slot %p from window %p", slot, window);
     if (window == NULL || slot == NULL)
@@ -1019,7 +1004,12 @@ nautilus_window_slot_close (NautilusWindow     *window,
         g_queue_push_head (window->tab_data_queue, data);
     }
 
-    close_slot (window, slot, TRUE);
+    remove_slot_from_window (slot, window);
+
+    page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
+    g_assert (page_num >= 0);
+    /* this will destroy the slot */
+    gtk_notebook_remove_page (notebook, page_num);
 
     /* If that was the last slot in the window, close the window. */
     if (window->slots == NULL)
@@ -1394,7 +1384,7 @@ notebook_page_removed_cb (GtkNotebook *notebook,
         return;
     }
 
-    close_slot (window, slot, FALSE);
+    remove_slot_from_window (slot, window);
 }
 
 static void
@@ -1599,16 +1589,6 @@ nautilus_window_constructed (GObject *self)
     nautilus_profile_end (NULL);
 }
 
-static void
-remove_slots_foreach (gpointer data,
-                       gpointer user_data)
-{
-    NautilusWindowSlot *slot = data;
-    NautilusWindow *window = user_data;
-
-    close_slot (window, slot, FALSE);
-}
-
 static void
 nautilus_window_dispose (GObject *object)
 {
@@ -1625,7 +1605,7 @@ nautilus_window_dispose (GObject *object)
 
     /* close all slots safely */
     slots_copy = g_list_copy (window->slots);
-    g_list_foreach (slots_copy, (GFunc) remove_slots_foreach, window);
+    g_list_foreach (slots_copy, (GFunc) remove_slot_from_window, window);
     g_list_free (slots_copy);
 
     /* the slots list should now be empty */


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