Skip to content

Commit

Permalink
shell: Save document to the same path it was opened from
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
gpoo authored and raveit65 committed Oct 26, 2018
1 parent f4b9c80 commit 91d5b0f
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions shell/ev-window.c
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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) },

Expand Down

0 comments on commit 91d5b0f

Please sign in to comment.