From 699ce127f8f18007d2894da87c81a31727b0a5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Fri, 12 May 2017 10:54:37 -0300 Subject: shell: Save document to the same path it was opened from When annotating or filling a form in a document, this must be saved as a different document as atril does not overwrite documents. The user can expect to store the modified file in the same place than the original document, except when the document lives in a temporary directory (e.g. downloaded automatically with a web browser), in whose case it must fallback to the Documents directory (if set) or the the home directory. Previously, atril assumed the latest directory used, or the place where an image or attachment was stored last. Such behaviour is confusing because the latest place opened might have no relation with the document modified. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=767611 Adapted from https://gitlab.gnome.org/GNOME/evince/commit/319a6d49 --- shell/ev-window.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/shell/ev-window.c b/shell/ev-window.c index 566b34d0..b4d24b09 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -3207,11 +3207,12 @@ static void ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window) { GtkWidget *fc; - gchar *base_name; - GFile *file; + gchar *base_name, *dir_name, *var_tmp_dir, *tmp_dir; + GFile *file, *parent; + const gchar *default_dir, *dest_dir, *documents_dir; fc = gtk_file_chooser_dialog_new ( - _("Save a Copy"), + _("Save As…"), GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE, "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-save", GTK_RESPONSE_OK, @@ -3224,14 +3225,31 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window) gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE); file = g_file_new_for_uri (ev_window->priv->uri); base_name = g_file_get_basename (file); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name); + parent = g_file_get_parent (file); + dir_name = g_file_get_path (parent); + g_object_unref (parent); - g_object_unref (file); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name); g_free (base_name); - ev_window_file_chooser_restore_folder (ev_window, GTK_FILE_CHOOSER (fc), - ev_window->priv->uri, - G_USER_DIRECTORY_DOCUMENTS); + documents_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); + default_dir = g_file_test (documents_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ? + documents_dir : g_get_home_dir (); + + tmp_dir = g_build_filename ("tmp", NULL); + var_tmp_dir = g_build_filename ("var", "tmp", NULL); + dest_dir = dir_name && !g_str_has_prefix (dir_name, g_get_tmp_dir ()) && + !g_str_has_prefix (dir_name, tmp_dir) && + !g_str_has_prefix (dir_name, var_tmp_dir) ? + dir_name : default_dir; + + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), + dest_dir); + + g_object_unref (file); + g_free (tmp_dir); + g_free (var_tmp_dir); + g_free (dir_name); g_signal_connect (fc, "response", G_CALLBACK (file_save_dialog_response_cb), @@ -3846,7 +3864,7 @@ ev_window_check_document_modified (EvWindow *ev_window) GTK_RESPONSE_NO, "gtk-cancel", GTK_RESPONSE_CANCEL, - _("Save a _Copy"), + _("_Save As…"), GTK_RESPONSE_YES, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); @@ -6340,7 +6358,7 @@ static const GtkActionEntry entries[] = { { "FileOpenCopy", NULL, N_("Op_en a Copy"), "N", N_("Open a copy of the current document in a new window"), G_CALLBACK (ev_window_cmd_file_open_copy) }, - { "FileSaveAs", "document-save-as", N_("_Save a Copy…"), "S", + { "FileSaveAs", "document-save-as", N_("_Save As…"), "S", N_("Save a copy of the current document"), G_CALLBACK (ev_window_cmd_save_as) }, { "FileSendTo", EV_STOCK_SEND_TO, N_("Send _To..."), NULL, @@ -6350,7 +6368,7 @@ static const GtkActionEntry entries[] = { N_("Print this document"), G_CALLBACK (ev_window_cmd_file_print) }, { "FileProperties", "document-properties", N_("P_roperties"), "Return", NULL, - G_CALLBACK (ev_window_cmd_file_properties) }, + G_CALLBACK (ev_window_cmd_file_properties) }, { "FileCloseWindow", "window-close", N_("_Close"), "W", NULL, G_CALLBACK (ev_window_cmd_file_close_window) }, -- cgit v1.2.1