summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Berla <corey@berla.me>2022-07-16 07:39:09 -0700
committerCorey Berla <corey@berla.me>2022-07-16 08:13:10 -0700
commit802a33b3e7f5cffd267065add44325d92341b2c7 (patch)
treeb3aefa32c616da614c5a0eb5b37b33be201e031e
parent55c6e19682762211814a9f80e40cef9c7561f91c (diff)
downloadnautilus-802a33b3e7f5cffd267065add44325d92341b2c7.tar.gz
window: Add helper to open new tab from a back / forward selection
Add function like nautilus_window_back_or_foward(), but instead of acting on the current slot, open a new tab. This will be used when middle clicking the navigation buttons in the toolbar.
-rw-r--r--src/nautilus-window.c48
-rw-r--r--src/nautilus-window.h3
2 files changed, 51 insertions, 0 deletions
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 34f2aec72..d409d31ef 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2034,6 +2034,54 @@ nautilus_window_back_or_forward (NautilusWindow *window,
}
}
+void
+nautilus_window_back_or_forward_in_new_tab (NautilusWindow *window,
+ NautilusNavigationDirection direction)
+{
+ GFile *location;
+ NautilusWindowSlot *window_slot;
+ NautilusWindowSlot *new_slot;
+ NautilusNavigationState *state;
+
+ window_slot = nautilus_window_get_active_slot (window);
+ new_slot = nautilus_window_slot_new (window);
+ state = nautilus_window_slot_get_navigation_state (window_slot);
+
+ /* Manually fix up the back / forward lists and location.
+ * This way we don't have to unnecessary load the current location
+ * and then load back / forward */
+ switch (direction)
+ {
+ case NAUTILUS_NAVIGATION_DIRECTION_BACK:
+ {
+ state->forward_list = g_list_prepend (state->forward_list, state->current_location_bookmark);
+ state->current_location_bookmark = state->back_list->data;
+ state->back_list = state->back_list->next;
+ }
+ break;
+
+ case NAUTILUS_NAVIGATION_DIRECTION_FORWARD:
+ {
+ state->back_list = g_list_prepend (state->back_list, state->current_location_bookmark);
+ state->current_location_bookmark = state->forward_list->data;
+ state->forward_list = state->forward_list->next;
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ }
+
+ location = nautilus_bookmark_get_location (state->current_location_bookmark);
+ nautilus_window_initialize_slot (window, new_slot, NAUTILUS_OPEN_FLAG_NEW_TAB);
+ nautilus_window_slot_open_location_full (new_slot, location, 0, NULL);
+ nautilus_window_slot_restore_navigation_state (new_slot, state);
+
+ free_navigation_state (state);
+}
+
static void
on_click_gesture_pressed (GtkGestureClick *gesture,
gint n_press,
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 03fb00edd..71bf490e3 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -115,4 +115,7 @@ gboolean nautilus_window_export_handle (NautilusWindow *window,
gpointer user_data);
void nautilus_window_unexport_handle (NautilusWindow *window);
+void nautilus_window_back_or_forward_in_new_tab (NautilusWindow *window,
+ NautilusNavigationDirection back);
+
G_END_DECLS