Skip to content

Commit 699ce12

Browse files
gpooraveit65
authored andcommitted
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
1 parent a6fc396 commit 699ce12

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

shell/ev-window.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,11 +3207,12 @@ static void
32073207
ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
32083208
{
32093209
GtkWidget *fc;
3210-
gchar *base_name;
3211-
GFile *file;
3210+
gchar *base_name, *dir_name, *var_tmp_dir, *tmp_dir;
3211+
GFile *file, *parent;
3212+
const gchar *default_dir, *dest_dir, *documents_dir;
32123213

32133214
fc = gtk_file_chooser_dialog_new (
3214-
_("Save a Copy"),
3215+
_("Save As…"),
32153216
GTK_WINDOW (ev_window), GTK_FILE_CHOOSER_ACTION_SAVE,
32163217
"gtk-cancel", GTK_RESPONSE_CANCEL,
32173218
"gtk-save", GTK_RESPONSE_OK,
@@ -3224,14 +3225,31 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
32243225
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
32253226
file = g_file_new_for_uri (ev_window->priv->uri);
32263227
base_name = g_file_get_basename (file);
3227-
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
3228+
parent = g_file_get_parent (file);
3229+
dir_name = g_file_get_path (parent);
3230+
g_object_unref (parent);
32283231

3229-
g_object_unref (file);
3232+
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
32303233
g_free (base_name);
32313234

3232-
ev_window_file_chooser_restore_folder (ev_window, GTK_FILE_CHOOSER (fc),
3233-
ev_window->priv->uri,
3234-
G_USER_DIRECTORY_DOCUMENTS);
3235+
documents_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
3236+
default_dir = g_file_test (documents_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ?
3237+
documents_dir : g_get_home_dir ();
3238+
3239+
tmp_dir = g_build_filename ("tmp", NULL);
3240+
var_tmp_dir = g_build_filename ("var", "tmp", NULL);
3241+
dest_dir = dir_name && !g_str_has_prefix (dir_name, g_get_tmp_dir ()) &&
3242+
!g_str_has_prefix (dir_name, tmp_dir) &&
3243+
!g_str_has_prefix (dir_name, var_tmp_dir) ?
3244+
dir_name : default_dir;
3245+
3246+
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
3247+
dest_dir);
3248+
3249+
g_object_unref (file);
3250+
g_free (tmp_dir);
3251+
g_free (var_tmp_dir);
3252+
g_free (dir_name);
32353253

32363254
g_signal_connect (fc, "response",
32373255
G_CALLBACK (file_save_dialog_response_cb),
@@ -3846,7 +3864,7 @@ ev_window_check_document_modified (EvWindow *ev_window)
38463864
GTK_RESPONSE_NO,
38473865
"gtk-cancel",
38483866
GTK_RESPONSE_CANCEL,
3849-
_("Save a _Copy"),
3867+
_("_Save As…"),
38503868
GTK_RESPONSE_YES,
38513869
NULL);
38523870
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
@@ -6340,7 +6358,7 @@ static const GtkActionEntry entries[] = {
63406358
{ "FileOpenCopy", NULL, N_("Op_en a Copy"), "<control>N",
63416359
N_("Open a copy of the current document in a new window"),
63426360
G_CALLBACK (ev_window_cmd_file_open_copy) },
6343-
{ "FileSaveAs", "document-save-as", N_("_Save a Copy…"), "<control>S",
6361+
{ "FileSaveAs", "document-save-as", N_("_Save As…"), "<control>S",
63446362
N_("Save a copy of the current document"),
63456363
G_CALLBACK (ev_window_cmd_save_as) },
63466364
{ "FileSendTo", EV_STOCK_SEND_TO, N_("Send _To..."), NULL,
@@ -6350,7 +6368,7 @@ static const GtkActionEntry entries[] = {
63506368
N_("Print this document"),
63516369
G_CALLBACK (ev_window_cmd_file_print) },
63526370
{ "FileProperties", "document-properties", N_("P_roperties"), "<alt>Return", NULL,
6353-
G_CALLBACK (ev_window_cmd_file_properties) },
6371+
G_CALLBACK (ev_window_cmd_file_properties) },
63546372
{ "FileCloseWindow", "window-close", N_("_Close"), "<control>W", NULL,
63556373
G_CALLBACK (ev_window_cmd_file_close_window) },
63566374

0 commit comments

Comments
 (0)