From 48ca4bc36d8d8fa0536dc5f3eb619ae0c369c9d7 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sun, 9 Aug 2009 14:23:52 +0000 Subject: [PATCH] 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. --- src/dialogs/export.cpp | 3 +- src/extension/implementation/script.cpp | 13 +- src/extension/input.cpp | 13 -- src/extension/system.cpp | 102 ++++++++++++++- src/extension/system.h | 53 +++++++- src/file.cpp | 157 +++++++++++------------- src/file.h | 4 +- src/ui/dialog/filedialog.cpp | 6 +- src/ui/dialog/filedialog.h | 6 +- src/ui/dialog/filedialogimpl-gtkmm.cpp | 18 ++- src/ui/dialog/filedialogimpl-gtkmm.h | 8 +- src/ui/dialog/filedialogimpl-win32.cpp | 5 +- src/ui/dialog/filedialogimpl-win32.h | 2 +- src/ui/view/edit-widget.cpp | 2 +- src/widgets/desktop-widget.cpp | 4 +- 15 files changed, 254 insertions(+), 142 deletions(-) diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index 0cde76657..835003e5e 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -540,8 +540,7 @@ sp_export_dialog (void) gchar *name; SPDocument * doc = SP_ACTIVE_DOCUMENT; const gchar *uri = SP_DOCUMENT_URI (doc); - Inkscape::XML::Node * repr = sp_document_repr_root(doc); - const gchar * text_extension = repr->attribute("inkscape:output_extension"); + const gchar *text_extension = Inkscape::Preferences::get()->getString("/dialogs/save_as/default").c_str(); Inkscape::Extension::Output * oextension = NULL; if (text_extension != NULL) { diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index e6ce40bc0..5f1bef8d1 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -477,7 +477,7 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : Inkscape::Extension::save( Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE), - view->doc(), _filename.c_str(), false, false, false); + view->doc(), _filename.c_str(), false, false, false, Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); return; } @@ -641,11 +641,13 @@ Script::save(Inkscape::Extension::Output *module, if (helper_extension.size() == 0) { Inkscape::Extension::save( Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE), - doc, tempfilename_in.c_str(), false, false, false); + doc, tempfilename_in.c_str(), false, false, false, + Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); } else { Inkscape::Extension::save( Inkscape::Extension::db.get(helper_extension.c_str()), - doc, tempfilename_in.c_str(), false, false, false); + doc, tempfilename_in.c_str(), false, false, false, + Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); } @@ -714,8 +716,6 @@ Script::effect(Inkscape::Extension::Effect *module, SPDesktop *desktop = (SPDesktop *)doc; sp_namedview_document_from_window(desktop); - gchar * orig_output_extension = g_strdup(sp_document_repr_root(desktop->doc())->attribute("inkscape:output_extension")); - std::list params; module->paramListString(params); @@ -779,10 +779,7 @@ Script::effect(Inkscape::Extension::Effect *module, doc->doc()->emitReconstructionFinish(); mydoc->release(); sp_namedview_update_layers_from_document(desktop); - - sp_document_repr_root(desktop->doc())->setAttribute("inkscape:output_extension", orig_output_extension); } - g_free(orig_output_extension); return; } diff --git a/src/extension/input.cpp b/src/extension/input.cpp index 689c1286f..b4599dbd0 100644 --- a/src/extension/input.cpp +++ b/src/extension/input.cpp @@ -138,12 +138,6 @@ Input::check (void) from a file. The first thing that this does is make sure that the file actually exists. If it doesn't, a NULL is returned. If the file exits, then it is opened using the implmentation of this extension. - - After opening the document the output_extension is set. What this - accomplishes is that save can try to use an extension that supports - the same fileformat. So something like opening and saveing an - Adobe Illustrator file can be transparent (not recommended, but - transparent). This is all done with undo being turned off. */ SPDocument * Input::open (const gchar *uri) @@ -157,13 +151,6 @@ Input::open (const gchar *uri) timer->touch(); SPDocument *const doc = imp->open(this, uri); - if (doc != NULL) { - Inkscape::XML::Node * repr = sp_document_repr_root(doc); - bool saved = sp_document_get_undo_sensitive(doc); - sp_document_set_undo_sensitive (doc, false); - repr->setAttribute("inkscape:output_extension", output_extension); - sp_document_set_undo_sensitive (doc, saved); - } return doc; } 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 */ diff --git a/src/extension/system.h b/src/extension/system.h index 6c23b2f0d..b6740e109 100644 --- a/src/extension/system.h +++ b/src/extension/system.h @@ -21,13 +21,64 @@ namespace Inkscape { namespace Extension { +/** + * Used to distinguish between the various invocations of the save dialogs (and thus to determine + * the file type and save path offered in the dialog) + */ +enum FileSaveMethod { + FILE_SAVE_METHOD_SAVE_AS, + FILE_SAVE_METHOD_SAVE_COPY, + FILE_SAVE_METHOD_EXPORT, + // Fallback for special cases (e.g., when saving a document for the first time or after saving + // it in a lossy format) + FILE_SAVE_METHOD_INKSCAPE_SVG, + // For saving temporary files; we return the same data as for FILE_SAVE_METHOD_SAVE_AS + FILE_SAVE_METHOD_TEMPORARY, +}; + SPDocument *open(Extension *key, gchar const *filename); void save(Extension *key, SPDocument *doc, gchar const *filename, - bool setextension, bool check_overwrite, bool official); + bool setextension, bool check_overwrite, bool official, + Inkscape::Extension::FileSaveMethod save_method); Print *get_print(gchar const *key); Extension *build_from_file(gchar const *filename); Extension *build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp); +/** + * Determine the desired default file extension depending on the given file save method. + * The returned string is guaranteed to be non-empty. + * + * @param method the file save method of the dialog + * @return the corresponding default file extension + */ +Glib::ustring get_file_save_extension (FileSaveMethod method); + +/** + * Determine the desired default save path depending on the given FileSaveMethod. + * The returned string is guaranteed to be non-empty. + * + * @param method the file save method of the dialog + * @param doc the file's document + * @return the corresponding default save path + */ +Glib::ustring get_file_save_path (SPDocument *doc, FileSaveMethod method); + +/** + * Write the given file extension back to prefs so that it can be used later on. + * + * @param extension the file extension which should be written to prefs + * @param method the file save mathod of the dialog + */ +void store_file_extension_in_prefs (Glib::ustring extension, FileSaveMethod method); + +/** + * Write the given path back to prefs so that it can be used later on. + * + * @param path the path which should be written to prefs + * @param method the file save mathod of the dialog + */ +void store_save_path_in_prefs (Glib::ustring path, FileSaveMethod method); + } } /* namespace Inkscape::Extension */ #endif /* INKSCAPE_EXTENSION_SYSTEM_H__ */ diff --git a/src/file.cpp b/src/file.cpp index f16d87cbd..03fb7bd59 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -59,7 +59,6 @@ #include "selection.h" #include "sp-namedview.h" #include "style.h" -#include "ui/dialog/filedialog.h" #include "ui/dialog/ocaldialogs.h" #include "ui/view/view-widget.h" #include "uri.h" @@ -573,15 +572,17 @@ sp_file_vacuum() */ static bool file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, - Inkscape::Extension::Extension *key, bool saveas, bool official) + Inkscape::Extension::Extension *key, bool checkoverwrite, bool official, + Inkscape::Extension::FileSaveMethod save_method) { if (!doc || uri.size()<1) //Safety check return false; try { Inkscape::Extension::save(key, doc, uri.c_str(), - false, - saveas, official); + false, + checkoverwrite, official, + save_method); } catch (Inkscape::Extension::Output::no_extension_found &e) { gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str()); gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri); @@ -602,7 +603,7 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); return FALSE; } catch (Inkscape::Extension::Output::no_overwrite &e) { - return sp_file_save_dialog(parentWindow, doc); + return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); @@ -698,85 +699,58 @@ file_save_remote(SPDocument */*doc*/, /** * Display a SaveAs dialog. Save the document if OK pressed. - * - * \param ascopy (optional) wether to set the documents->uri to the new filename or not */ bool -sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) +sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method) { - - Inkscape::XML::Node *repr = sp_document_repr_root(doc); Inkscape::Extension::Output *extension = 0; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool is_copy = (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY); - //# Get the default extension name + // Note: default_extension has the format "org.inkscape.output.svg.inkscape", whereas + // filename_extension only uses ".svg" Glib::ustring default_extension; - char *attr = (char *)repr->attribute(is_copy ? "inkscape:output_extension_copy" : "inkscape:output_extension"); - if (!attr) { - Glib::ustring attr2 = prefs->getString(is_copy ? "/dialogs/save_copy/default" : "/dialogs/save_as/default"); - if(!attr2.empty()) default_extension = attr2; - } else { - default_extension = attr; - } + Glib::ustring filename_extension = ".svg"; + + default_extension= Inkscape::Extension::get_file_save_extension(save_method); //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension); + extension = dynamic_cast + (Inkscape::Extension::db.get(default_extension.c_str())); + + if (extension) + filename_extension = extension->get_extension(); + Glib::ustring save_path; Glib::ustring save_loc; - if (!default_extension.empty()) { - extension = dynamic_cast - (Inkscape::Extension::db.get(default_extension.c_str())); - } else { - g_warning ("No default extension!!!! What to do?\n"); - } + save_path = Inkscape::Extension::get_file_save_path(doc, save_method); - if (doc->uri && !is_copy) { - // Saving as a regular file: recover the filename from the existing doc->uri - save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri), - Glib::path_get_basename(doc->uri)); - } else { - Glib::ustring filename_extension = ".svg"; - //g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension); - if (extension) - filename_extension = extension->get_extension(); + if (!Inkscape::IO::file_test(save_path.c_str(), + (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) + save_path = ""; - Glib::ustring attr3 = prefs->getString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path"); - if (!attr3.empty()) - save_path = attr3; - - if (!Inkscape::IO::file_test(save_path.c_str(), - (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) - save_path = ""; + if (save_path.size()<1) + save_path = g_get_home_dir(); - if (save_path.size()<1) - save_path = g_get_home_dir(); + save_loc = save_path; + save_loc.append(G_DIR_SEPARATOR_S); - save_loc = save_path; - save_loc.append(G_DIR_SEPARATOR_S); + char formatBuf[256]; + int i = 1; + if (!doc->uri) { + // We are saving for the first time; create a unique default filename + snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str()); + save_loc.append(formatBuf); - char formatBuf[256]; - int i = 1; - if (!doc->uri) { - // We are saving for the first time; create a unique default filename - snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str()); + while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) { + save_loc = save_path; + save_loc.append(G_DIR_SEPARATOR_S); + snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str()); save_loc.append(formatBuf); - - while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) { - save_loc = save_path; - save_loc.append(G_DIR_SEPARATOR_S); - snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str()); - save_loc.append(formatBuf); - } - } else { - if (is_copy) { - // Use the document uri's base name as the filename but - // store in the directory last used for "Save a copy ..." - snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str()); - save_loc.append(formatBuf); - } else { - g_assert_not_reached(); - } } + } else { + snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str()); + save_loc.append(formatBuf); } // convert save_loc from utf-8 to locale @@ -803,7 +777,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) dialog_title, default_extension, doc_title ? doc_title : "", - is_copy + save_method ); saveDialog->setSelectionType(extension); @@ -834,15 +808,15 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) else g_warning( "Error converting save filename to UTF-8." ); - success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy); + // FIXME: does the argument !is_copy really convey the correct meaning here? + success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy, save_method); if (success && SP_DOCUMENT_URI(doc)) { sp_file_add_recent(SP_DOCUMENT_URI(doc)); } save_path = Glib::path_get_dirname(fileName); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path", save_path); + Inkscape::Extension::store_save_path_in_prefs(save_path, save_method); return success; } @@ -861,16 +835,26 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) bool success = true; if (doc->isModifiedSinceSave()) { - Inkscape::XML::Node *repr = sp_document_repr_root(doc); - if ( doc->uri == NULL - || repr->attribute("inkscape:output_extension") == NULL ) + if ( doc->uri == NULL ) { - return sp_file_save_dialog(parentWindow, doc, FALSE); + // Hier sollte in Argument mitgegeben werden, das anzeigt, daß das Dokument das erste + // Mal gespeichert wird, so daß als default .svg ausgewählt wird und nicht die zuletzt + // benutzte "Save as ..."-Endung + return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); } else { - gchar const *fn = g_strdup(doc->uri); - gchar const *ext = repr->attribute("inkscape:output_extension"); - success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE); - g_free((void *) fn); + Glib::ustring extension = Inkscape::Extension::get_file_save_extension(Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + Glib::ustring fn = g_strdup(doc->uri); + // Try to determine the extension from the uri; this may not lead to a valid extension, + // but this case is caught in the file_save method below (or rather in Extension::save() + // further down the line). + Glib::ustring ext = ""; + Glib::ustring::size_type pos = fn.rfind('.'); + if (pos != Glib::ustring::npos) { + // FIXME: this could/should be more sophisticated (see FileSaveDialog::appendExtension()), + // but hopefully it's a reasonable workaround for now + ext = fn.substr( pos ); + } + success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext.c_str()), FALSE, TRUE, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } } else { SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved.")); @@ -906,7 +890,7 @@ sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data* if (!SP_ACTIVE_DOCUMENT) return false; sp_namedview_document_from_window(SP_ACTIVE_DESKTOP); - return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE); + return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } @@ -920,7 +904,7 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d if (!SP_ACTIVE_DOCUMENT) return false; sp_namedview_document_from_window(SP_ACTIVE_DESKTOP); - return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE); + return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY); } @@ -1162,13 +1146,10 @@ sp_file_export_dialog(void *widget) Inkscape::Extension::Output *extension; //# Get the default extension name - Glib::ustring default_extension; - char *attr = (char *)repr->attribute("inkscape:output_extension_export"); - if (!attr) { - Glib::ustring attr2 = prefs->getString("/dialogs/save_export/default"); - if(!attr2.empty()) default_extension = attr2; - } else { - default_extension = attr; + Glib::ustring default_extension = prefs->getString("/dialogs/save_export/default"); + if(default_extension.empty()) { + // FIXME: Is this a good default? Should there be a macro for the string? + default_extension = "org.inkscape.output.png.cairo"; } //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension); @@ -1360,7 +1341,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) fileName = filePath; - success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE); + success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT); if (!success){ gchar *text = g_strdup_printf(_("Error saving a temporary copy")); diff --git a/src/file.h b/src/file.h index ce75a61a7..9913fbe1a 100644 --- a/src/file.h +++ b/src/file.h @@ -20,6 +20,7 @@ #include #include "extension/extension-forward.h" +#include "extension/system.h" struct SPDesktop; struct SPDocument; @@ -30,6 +31,7 @@ namespace Inkscape { } } + /*###################### ## N E W ######################*/ @@ -111,7 +113,7 @@ bool sp_file_save_a_copy (Gtk::Window &parentWindow, gpointer object, gpointer d bool sp_file_save_document (Gtk::Window &parentWindow, SPDocument *document); /* Do the saveas dialog with a document as the parameter */ -bool sp_file_save_dialog (Gtk::Window &parentWindow, SPDocument *doc, bool bAsCopy = FALSE); +bool sp_file_save_dialog (Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method); /*###################### diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index b1385195f..8e372c394 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -110,12 +110,12 @@ FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow, const char *title, const Glib::ustring &default_key, const gchar *docTitle, - const bool save_copy) + const Inkscape::Extension::FileSaveMethod save_method) { #ifdef WIN32 - FileSaveDialog *dialog = new FileSaveDialogImplWin32(parentWindow, path, fileTypes, title, default_key, docTitle, save_copy); + FileSaveDialog *dialog = new FileSaveDialogImplWin32(parentWindow, path, fileTypes, title, default_key, docTitle, save_method); #else - FileSaveDialog *dialog = new FileSaveDialogImplGtk(parentWindow, path, fileTypes, title, default_key, docTitle, save_copy); + FileSaveDialog *dialog = new FileSaveDialogImplGtk(parentWindow, path, fileTypes, title, default_key, docTitle, save_method); #endif return dialog; } diff --git a/src/ui/dialog/filedialog.h b/src/ui/dialog/filedialog.h index 6eab75a5b..f7be86ef3 100644 --- a/src/ui/dialog/filedialog.h +++ b/src/ui/dialog/filedialog.h @@ -21,6 +21,10 @@ #include #include +#include "extension/system.h" + +class SPDocument; + namespace Inkscape { namespace Extension { class Extension; @@ -164,7 +168,7 @@ public: const char *title, const Glib::ustring &default_key, const gchar *docTitle, - const bool save_copy); + const Inkscape::Extension::FileSaveMethod save_method); /** diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 53faa075a..3e681bd3b 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -884,9 +884,10 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, const Glib::ustring &title, const Glib::ustring &/*default_key*/, const gchar* docTitle, - const bool save_copy) : - FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, save_copy ? "/dialogs/save_copy" : "/dialogs/save_as"), - is_copy(save_copy) + const Inkscape::Extension::FileSaveMethod save_method) : + FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, + (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "/dialogs/save_copy" : "/dialogs/save_as"), + save_method(save_method) { FileSaveDialog::myDocTitle = docTitle; @@ -924,7 +925,7 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, //###### Do we want the .xxx extension automatically added? Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically"))); - if (save_copy) { + if (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) { fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_copy/append_extension", true)); } else { fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true)); @@ -1115,18 +1116,13 @@ FileSaveDialogImplGtk::show() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // Store changes of the "Append filename automatically" checkbox back to preferences. - if (is_copy) { + if (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) { prefs->setBool("/dialogs/save_copy/append_extension", fileTypeCheckbox.get_active()); } else { prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active()); } - // Store the last used save-as filetype to preferences. - if (is_copy) { - prefs->setString("/dialogs/save_copy/default", ( extension != NULL ? extension->get_id() : "" )); - } else { - prefs->setString("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" )); - } + Inkscape::Extension::store_file_extension_in_prefs ((extension != NULL ? extension->get_id() : "" ), save_method); cleanup( true ); diff --git a/src/ui/dialog/filedialogimpl-gtkmm.h b/src/ui/dialog/filedialogimpl-gtkmm.h index 2a37aed2b..ac868fecc 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.h +++ b/src/ui/dialog/filedialogimpl-gtkmm.h @@ -18,6 +18,7 @@ #define __FILE_DIALOGIMPL_H__ #include "filedialog.h" +#include "extension/system.h" //General includes #include @@ -286,7 +287,7 @@ public: const Glib::ustring &title, const Glib::ustring &default_key, const gchar* docTitle, - const bool save_copy); + const Inkscape::Extension::FileSaveMethod save_method); virtual ~FileSaveDialogImplGtk(); @@ -303,9 +304,10 @@ private: void updateNameAndExtension(); /** - * Whether the dialog was invoked by "Save as ..." or "Save a copy ..." + * The file save method (essentially whether the dialog was invoked by "Save as ..." or "Save a + * copy ..."), which is used to determine file extensions and save paths. */ - bool is_copy; + Inkscape::Extension::FileSaveMethod save_method; /** * Fix to allow the user to type the file name diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp index c703d3c75..690c74004 100644 --- a/src/ui/dialog/filedialogimpl-win32.cpp +++ b/src/ui/dialog/filedialogimpl-win32.cpp @@ -1498,8 +1498,9 @@ FileSaveDialogImplWin32::FileSaveDialogImplWin32(Gtk::Window &parent, const char *title, const Glib::ustring &/*default_key*/, const char *docTitle, - const bool save_copy) : - FileDialogBaseWin32(parent, dir, title, fileTypes, save_copy ? "dialogs.save_copy" : "dialogs.save_as"), + const FileSaveMethod save_method) : + FileDialogBaseWin32(parent, dir, title, fileTypes, + (save_method == FILE_SAVE_METHOD_SAVE_COPY) ? "dialogs.save_copy" : "dialogs.save_as"), _title_label(NULL), _title_edit(NULL) { diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index f74d9fccf..1f4a417f2 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -311,7 +311,7 @@ public: const char *title, const Glib::ustring &default_key, const char *docTitle, - const bool save_copy); + const FileSaveMethod save_method); /// Destructor virtual ~FileSaveDialogImplWin32(); diff --git a/src/ui/view/edit-widget.cpp b/src/ui/view/edit-widget.cpp index 756f4df73..1d319f97f 100644 --- a/src/ui/view/edit-widget.cpp +++ b/src/ui/view/edit-widget.cpp @@ -1247,7 +1247,7 @@ EditWidget::shutdown() _("The file \"%s\" was saved with a format (%s) that may cause data loss!\n\n" "Do you want to save this file as an Inkscape SVG?"), SP_DOCUMENT_NAME(doc), - Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name()); + SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE); Gtk::MessageDialog dlg (*this, markup, diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index a2f88c16d..6d9a61329 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -892,7 +892,7 @@ SPDesktopWidget::shutdown() _("The file \"%s\" was saved with a format (%s) that may cause data loss!\n\n" "Do you want to save this file as an Inkscape SVG?"), SP_DOCUMENT_NAME(doc), - Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name()); + SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE); // fix for bug 1767940: GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS); @@ -919,7 +919,7 @@ SPDesktopWidget::shutdown() Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window"); - if (sp_file_save_dialog(*window, doc)) { + if (sp_file_save_dialog(*window, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG)) { sp_document_unref(doc); } else { // save dialog cancelled or save failed sp_document_unref(doc); -- 2.30.2