X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Fsystem.cpp;h=a7828d3fc115e0bcb291b6e2fea29603c46b68d7;hb=8ebe4cd501af68581f40982b54f463546c59943a;hp=ccf168446d2eaf811ad677a85c87e9934ba384a9;hpb=97153383e812cc9c0a0d87f944295edec69915d4;p=inkscape.git diff --git a/src/extension/system.cpp b/src/extension/system.cpp index ccf168446..a7828d3fc 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -6,8 +6,10 @@ * * Authors: * Ted Gould + * Johan Engelen * - * Copyright (C) 2002-2004 Authors + * Copyright (C) 2006-2007 Johan Engelen + * Copyright (C) 2002-2004 Ted Gould * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -18,12 +20,16 @@ #include +#include "extension.h" #include "db.h" #include "input.h" #include "output.h" #include "effect.h" +#include "patheffect.h" #include "print.h" #include "implementation/script.h" +#include "implementation/xslt.h" +#include "xml/rebase-hrefs.h" /* #include "implementation/plugin.h" */ namespace Inkscape { @@ -87,11 +93,11 @@ open(Extension *key, gchar const *filename) SPDocument *doc = imod->open(filename); if (!doc) { - return NULL; + throw Input::open_failed(); } if (last_chance_svg) { - /* We can't call sp_ui_error_dialog because we may be + /* We can't call sp_ui_error_dialog because we may be running from the console, in which case calling sp_ui routines will cause a segfault. See bug 1000350 - bryce */ // sp_ui_error_dialog(_("Format autodetect failed. The file is being opened as SVG.")); @@ -100,11 +106,7 @@ open(Extension *key, gchar const *filename) /* This kinda overkill as most of these are already set, but I want to make sure for this release -- TJG */ - Inkscape::XML::Node *repr = sp_document_repr_root(doc); - gboolean saved = sp_document_get_undo_sensitive(doc); - sp_document_set_undo_sensitive(doc, FALSE); - repr->setAttribute("sodipodi:modified", NULL); - sp_document_set_undo_sensitive(doc, saved); + doc->setModifiedSinceSave(false); sp_document_set_uri(doc, filename); @@ -217,8 +219,9 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, throw Output::save_failed(); } - if (!omod->prefs()) - return; + if (!omod->prefs()) { + throw Output::save_cancelled(); + } gchar *fileName = NULL; if (setextension) { @@ -242,12 +245,55 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, throw Output::no_overwrite(); } - if (official) { - sp_document_set_uri(doc, fileName); + Inkscape::XML::Node *repr = sp_document_repr_root(doc); + + // remember attributes in case this is an unofficial save + 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 { + /* The document is changing name/uri. */ + sp_document_change_uri_and_hrefs(doc, fileName); + } + + // Update attributes: + { + bool const saved = sp_document_get_undo_sensitive(doc); + sp_document_set_undo_sensitive(doc, false); + { + // also save the extension for next use + repr->setAttribute("inkscape:output_extension", omod->get_id()); + // set the "dataloss" attribute if the chosen extension is lossy + repr->setAttribute("inkscape:dataloss", NULL); + if (omod->causes_dataloss()) { + repr->setAttribute("inkscape:dataloss", "true"); + } + } + sp_document_set_undo_sensitive(doc, saved); + doc->setModifiedSinceSave(false); } omod->save(doc, fileName); + // If it is an unofficial save, set the modified attributes back to what they were. + if ( !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); + doc->setModifiedSinceSave(saved_modified); + + g_free(saved_output_extension); + g_free(saved_dataloss); + } + g_free(fileName); return; } @@ -325,6 +371,7 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation { enum { MODULE_EXTENSION, + MODULE_XSLT, /* MODULE_PLUGIN, */ MODULE_UNKNOWN_IMP } module_implementation_type = MODULE_UNKNOWN_IMP; @@ -333,17 +380,16 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation MODULE_OUTPUT, MODULE_FILTER, MODULE_PRINT, + MODULE_PATH_EFFECT, MODULE_UNKNOWN_FUNC } module_functional_type = MODULE_UNKNOWN_FUNC; g_return_val_if_fail(doc != NULL, NULL); - Inkscape::XML::Node *repr = sp_repr_document_root(doc); + Inkscape::XML::Node *repr = doc->root(); - /* sp_repr_print(repr); */ - - if (strcmp(repr->name(), "inkscape-extension")) { - g_warning("Extension definition started with <%s> instead of . Extension will not be created.\n", repr->name()); + if (strcmp(repr->name(), INKSCAPE_EXTENSION_NS "inkscape-extension")) { + g_warning("Extension definition started with <%s> instead of <" INKSCAPE_EXTENSION_NS "inkscape-extension>. Extension will not be created. See http://wiki.inkscape.org/wiki/index.php/Extensions for reference.\n", repr->name()); return NULL; } @@ -351,16 +397,20 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation while (child_repr != NULL) { char const *element_name = child_repr->name(); /* printf("Child: %s\n", child_repr->name()); */ - if (!strcmp(element_name, "input")) { + if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "input")) { module_functional_type = MODULE_INPUT; - } else if (!strcmp(element_name, "output")) { + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "output")) { module_functional_type = MODULE_OUTPUT; - } else if (!strcmp(element_name, "effect")) { + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "effect")) { module_functional_type = MODULE_FILTER; - } else if (!strcmp(element_name, "print")) { + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "print")) { module_functional_type = MODULE_PRINT; - } else if (!strcmp(element_name, "script")) { + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "path-effect")) { + module_functional_type = MODULE_PATH_EFFECT; + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "script")) { module_implementation_type = MODULE_EXTENSION; + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "xslt")) { + module_implementation_type = MODULE_XSLT; #if 0 } else if (!strcmp(element_name, "plugin")) { module_implementation_type = MODULE_PLUGIN; @@ -380,6 +430,11 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation imp = static_cast(script); break; } + case MODULE_XSLT: { + Implementation::XSLT *xslt = new Implementation::XSLT(); + imp = static_cast(xslt); + break; + } #if 0 case MODULE_PLUGIN: { Implementation::Plugin *plugin = new Implementation::Plugin(); @@ -414,6 +469,10 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation module = new Print(repr, imp); break; } + case MODULE_PATH_EFFECT: { + module = new PathEffect(repr, imp); + break; + } default: { break; } @@ -433,9 +492,7 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation Extension * build_from_file(gchar const *filename) { - /* TODO: Need to define namespace here, need to write the - DTD in general for this stuff */ - Inkscape::XML::Document *doc = sp_repr_read_file(filename, NULL); + Inkscape::XML::Document *doc = sp_repr_read_file(filename, INKSCAPE_EXTENSION_URI); Extension *ext = build_from_reprdoc(doc, NULL); if (ext != NULL) Inkscape::GC::release(doc); @@ -456,7 +513,7 @@ build_from_file(gchar const *filename) Extension * build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp) { - Inkscape::XML::Document *doc = sp_repr_read_mem(buffer, strlen(buffer), NULL); + Inkscape::XML::Document *doc = sp_repr_read_mem(buffer, strlen(buffer), INKSCAPE_EXTENSION_URI); Extension *ext = build_from_reprdoc(doc, in_imp); Inkscape::GC::release(doc); return ext;