diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2012-10-23 15:10:15 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2012-10-23 16:10:04 -0400 |
commit | 24e0a2a47fb15573478e1a17710385323dbb7026 (patch) | |
tree | 5813701efadfd9004c965f0c929e96b0db4eec31 | |
parent | cbbf9c88548f2295921bfe9fbf30ea0ca59d1b6f (diff) | |
download | nautilus-24e0a2a47fb15573478e1a17710385323dbb7026.tar.gz |
slot: unify handling of back/forward navigation
These two functions are identical, only the variables are inverted.
Unify them into a single function.
-rw-r--r-- | src/nautilus-window-slot.c | 88 |
1 files changed, 27 insertions, 61 deletions
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index 6534acde8..7486ae93f 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -1804,82 +1804,48 @@ check_last_bookmark_location_matches_slot (NautilusWindowSlot *slot) } static void -handle_go_back (NautilusWindowSlot *slot, - GFile *location) +handle_go_direction (NautilusWindowSlot *slot, + GFile *location, + gboolean forward) { - guint i; - GList *link; + GList **list_ptr, **other_list_ptr; + GList *list, *other_list, *link; NautilusBookmark *bookmark; + gint i; - /* Going back. Move items from the back list to the forward list. */ - g_assert (g_list_length (slot->details->back_list) > slot->details->location_change_distance); - check_bookmark_location_matches (NAUTILUS_BOOKMARK (g_list_nth_data (slot->details->back_list, - slot->details->location_change_distance)), - location); - g_assert (nautilus_window_slot_get_location (slot) != NULL); - - /* Move current location to Forward list */ - - check_last_bookmark_location_matches_slot (slot); - - /* Use the first bookmark in the history list rather than creating a new one. */ - slot->details->forward_list = g_list_prepend (slot->details->forward_list, - slot->details->last_location_bookmark); - g_object_ref (slot->details->forward_list->data); - - /* Move extra links from Back to Forward list */ - for (i = 0; i < slot->details->location_change_distance; ++i) { - bookmark = NAUTILUS_BOOKMARK (slot->details->back_list->data); - slot->details->back_list = - g_list_remove (slot->details->back_list, bookmark); - slot->details->forward_list = - g_list_prepend (slot->details->forward_list, bookmark); - } + list_ptr = (forward) ? (&slot->details->forward_list) : (&slot->details->back_list); + other_list_ptr = (forward) ? (&slot->details->back_list) : (&slot->details->forward_list); + list = *list_ptr; + other_list = *other_list_ptr; - /* One bookmark falls out of back/forward lists and becomes viewed location */ - link = slot->details->back_list; - slot->details->back_list = g_list_remove_link (slot->details->back_list, link); - g_object_unref (link->data); - g_list_free_1 (link); -} - -static void -handle_go_forward (NautilusWindowSlot *slot, - GFile *location) -{ - guint i; - GList *link; - NautilusBookmark *bookmark; - - /* Going forward. Move items from the forward list to the back list. */ - g_assert (g_list_length (slot->details->forward_list) > slot->details->location_change_distance); - check_bookmark_location_matches (NAUTILUS_BOOKMARK (g_list_nth_data (slot->details->forward_list, - slot->details->location_change_distance)), + /* Move items from the list to the other list. */ + g_assert (g_list_length (list) > slot->details->location_change_distance); + check_bookmark_location_matches (g_list_nth_data (list, slot->details->location_change_distance), location); g_assert (nautilus_window_slot_get_location (slot) != NULL); - /* Move current location to Back list */ + /* Move current location to list */ check_last_bookmark_location_matches_slot (slot); /* Use the first bookmark in the history list rather than creating a new one. */ - slot->details->back_list = g_list_prepend (slot->details->back_list, - slot->details->last_location_bookmark); - g_object_ref (slot->details->back_list->data); + other_list = g_list_prepend (other_list, slot->details->last_location_bookmark); + g_object_ref (other_list->data); - /* Move extra links from Forward to Back list */ + /* Move extra links from the list to the other list */ for (i = 0; i < slot->details->location_change_distance; ++i) { - bookmark = NAUTILUS_BOOKMARK (slot->details->forward_list->data); - slot->details->forward_list = - g_list_remove (slot->details->back_list, bookmark); - slot->details->back_list = - g_list_prepend (slot->details->forward_list, bookmark); + bookmark = NAUTILUS_BOOKMARK (list->data); + list = g_list_remove (list, bookmark); + other_list = g_list_prepend (other_list, bookmark); } /* One bookmark falls out of back/forward lists and becomes viewed location */ - link = slot->details->forward_list; - slot->details->forward_list = g_list_remove_link (slot->details->forward_list, link); + link = list; + list = g_list_remove_link (list, link); g_object_unref (link->data); g_list_free_1 (link); + + *list_ptr = list; + *other_list_ptr = other_list; } static void @@ -1921,10 +1887,10 @@ update_history (NautilusWindowSlot *slot, /* for reload there is no work to do */ return; case NAUTILUS_LOCATION_CHANGE_BACK: - handle_go_back (slot, new_location); + handle_go_direction (slot, new_location, FALSE); return; case NAUTILUS_LOCATION_CHANGE_FORWARD: - handle_go_forward (slot, new_location); + handle_go_direction (slot, new_location, TRUE); return; } g_return_if_fail (FALSE); |