Code

BUG 218090 opening of bitmap fails, now error message
[inkscape.git] / src / extension / system.cpp
index cd70042b6e758d2918956fe0fa2268817a95927c..a7828d3fc115e0bcb291b6e2fea29603c46b68d7 100644 (file)
@@ -8,7 +8,7 @@
  *   Ted Gould <ted@gould.cx>
  *   Johan Engelen <johan@shouraizou.nl>
  *
- * Copyright (C) 2006-2007 Johan Engelen 
+ * Copyright (C) 2006-2007 Johan Engelen
  * Copyright (C) 2002-2004 Ted Gould
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
@@ -29,6 +29,7 @@
 #include "print.h"
 #include "implementation/script.h"
 #include "implementation/xslt.h"
+#include "xml/rebase-hrefs.h"
 /* #include "implementation/plugin.h" */
 
 namespace Inkscape {
@@ -92,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."));
@@ -218,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) {
@@ -249,52 +251,49 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
     bool saved_modified = false;
     gchar *saved_output_extension = NULL;
     gchar *saved_dataloss = NULL;
-    gchar *saved_uri = NULL;
     if (!official) {
         saved_modified = doc->isModifiedSinceSave();
-        if (repr->attribute("inkscape:output_extension")) {
-            saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension"));
-        }
-        if (repr->attribute("inkscape:dataloss")) {
-            saved_dataloss = g_strdup(repr->attribute("inkscape:dataloss"));
-        }
-        if (doc->uri) {
-            saved_uri = g_strdup(doc->uri);    
-        }
-    }    
-
-    // update attributes:
-    bool saved = sp_document_get_undo_sensitive(doc);
-    sp_document_set_undo_sensitive (doc, false); 
-        // save the filename for next use
-        sp_document_set_uri(doc, fileName);
-        // 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");
+        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);
+        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 it is an unofficial save, set the modified attributes back to what they were.
     if ( !official) {
-        saved = sp_document_get_undo_sensitive(doc);
-        sp_document_set_undo_sensitive (doc, false);
+        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_uri(doc, saved_uri);
-        sp_document_set_undo_sensitive (doc, saved);
+        }
+        sp_document_set_undo_sensitive(doc, saved);
         doc->setModifiedSinceSave(saved_modified);
+
+        g_free(saved_output_extension);
+        g_free(saved_dataloss);
     }
-    
-    if (saved_output_extension)  g_free(saved_output_extension);
-    if (saved_dataloss)          g_free(saved_dataloss);
-    if (saved_uri)               g_free(saved_uri);    
-    
+
     g_free(fileName);
     return;
 }
@@ -389,8 +388,6 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation
 
     Inkscape::XML::Node *repr = doc->root();
 
-    /* sp_repr_print(repr); */
-
     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;