Code

Patch from Hannes Hochreiner to make it so that attributes on the root node copy...
authorTed Gould <ted@canonical.com>
Fri, 31 Oct 2008 15:13:48 +0000 (10:13 -0500)
committerTed Gould <ted@canonical.com>
Fri, 31 Oct 2008 15:13:48 +0000 (10:13 -0500)
src/extension/implementation/script.cpp

index fc94205b64007c70d4061f0345b4c8820f24a2f3..964eb85d87d9b46a73fe7c9108885c1b863de449 100644 (file)
@@ -37,6 +37,7 @@
 #include "script.h"
 #include "dialogs/dialog-events.h"
 #include "application/application.h"
+#include "xml/node.h"
 
 #include "util/glib-list-iterators.h"
 
@@ -834,8 +835,26 @@ Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot)
         }
     }
 
-    oldroot->setAttribute("width", newroot->attribute("width"));
-    oldroot->setAttribute("height", newroot->attribute("height"));
+    {
+        using Inkscape::Util::List;
+        using Inkscape::XML::AttributeRecord;        
+        std::vector<gchar const *> attribs;
+
+        // Make a list of all attributes of the old root node.
+        for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) {
+            attribs.push_back(g_quark_to_string(iter->key));
+        }
+
+        // Delete the attributes of the old root nodes.
+        for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); it++)
+            oldroot->setAttribute(*it, NULL);
+
+        // Set the new attributes.
+        for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) {
+            gchar const *name = g_quark_to_string(iter->key);
+            oldroot->setAttribute(name, newroot->attribute(name));
+        }
+    }
 
     /** \todo  Restore correct layer */
     /** \todo  Restore correct selection */