summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2009-08-09 14:23:52 +0000
committercilix42 <cilix42@users.sourceforge.net>2009-08-09 14:23:52 +0000
commit606ebb35498c3d750bb2906954195baaa0fbcad6 (patch)
treea4b40cd970efc83525392a6a8164e2e6789029b8 /src/extension
parentAdding a Tinfoil bump, removing NR from Non realistic shaders names (diff)
downloadinkscape-606ebb35498c3d750bb2906954195baaa0fbcad6.tar.gz
inkscape-606ebb35498c3d750bb2906954195baaa0fbcad6.zip
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)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/implementation/script.cpp13
-rw-r--r--src/extension/input.cpp13
-rw-r--r--src/extension/system.cpp102
-rw-r--r--src/extension/system.h53
4 files changed, 154 insertions, 27 deletions
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<std::string> 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 <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 */
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__ */