diff options
author | António Fernandes <antoniof@gnome.org> | 2022-07-13 12:40:48 +0100 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-07-30 20:23:15 +0000 |
commit | d1b58407f6dd4119ba07ff145d0be5724451b83d (patch) | |
tree | f9d70a005e26de17ec68de39f6f7aaf2eda76209 /src/nautilus-window.c | |
parent | 108671415514c6baaca65889f5ab6106a264a16e (diff) | |
download | nautilus-d1b58407f6dd4119ba07ff145d0be5724451b83d.tar.gz |
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.
Diffstat (limited to 'src/nautilus-window.c')
-rw-r--r-- | src/nautilus-window.c | 50 |
1 files 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 @@ -1600,16 +1590,6 @@ nautilus_window_constructed (GObject *self) } 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; @@ -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 */ |