From 4396022ebd72ef9b66c185b732e141ff5ebcb5c4 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Thu, 25 Oct 2018 22:56:51 +0200 Subject: [PATCH] Start archive application from file's directory (Bug #14773) --- scripts/ark.tap | 4 ++-- scripts/engrampa.tap | 6 +++--- scripts/file-roller.tap | 8 ++++---- thunar-archive-plugin/tap-provider.c | 32 +++++++++++++++++++++----------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/scripts/ark.tap b/scripts/ark.tap index d42138c..5358ab2 100644 --- a/scripts/ark.tap +++ b/scripts/ark.tap @@ -25,7 +25,7 @@ # determine the action and the folder, $@ then contains only the files action=$1; shift; -folder=$1; shift; +pwd=$1; shift; # check the action case $action in @@ -34,7 +34,7 @@ create) ;; extract-here) - exec ark --extract-to "$folder" "$@" + exec ark --extract-to "$pwd" "$@" ;; extract-to) diff --git a/scripts/engrampa.tap b/scripts/engrampa.tap index 1081d7c..58fc916 100644 --- a/scripts/engrampa.tap +++ b/scripts/engrampa.tap @@ -25,16 +25,16 @@ # determine the action and the folder, $@ then contains only the files action=$1; shift; -folder=$1; shift; +pwd=$1; shift; # check the action case $action in create) - exec engrampa --default-dir="$folder" --add "$@" + exec engrampa --default-dir="$pwd" --add "$@" ;; extract-here) - exec engrampa --extract-to="$(pwd)" --extract-here --force "$@" + exec engrampa --extract-to="$pwd" --extract-here --force "$@" ;; extract-to) diff --git a/scripts/file-roller.tap b/scripts/file-roller.tap index c238c40..35197ad 100644 --- a/scripts/file-roller.tap +++ b/scripts/file-roller.tap @@ -26,20 +26,20 @@ # determine the action and the folder, $@ then contains only the files action=$1; shift; -folder=$1; shift; +pwd=$1; shift; # check the action case $action in create) - exec file-roller "--default-dir=$folder" --add "$@" + exec file-roller "--default-dir=$pwd" --add "$@" ;; extract-here) - exec file-roller "--extract-to=$(pwd)" --extract-here --force "$@" + exec file-roller "--extract-to=$pwd" --extract-here --force "$@" ;; extract-to) - exec file-roller "--default-dir=$folder" --extract "$@" + exec file-roller "--default-dir=$pwd" --extract "$@" ;; *) diff --git a/thunar-archive-plugin/tap-provider.c b/thunar-archive-plugin/tap-provider.c index bfc30f5..04499d6 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,24 @@ 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); + if (G_UNLIKELY (uri == NULL)) + return; - /* 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")); + /* determine the directory of the first selected file */ + dirname = g_filename_from_uri (uri, NULL, NULL); + g_free (uri); + + /* verify that we were able to determine a local path */ + if (G_UNLIKELY (dirname == NULL)) + return; + + /* execute the action */ + tap_provider_execute (tap_provider, tap_backend_extract_to, window, dirname, files, _("Failed to extract files")); + + /* cleanup */ + g_free (dirname); } -- 2.11.0