Code

r19136@shi: ted | 2008-04-24 19:44:01 -0700
[inkscape.git] / src / extension / system.cpp
index 3eb9cf809d5a699a434b2806e7b21d2bb6dd6f52..cd70042b6e758d2918956fe0fa2268817a95927c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <interface.h>
 
+#include "extension.h"
 #include "db.h"
 #include "input.h"
 #include "output.h"
@@ -104,11 +105,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);
-    bool 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);
 
@@ -249,14 +246,12 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
 
     // remember attributes in case this is an unofficial save
-    gchar *saved_sodipodi_modified = NULL;
+    bool saved_modified = false;
     gchar *saved_output_extension = NULL;
     gchar *saved_dataloss = NULL;
     gchar *saved_uri = NULL;
     if (!official) {
-        if (repr->attribute("sodipodi:modified")) {
-            saved_sodipodi_modified = g_strdup(repr->attribute("sodipodi:modified"));
-        }
+        saved_modified = doc->isModifiedSinceSave();
         if (repr->attribute("inkscape:output_extension")) {
             saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension"));
         }
@@ -271,7 +266,6 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
     // update attributes:
     bool saved = sp_document_get_undo_sensitive(doc);
     sp_document_set_undo_sensitive (doc, false); 
-        repr->setAttribute("sodipodi:modified", NULL); 
         // save the filename for next use
         sp_document_set_uri(doc, fileName);
         // also save the extension for next use
@@ -282,6 +276,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
             repr->setAttribute("inkscape:dataloss", "true");
         }
     sp_document_set_undo_sensitive (doc, saved);
+    doc->setModifiedSinceSave(false);
 
     omod->save(doc, fileName);
     
@@ -289,14 +284,13 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
     if ( !official) {
         saved = sp_document_get_undo_sensitive(doc);
         sp_document_set_undo_sensitive (doc, false);
-            repr->setAttribute("sodipodi:modified", saved_sodipodi_modified);
             repr->setAttribute("inkscape:output_extension", saved_output_extension);
             repr->setAttribute("inkscape:dataloss", saved_dataloss);
             sp_document_set_uri(doc, saved_uri);
         sp_document_set_undo_sensitive (doc, saved);
+        doc->setModifiedSinceSave(saved_modified);
     }
     
-    if (saved_sodipodi_modified) g_free(saved_sodipodi_modified);
     if (saved_output_extension)  g_free(saved_output_extension);
     if (saved_dataloss)          g_free(saved_dataloss);
     if (saved_uri)               g_free(saved_uri);    
@@ -393,12 +387,12 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation
 
     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 <inkscape-extension>.  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;
     }
 
@@ -406,19 +400,19 @@ 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, "path-effect")) {
+        } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "path-effect")) {
             module_functional_type = MODULE_PATH_EFFECT;
-        } else if (!strcmp(element_name, "script")) {
+        } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "script")) {
             module_implementation_type = MODULE_EXTENSION;
-        } else if (!strcmp(element_name, "xslt")) {
+        } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "xslt")) {
             module_implementation_type = MODULE_XSLT;
 #if 0
         } else if (!strcmp(element_name, "plugin")) {
@@ -501,9 +495,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);
@@ -524,7 +516,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;