From 3bc07e00d9031c908031ef3fcfe325789c5e7594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 18 Nov 2021 21:58:15 +0100 Subject: [PATCH] Enable opening from sidebar in a new window --- fastiv.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/fastiv.c b/fastiv.c index dc15bf9..4a7af03 100644 --- a/fastiv.c +++ b/fastiv.c @@ -270,13 +270,26 @@ on_item_activated(G_GNUC_UNUSED FastivBrowser *browser, const char *path, open(path); } +static void +spawn_path(const char *path) +{ + char *argv[] = {PROJECT_NAME, (char *) path, NULL}; + GError *error = NULL; + g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, + NULL, &error); + g_clear_error(&error); +} + static void on_open_location(G_GNUC_UNUSED GtkPlacesSidebar *sidebar, GFile *location, G_GNUC_UNUSED GtkPlacesOpenFlags flags, G_GNUC_UNUSED gpointer user_data) { gchar *path = g_file_get_path(location); if (path) { - load_directory(path); + if (flags & GTK_PLACES_OPEN_NEW_WINDOW) + spawn_path(path); + else + load_directory(path); g_free(path); } } @@ -302,15 +315,10 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event, case GDK_KEY_o: on_open(); return TRUE; - case GDK_KEY_n: { - char *argv[] = {PROJECT_NAME, g.directory, NULL}; - GError *error = NULL; - g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, - NULL, &error); - g_clear_error(&error); + case GDK_KEY_n: + spawn_path(g.directory); return TRUE; } - } break; case 0: switch (event->keyval) { @@ -506,6 +514,8 @@ main(int argc, char *argv[]) GTK_PLACES_SIDEBAR(g.browser_sidebar), FALSE); gtk_places_sidebar_set_show_trash( GTK_PLACES_SIDEBAR(g.browser_sidebar), FALSE); + gtk_places_sidebar_set_open_flags(GTK_PLACES_SIDEBAR(g.browser_sidebar), + GTK_PLACES_OPEN_NORMAL | GTK_PLACES_OPEN_NEW_WINDOW); g_signal_connect(g.browser_sidebar, "open-location", G_CALLBACK(on_open_location), NULL);