[evince] shell: Save document to the same path it was opened from



commit 319a6d4922d7a700b10b8aa92c6edf34fdfcec99
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Fri May 12 10:54:37 2017 -0300

    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 evince 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, evince 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

 shell/ev-application.c |    2 +-
 shell/ev-window.c      |   44 ++++++++++++++++++++++++++++++++------------
 shell/evince-menus.ui  |    4 ++--
 3 files changed, 35 insertions(+), 15 deletions(-)
---
diff --git a/shell/ev-application.c b/shell/ev-application.c
index eb5a94b..263390c 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -1051,7 +1051,7 @@ ev_application_startup (GApplication *gapplication)
         const gchar *action_accels[] = {
           "win.open",                   "<Ctrl>O", NULL,
           "win.open-copy",              "<Ctrl>N", NULL,
-          "win.save-copy",              "<Ctrl>S", NULL,
+          "win.save-as",                "<Ctrl>S", NULL,
           "win.print",                  "<Ctrl>P", NULL,
           "win.show-properties",        "<alt>Return", NULL,
           "win.copy",                   "<Ctrl>C", "<Ctrl>Insert", NULL,
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 6509b51..4a76434 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -480,7 +480,7 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
 
        /* File menu */
        ev_window_set_action_enabled (ev_window, "open-copy", has_document);
-       ev_window_set_action_enabled (ev_window, "save-copy", has_document &&
+       ev_window_set_action_enabled (ev_window, "save-as", has_document &&
                                      ok_to_copy && !recent_view_mode);
        ev_window_set_action_enabled (ev_window, "print", has_pages &&
                                      ok_to_print && !recent_view_mode);
@@ -2823,14 +2823,15 @@ file_save_dialog_response_cb (GtkWidget *fc,
 }
 
 static void
-ev_window_save_a_copy (EvWindow *ev_window)
+ev_window_save_as (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_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                GTK_STOCK_SAVE, GTK_RESPONSE_OK,
@@ -2845,15 +2846,34 @@ ev_window_save_a_copy (EvWindow *ev_window)
 
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
        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);
+       parent = g_file_get_parent (file);
+       dir_name = g_file_get_path (parent);
+       g_object_unref (parent);
+
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
-       g_object_unref (file);
        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),
@@ -2869,7 +2889,7 @@ ev_window_cmd_save_as (GSimpleAction *action,
 {
        EvWindow *window = user_data;
 
-       ev_window_save_a_copy (window);
+       ev_window_save_as (window);
 }
 
 static void
@@ -3514,7 +3534,7 @@ document_modified_confirmation_dialog_response (GtkDialog *dialog,
 
        switch (response) {
        case GTK_RESPONSE_YES:
-               ev_window_save_a_copy (ev_window);
+               ev_window_save_as (ev_window);
                break;
        case GTK_RESPONSE_NO:
                gtk_widget_destroy (GTK_WIDGET (ev_window));
@@ -5649,7 +5669,7 @@ ev_window_class_init (EvWindowClass *ev_window_class)
 static const GActionEntry actions[] = {
        { "open", ev_window_cmd_file_open },
        { "open-copy", ev_window_cmd_file_open_copy },
-       { "save-copy", ev_window_cmd_save_as },
+       { "save-as", ev_window_cmd_save_as },
        { "send-to", ev_window_cmd_send_to },
        { "open-containing-folder", ev_window_cmd_open_containing_folder },
        { "print", ev_window_cmd_file_print },
diff --git a/shell/evince-menus.ui b/shell/evince-menus.ui
index e43d124..6100777 100644
--- a/shell/evince-menus.ui
+++ b/shell/evince-menus.ui
@@ -136,8 +136,8 @@
         <attribute name="action">win.open-copy</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">_Save a Copy…</attribute>
-        <attribute name="action">win.save-copy</attribute>
+        <attribute name="label" translatable="yes">_Save As…</attribute>
+        <attribute name="action">win.save-as</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">Send _To…</attribute>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]