toolbar: Handle NautilusPathBar::open-location

There is no need for NautilusWindow to handle it. This way the
upcoming FileChooser window will not have to duplicate the code.

Part of: https://gitlab.gnome.org/GNOME/nautilus/-/work_items/3431
This commit is contained in:
António Fernandes 2024-05-12 21:42:06 +01:00
parent 7360be440a
commit 874150b017
2 changed files with 25 additions and 30 deletions

View file

@ -158,6 +158,25 @@ nautilus_toolbar_close_location_entry (NautilusToolbar *self)
}
}
static void
on_path_bar_open_location (NautilusPathBar *path_bar,
GFile *location,
NautilusOpenFlags open_flags,
gpointer user_data)
{
NautilusToolbar *self = NAUTILUS_TOOLBAR (user_data);
if (open_flags & (NAUTILUS_OPEN_FLAG_NEW_WINDOW | NAUTILUS_OPEN_FLAG_NEW_TAB))
{
nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
location, open_flags, NULL, NULL, NULL);
}
else
{
nautilus_window_slot_open_location_full (self->window_slot, location, open_flags, NULL);
}
}
static void
on_location_entry_focus_leave (GtkEventControllerFocus *controller,
gpointer user_data)
@ -207,6 +226,12 @@ nautilus_toolbar_init (NautilusToolbar *self)
gtk_widget_init_template (GTK_WIDGET (self));
/* Setup path bar */
g_signal_connect_object (self->path_bar, "open-location",
G_CALLBACK (on_path_bar_open_location), self,
G_CONNECT_DEFAULT);
/* Setup location entry */
GtkEventController *controller = gtk_event_controller_focus_new ();
gtk_widget_add_controller (self->location_entry, controller);

View file

@ -1230,34 +1230,6 @@ nautilus_window_show_operation_notification (NautilusWindow *window,
adw_toast_overlay_add_toast (window->toast_overlay, toast);
}
static void
on_path_bar_open_location (NautilusWindow *window,
GFile *location,
NautilusOpenFlags open_flags)
{
if (open_flags & NAUTILUS_OPEN_FLAG_NEW_WINDOW)
{
nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
location, NAUTILUS_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
}
else
{
nautilus_window_open_location_full (window, location, open_flags, NULL, NULL);
}
}
static void
setup_toolbar (NautilusWindow *window)
{
GtkWidget *path_bar;
/* connect to the pathbar signals */
path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->toolbar));
g_signal_connect_swapped (path_bar, "open-location",
G_CALLBACK (on_path_bar_open_location), window);
}
static gboolean
tab_view_close_page_cb (AdwTabView *view,
AdwTabPage *page,
@ -1526,8 +1498,6 @@ nautilus_window_constructed (GObject *self)
application = NAUTILUS_APPLICATION (g_application_get_default ());
gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
setup_toolbar (window);
gtk_window_set_default_size (GTK_WINDOW (window),
NAUTILUS_WINDOW_DEFAULT_WIDTH,
NAUTILUS_WINDOW_DEFAULT_HEIGHT);