diff options
Diffstat (limited to 'src/extension/system.cpp')
| -rw-r--r-- | src/extension/system.cpp | 102 |
1 files changed, 97 insertions, 5 deletions
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 <interface.h> +#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 */ |
