summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f5a946)
raw | patch | inline | side by side (parent: 3f5a946)
author | cilix42 <cilix42@users.sourceforge.net> | |
Sun, 9 Aug 2009 14:23:52 +0000 (14:23 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Sun, 9 Aug 2009 14:23:52 +0000 (14:23 +0000) |
15 files changed:
diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp
index 0cde76657c99fd1a861f9034693744d39fac3061..835003e5e621737df23b2c948820b879216611b9 100644 (file)
--- a/src/dialogs/export.cpp
+++ b/src/dialogs/export.cpp
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) {
index e6ce40bc0f517e948d3a5772a1ef940c01b4a0cb..5f1bef8d1afe1013e6189b00df72a2114818aea2 100644 (file)
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;
}
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);
}
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<std::string> params;
module->paramListString(params);
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;
}
index 689c1286f6e96155694f7b13c3868f075e6c976b..b4599dbd06e67b64dd611ade8275d0980854054c 100644 (file)
--- a/src/extension/input.cpp
+++ b/src/extension/input.cpp
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)
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;
}
index d7e0eebf3794515a9a07e94b8143219f8ecfb401..2251ac7b6edbcec53ddcea10546f0724a13477ce 100644 (file)
--- a/src/extension/system.cpp
+++ b/src/extension/system.cpp
#include <interface.h>
+#include "system.h"
+#include "preferences.h"
#include "extension.h"
#include "db.h"
#include "input.h"
* 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) {
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. */
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()) {
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);
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);
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 6c23b2f0dde073affcd553e0ff816a4df729ba08..b6740e10978900ffcf9eb02a15c17cf2281f24d9 100644 (file)
--- a/src/extension/system.h
+++ b/src/extension/system.h
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 f16d87cbd82313873a2dff960259a326db81d12e..03fb7bd5937f1bcd1ef7202a7e4165b2dce460ed 100644 (file)
--- a/src/file.cpp
+++ b/src/file.cpp
#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"
*/
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);
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();
/**
* 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::Output *>
+ (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::Output *>
- (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
dialog_title,
default_extension,
doc_title ? doc_title : "",
- is_copy
+ save_method
);
saveDialog->setSelectionType(extension);
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;
}
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);
}
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);
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 ce75a61a7cfff5f0a689bd0574a343a1b1837d2d..9913fbe1aa4a00d1b564846b00361f6732b8ea04 100644 (file)
--- a/src/file.h
+++ b/src/file.h
#include <gtk/gtkwidget.h>
#include "extension/extension-forward.h"
+#include "extension/system.h"
struct SPDesktop;
struct SPDocument;
}
}
+
/*######################
## 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);
/*######################
index b1385195f4c3f38e91cc37e280b72624c6a76639..8e372c394c555781e21d7965ce0eb9b4ccf140f8 100644 (file)
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;
}
index 6eab75a5b41fa027d5d1e091b164f2aafdb769b5..f7be86ef3da5152d8e9e8ded0f7eb361fae0f53c 100644 (file)
#include <set>
#include <gtkmm.h>
+#include "extension/system.h"
+
+class SPDocument;
+
namespace Inkscape {
namespace Extension {
class Extension;
const char *title,
const Glib::ustring &default_key,
const gchar *docTitle,
- const bool save_copy);
+ const Inkscape::Extension::FileSaveMethod save_method);
/**
index 53faa075ab9100ae72da6c0ab92c7387e2d7b705..3e681bd3be00ea6285a4670bd35eaccb756519cd 100644 (file)
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;
//###### 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));
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 );
index 2a37aed2b62e37ae9a36bdb8c7b34053cd3228cb..ac868fecc84cb9ca843bd3ce78a10ac972f38ac8 100644 (file)
#define __FILE_DIALOGIMPL_H__
#include "filedialog.h"
+#include "extension/system.h"
//General includes
#include <unistd.h>
const Glib::ustring &title,
const Glib::ustring &default_key,
const gchar* docTitle,
- const bool save_copy);
+ const Inkscape::Extension::FileSaveMethod save_method);
virtual ~FileSaveDialogImplGtk();
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
index c703d3c759ae6dd4b7f465c8ea8eae0651a323e2..690c7400490c8de6fb58b741ac08d3ba4b96259d 100644 (file)
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)
{
index f74d9fccf6c0809eadd6b243e670f75cb0764702..1f4a417f252dad1f762f2a7411f588bd53476770 100644 (file)
const char *title,
const Glib::ustring &default_key,
const char *docTitle,
- const bool save_copy);
+ const FileSaveMethod save_method);
/// Destructor
virtual ~FileSaveDialogImplWin32();
index 756f4df73a72f0f6d651a5296e97ca0982a627c0..1d319f97ff7e64c60971c875cf770ca287ffea42 100644 (file)
_("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\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,
index a2f88c16d184ae07597f58a706d2744199e1d980..6d9a61329b31e46a734f33d6a2895802c1d5306a 100644 (file)
_("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\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);
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);