Skip to content
Browse files

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.

    Adapted from
  • Loading branch information...
gpoo authored and raveit65 committed May 12, 2017
1 parent f4b9c80 commit 91d5b0f695948b84d67ff3c0a2e6cedd010cac76
Showing with 29 additions and 11 deletions.
  1. +29 −11 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-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),
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),

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)
_("Save a _Copy"),
_("_Save As…"),
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
@@ -6343,7 +6361,7 @@ static const GtkActionEntry entries[] = {
{ "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>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"), "<control>S",
{ "FileSaveAs", "document-save-as", N_("_Save As"), "<control>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,
@@ -6353,7 +6371,7 @@ static const GtkActionEntry entries[] = {
N_("Print this document"),
G_CALLBACK (ev_window_cmd_file_print) },
{ "FileProperties", "document-properties", N_("P_roperties"), "<alt>Return", NULL,
G_CALLBACK (ev_window_cmd_file_properties) },
G_CALLBACK (ev_window_cmd_file_properties) },
{ "FileCloseWindow", "window-close", N_("_Close"), "<control>W", NULL,
G_CALLBACK (ev_window_cmd_file_close_window) },

0 comments on commit 91d5b0f

Please sign in to comment.
You can’t perform that action at this time.