summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermán Poo-Caamaño <[email protected]>2017-05-12 10:54:37 -0300
committerraveit65 <[email protected]>2018-10-26 23:03:18 +0200
commit91d5b0f695948b84d67ff3c0a2e6cedd010cac76 (patch)
tree43e8bc37c5ea45ca5568dfb3af6d9b53708b032e
parentf4b9c800c5121888e90098311257a366a5dab69d (diff)
downloadatril-91d5b0f695948b84d67ff3c0a2e6cedd010cac76.tar.bz2
atril-91d5b0f695948b84d67ff3c0a2e6cedd010cac76.tar.xz
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
-rw-r--r--shell/ev-window.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 993ef519..8d0b37d5 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);
@@ -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) },