From a0276835e2ce782a41aa2b680eb29cad173cd0d4 Mon Sep 17 00:00:00 2001 From: Alexander Kurakin Date: Sun, 21 Oct 2018 00:53:18 +0200 Subject: [PATCH] Start archive application from file's directory (Bug #14773) --- thunar-archive-plugin/tap-provider.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/thunar-archive-plugin/tap-provider.c b/thunar-archive-plugin/tap-provider.c index bfc30f5..665c5b8 100644 --- a/thunar-archive-plugin/tap-provider.c +++ b/thunar-archive-plugin/tap-provider.c @@ -297,9 +297,10 @@ static void tap_extract_to (ThunarxMenuItem *item, GtkWidget *window) { - TapProvider *tap_provider; - const gchar *default_dir; - GList *files; + TapProvider *tap_provider; + GList *files; + gchar *dirname; + gchar *uri; /* determine the files associated with the item */ files = g_object_get_qdata (G_OBJECT (item), tap_item_files_quark); @@ -311,15 +312,27 @@ tap_extract_to (ThunarxMenuItem *item, if (G_UNLIKELY (tap_provider == NULL)) return; - /* if $GTK_DEFAULT_FILECHOOSER_DIR is set, we use that as default - * folder (i.e. Ubuntu), otherwise we just use $HOME. - */ - default_dir = g_getenv ("GTK_DEFAULT_FILECHOOSER_DIR"); - if (G_LIKELY (default_dir == NULL)) - default_dir = g_get_home_dir (); + /* determine the parent URI of the first selected file */ + uri = thunarx_file_info_get_parent_uri (files->data); - /* execute the action associated with the menu item */ - tap_provider_execute (tap_provider, tap_backend_extract_to, window, default_dir, files, _("Failed to extract files")); + /* verify that we have an URI */ + if (G_LIKELY (uri != NULL)) + { + /* determine the directory of the first selected file */ + dirname = g_filename_from_uri (uri, NULL, NULL); + + /* verify that we were able to determine a local path */ + if (G_LIKELY (dirname != NULL)) + { + /* execute the action */ + tap_provider_execute (tap_provider, tap_backend_extract_to, window, dirname, files, _("Failed to extract files")); + + /* release the dirname */ + g_free (dirname); + } + /* release the URI */ + g_free (uri); + } } -- 2.11.0