From d8d60c60ebeeefb068d9b68bf7d96f1f1f88518a Mon Sep 17 00:00:00 2001 From: Adib Taraben Date: Sat, 1 Aug 2009 23:31:02 +0000 Subject: FIX 309856 353847: correctly advertise exception leads to error message dialogue (bzr r8380) --- src/extension/system.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index a7828d3fc..33ee544a1 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -277,7 +277,19 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, doc->setModifiedSinceSave(false); } - omod->save(doc, fileName); + try { + omod->save(doc, fileName); + } + catch(...) { + // free used ressources + if ( !official) { + g_free(saved_output_extension); + g_free(saved_dataloss); + } + g_free(fileName); + + throw Inkscape::Extension::Output::save_failed(); + } // If it is an unofficial save, set the modified attributes back to what they were. if ( !official) { -- cgit v1.2.3 From 98f6e4db3c307628c9d02cb432986741d59af058 Mon Sep 17 00:00:00 2001 From: theAdib Date: Sun, 2 Aug 2009 20:42:44 +0000 Subject: FIX 309856 353847 in case save_as fails the document uri is reverted (bzr r8387) --- src/extension/system.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 33ee544a1..d7e0eebf3 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -247,15 +247,16 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, Inkscape::XML::Node *repr = sp_document_repr_root(doc); - // remember attributes in case this is an unofficial save + + // remember attributes in case this is an unofficial save and/or overwrite fails + gchar *saved_uri = g_strdup(doc->uri); bool saved_modified = false; gchar *saved_output_extension = NULL; gchar *saved_dataloss = NULL; - if (!official) { - saved_modified = doc->isModifiedSinceSave(); - saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension")); - saved_dataloss = g_strdup(repr->attribute("inkscape:dataloss")); - } else { + saved_modified = doc->isModifiedSinceSave(); + saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension")); + saved_dataloss = g_strdup(repr->attribute("inkscape:dataloss")); + if (official) { /* The document is changing name/uri. */ sp_document_change_uri_and_hrefs(doc, fileName); } @@ -281,11 +282,23 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, omod->save(doc, fileName); } catch(...) { - // free used ressources - if ( !official) { - g_free(saved_output_extension); - g_free(saved_dataloss); + // revert attributes in case of official and overwrite + if(check_overwrite && official) { + bool const saved = sp_document_get_undo_sensitive(doc); + sp_document_set_undo_sensitive(doc, false); + { + repr->setAttribute("inkscape:output_extension", saved_output_extension); + repr->setAttribute("inkscape:dataloss", saved_dataloss); + } + sp_document_set_undo_sensitive(doc, saved); + sp_document_change_uri_and_hrefs(doc, saved_uri); } + doc->setModifiedSinceSave(saved_modified); + // free used ressources + g_free(saved_output_extension); + g_free(saved_dataloss); + g_free(saved_uri); + g_free(fileName); throw Inkscape::Extension::Output::save_failed(); -- cgit v1.2.3 From a6fa3b454bdcef9b23e0a3107b6de6b4c6a477a0 Mon Sep 17 00:00:00 2001 From: johnce Date: Wed, 5 Aug 2009 05:56:35 +0000 Subject: SPDocument->Document (bzr r8405) --- src/extension/system.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index d7e0eebf3..ad49c3d2a 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -59,7 +59,7 @@ static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementatio * * Lastly, the open function is called in the module itself. */ -SPDocument * +Document * open(Extension *key, gchar const *filename) { Input *imod = NULL; @@ -91,7 +91,7 @@ open(Extension *key, gchar const *filename) if (!imod->prefs(filename)) return NULL; - SPDocument *doc = imod->open(filename); + Document *doc = imod->open(filename); if (!doc) { throw Input::open_failed(); } @@ -184,7 +184,7 @@ open_internal(Extension *in_plug, gpointer in_data) * Lastly, the save function is called in the module itself. */ void -save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official) +save(Extension *key, Document *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official) { Output *omod; if (key == NULL) { -- cgit v1.2.3 From 51c2905fd3e99955db2d823b79abb763d8097028 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Thu, 6 Aug 2009 14:17:17 +0000 Subject: Revert recent refactoring changes by johnce because they break the build, which cannot be fixed easily. (bzr r8422) --- src/extension/system.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index ad49c3d2a..d7e0eebf3 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -59,7 +59,7 @@ static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementatio * * Lastly, the open function is called in the module itself. */ -Document * +SPDocument * open(Extension *key, gchar const *filename) { Input *imod = NULL; @@ -91,7 +91,7 @@ open(Extension *key, gchar const *filename) if (!imod->prefs(filename)) return NULL; - Document *doc = imod->open(filename); + SPDocument *doc = imod->open(filename); if (!doc) { throw Input::open_failed(); } @@ -184,7 +184,7 @@ open_internal(Extension *in_plug, gpointer in_data) * Lastly, the save function is called in the module itself. */ void -save(Extension *key, Document *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official) +save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official) { Output *omod; if (key == NULL) { -- cgit v1.2.3 From 606ebb35498c3d750bb2906954195baaa0fbcad6 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Sun, 9 Aug 2009 14:23:52 +0000 Subject: Fix remaining glitches in the behaviour of the Save dialogs (w.r.t. remembering the last file type and folder). As part of the cleanup inkscape:output_extension was removed, too. (bzr r8454) --- src/extension/system.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 5 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index d7e0eebf3..2251ac7b6 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -20,6 +20,8 @@ #include +#include "system.h" +#include "preferences.h" #include "extension.h" #include "db.h" #include "input.h" @@ -184,7 +186,8 @@ open_internal(Extension *in_plug, gpointer in_data) * Lastly, the save function is called in the module itself. */ void -save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official) +save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official, + Inkscape::Extension::FileSaveMethod save_method) { Output *omod; if (key == NULL) { @@ -254,7 +257,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, gchar *saved_output_extension = NULL; gchar *saved_dataloss = NULL; saved_modified = doc->isModifiedSinceSave(); - saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension")); + saved_output_extension = g_strdup(get_file_save_extension(save_method).c_str()); saved_dataloss = g_strdup(repr->attribute("inkscape:dataloss")); if (official) { /* The document is changing name/uri. */ @@ -267,7 +270,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, sp_document_set_undo_sensitive(doc, false); { // also save the extension for next use - repr->setAttribute("inkscape:output_extension", omod->get_id()); + store_file_extension_in_prefs (omod->get_id(), save_method); // set the "dataloss" attribute if the chosen extension is lossy repr->setAttribute("inkscape:dataloss", NULL); if (omod->causes_dataloss()) { @@ -287,7 +290,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool const saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); { - repr->setAttribute("inkscape:output_extension", saved_output_extension); + store_file_extension_in_prefs (saved_output_extension, save_method); repr->setAttribute("inkscape:dataloss", saved_dataloss); } sp_document_set_undo_sensitive(doc, saved); @@ -309,7 +312,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool const saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); { - repr->setAttribute("inkscape:output_extension", saved_output_extension); + store_file_extension_in_prefs (saved_output_extension, save_method); repr->setAttribute("inkscape:dataloss", saved_dataloss); } sp_document_set_undo_sensitive(doc, saved); @@ -544,6 +547,95 @@ build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp) return ext; } +/* + * TODO: Is it guaranteed that the returned extension is valid? If so, we can remove the check for + * filename_extension in sp_file_save_dialog(). + */ +Glib::ustring +get_file_save_extension (Inkscape::Extension::FileSaveMethod method) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring extension; + switch (method) { + case FILE_SAVE_METHOD_SAVE_AS: + case FILE_SAVE_METHOD_TEMPORARY: + extension = prefs->getString("/dialogs/save_as/default"); + break; + case FILE_SAVE_METHOD_SAVE_COPY: + extension = prefs->getString("/dialogs/save_copy/default"); + break; + case FILE_SAVE_METHOD_INKSCAPE_SVG: + extension = SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE; + break; + } + + // this is probably unnecessary, but just to be on the safe side ... + if(extension.empty()) + extension = SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE; + + return extension; +} + +Glib::ustring +get_file_save_path (SPDocument *doc, FileSaveMethod method) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring path; + switch (method) { + case FILE_SAVE_METHOD_SAVE_AS: + case FILE_SAVE_METHOD_TEMPORARY: + path = prefs->getString("/dialogs/save_as/path"); + break; + case FILE_SAVE_METHOD_SAVE_COPY: + path = prefs->getString("/dialogs/save_copy/path"); + break; + case FILE_SAVE_METHOD_INKSCAPE_SVG: + if (doc->uri) { + path = Glib::path_get_dirname(doc->uri); + } else { + // FIXME: should we use the save_as path here or the current directory or even something else? + path = prefs->getString("/dialogs/save_as/path"); + } + } + + // this is probably unnecessary, but just to be on the safe side ... + if(path.empty()) + path = g_get_current_dir(); // is this the most sensible solution? + + return path; +} + +void +store_file_extension_in_prefs (Glib::ustring extension, FileSaveMethod method) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + switch (method) { + case FILE_SAVE_METHOD_SAVE_AS: + case FILE_SAVE_METHOD_TEMPORARY: + prefs->setString("/dialogs/save_as/default", extension); + break; + case FILE_SAVE_METHOD_SAVE_COPY: + prefs->setString("/dialogs/save_copy/default", extension); + break; + case FILE_SAVE_METHOD_INKSCAPE_SVG: + // do nothing + break; + } +} + +void +store_save_path_in_prefs (Glib::ustring path, FileSaveMethod method) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + switch (method) { + case FILE_SAVE_METHOD_SAVE_AS: + case FILE_SAVE_METHOD_TEMPORARY: + prefs->setString("/dialogs/save_as/path", path); + break; + case FILE_SAVE_METHOD_SAVE_COPY: + prefs->setString("/dialogs/save_copy/path", path); + break; + case FILE_SAVE_METHOD_INKSCAPE_SVG: + // do nothing + break; + } +} } } /* namespace Inkscape::Extension */ -- cgit v1.2.3 From 9f9e21dec8cc697d91646924da431fc04a2b78bd Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Wed, 12 Aug 2009 13:18:51 +0000 Subject: Don't open 'Save as ...' dialog inside the application bundle on OS X when it is invoked for the first time (bzr r8472) --- src/extension/system.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 2251ac7b6..365ea925b 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -568,7 +568,6 @@ get_file_save_extension (Inkscape::Extension::FileSaveMethod method) { break; } - // this is probably unnecessary, but just to be on the safe side ... if(extension.empty()) extension = SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE; @@ -591,14 +590,17 @@ get_file_save_path (SPDocument *doc, FileSaveMethod method) { if (doc->uri) { path = Glib::path_get_dirname(doc->uri); } else { - // FIXME: should we use the save_as path here or the current directory or even something else? + // FIXME: should we use the save_as path here or something else? Maybe we should + // leave this as a choice to the user. path = prefs->getString("/dialogs/save_as/path"); } } - // this is probably unnecessary, but just to be on the safe side ... if(path.empty()) - path = g_get_current_dir(); // is this the most sensible solution? + path = g_get_home_dir(); // Is this the most sensible solution? Note that we should avoid + // g_get_current_dir because this leads to problems on OS X where + // Inkscape opens the dialog inside application bundle when it is + // invoked for the first teim. return path; } -- cgit v1.2.3 From 1807c74cbec5204385b71b3a120ebcd40f80c18e Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Wed, 16 Sep 2009 02:04:50 +0000 Subject: Fix by Adib for 353847 (bzr r8601) --- src/extension/system.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 365ea925b..43e7af494 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -32,6 +32,7 @@ #include "implementation/script.h" #include "implementation/xslt.h" #include "xml/rebase-hrefs.h" +#include "io/sys.h" /* #include "implementation/plugin.h" */ namespace Inkscape { @@ -248,6 +249,13 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, throw Output::no_overwrite(); } + // test if the file exists and is writable + // the test only checks the file attributes and might pass where ACL does not allow to write + if (Inkscape::IO::file_test(filename, G_FILE_TEST_EXISTS) && !Inkscape::IO::file_is_writable(filename)) { + g_free(fileName); + throw Output::file_read_only(); + } + Inkscape::XML::Node *repr = sp_document_repr_root(doc); -- cgit v1.2.3 From dc1d762c9e37b7932411fe513d5222c2928a2251 Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Fri, 2 Oct 2009 21:17:41 +0000 Subject: Patch by Max to add option for better Save As behavior. (bzr r8697) --- src/extension/system.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 43e7af494..f41217959 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -588,6 +588,15 @@ get_file_save_path (SPDocument *doc, FileSaveMethod method) { Glib::ustring path; switch (method) { case FILE_SAVE_METHOD_SAVE_AS: + { + bool use_current_dir = prefs->getBool("/dialogs/save_as/use_current_dir"); + if (doc->uri && use_current_dir) { + path = Glib::path_get_dirname(doc->uri); + } else { + path = prefs->getString("/dialogs/save_as/path"); + } + break; + } case FILE_SAVE_METHOD_TEMPORARY: path = prefs->getString("/dialogs/save_as/path"); break; -- cgit v1.2.3 From 62696234b51b95b6da2b2612162cc4f185481a47 Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Sun, 18 Oct 2009 19:17:16 +0000 Subject: Patch by Adib for 429529 (bzr r8792) --- src/extension/system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index f41217959..6ffa7f57f 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -206,7 +206,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, } /* If autodetect fails, save as Inkscape SVG */ if (omod == NULL) { - omod = dynamic_cast(db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE)); + // omod = dynamic_cast(db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE)); use exception and let user choose } } else { omod = dynamic_cast(key); -- cgit v1.2.3