[nautilus/wip/exalm/libhandy: 4/7] window: Refine slot removal code




commit 4e9c3a7b218d1af859c20333ed9fd39f4b710be6
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 | 51 +++++++++++++++------------------------------------
 1 file changed, 15 insertions(+), 36 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 6189d1fa8..3ca73e5ca 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -656,34 +656,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
@@ -1077,6 +1060,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)
@@ -1090,7 +1075,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)
@@ -1465,7 +1455,7 @@ notebook_page_removed_cb (GtkNotebook *notebook,
         return;
     }
 
-    close_slot (window, slot, FALSE);
+    remove_slot_from_window (slot, window);
 }
 
 static void
@@ -1674,17 +1664,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)
 {
     NautilusWindow *window;
@@ -1700,7 +1679,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]