Code

add basic support for preserving processing instructions in the AST
authormental <mental@users.sourceforge.net>
Fri, 7 Mar 2008 22:18:56 +0000 (22:18 +0000)
committermental <mental@users.sourceforge.net>
Fri, 7 Mar 2008 22:18:56 +0000 (22:18 +0000)
src/dialogs/xml-tree.cpp
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/inkboard-document.h
src/widgets/sp-xmlview-tree.cpp
src/xml/Makefile_insert
src/xml/document.h
src/xml/node.h
src/xml/pi-node.h [new file with mode: 0644]
src/xml/repr-io.cpp
src/xml/simple-document.cpp
src/xml/simple-document.h

index 6da0096e206346eed254a0580e4ad90fe77e94b8..a9db979d64460a622cedc145844b60faf83971bc 100644 (file)
@@ -772,7 +772,7 @@ void propagate_tree_select(Inkscape::XML::Node *repr)
         sp_xmlview_attr_list_set_repr(attributes, NULL);
     }
 
-    if (repr && ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE ) ) {
+    if (repr && ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE || repr->type() == Inkscape::XML::PI_NODE ) ) {
         sp_xmlview_content_set_repr(content, repr);
     } else {
         sp_xmlview_content_set_repr(content, NULL);
@@ -986,7 +986,7 @@ void on_tree_select_row_show_if_text(GtkCTree *tree, GtkCTreeNode *node,
 {
     Inkscape::XML::Node *repr = sp_xmlview_tree_node_get_repr(SP_XMLVIEW_TREE(tree), node);
 
-    if ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE ) {
+    if ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE || repr->type() == Inkscape::XML::PI_NODE ) {
         gtk_widget_show(GTK_WIDGET(data));
     } else {
         gtk_widget_hide(GTK_WIDGET(data));
index 9f3d8ce4293dac6fb59862965dec2df0ad85de0a..36295dd28d485ab15d8a6f3a4d6359bdf7ae5742 100644 (file)
@@ -33,6 +33,7 @@
 #include "xml/element-node.h"
 #include "xml/text-node.h"
 #include "xml/comment-node.h"
+#include "xml/pi-node.h"
 
 #include "util/share.h"
 #include "util/ucompose.hpp"
@@ -362,6 +363,13 @@ InkboardDocument::createComment(char const* content)
     return new XML::CommentNode(Util::share_string(content));
 }
 
+XML::Node*
+InkboardDocument::createPI(char const *target, char const* content)
+{
+    return new XML::PINode(g_quark_from_string(target), Util::share_string(content));
+}
+
+
 
 void InkboardDocument::notifyChildAdded(XML::Node &parent,
                                         XML::Node &child,
index 26d79396ed844bbb1d867727afbe977809604c79..23ce9f3b9ab54520240c54809d5c16844e0e2cda 100644 (file)
@@ -84,6 +84,7 @@ public:
     XML::Node* createElement(char const* name);
     XML::Node* createTextNode(char const* content);
     XML::Node* createComment(char const* content);
+    XML::Node* createPI(char const *target, char const* content);
 
     //
     // XML::NodeObserver methods
index ee5ca182377334f538de30e76f905357c7735ee1..b2d1a2531515f608518709dc9e980a0a744caa76 100644 (file)
@@ -41,6 +41,7 @@ static void element_order_changed (Inkscape::XML::Node * repr, Inkscape::XML::No
 
 static void text_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
 static void comment_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
+static void pi_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
 
 static void tree_move (GtkCTree * tree, GtkCTreeNode * node, GtkCTreeNode * new_parent, GtkCTreeNode * new_sibling);
 
@@ -76,6 +77,14 @@ static const Inkscape::XML::NodeEventVector comment_repr_events = {
         NULL  /* order_changed */
 };
 
+static const Inkscape::XML::NodeEventVector pi_repr_events = {
+        NULL, /* child_added */
+        NULL, /* child_removed */
+        NULL, /* attr_changed */
+        pi_content_changed,
+        NULL  /* order_changed */
+};
+
 static GtkCTreeClass * parent_class = NULL;
 
 GtkWidget *
@@ -191,6 +200,8 @@ add_node (SPXMLViewTree * tree, GtkCTreeNode * parent, GtkCTreeNode * before, In
                vec = &text_repr_events;
        } else if ( repr->type() == Inkscape::XML::COMMENT_NODE ) {
                vec = &comment_repr_events;
+       } else if ( repr->type() == Inkscape::XML::PI_NODE ) {
+               vec = &pi_repr_events;
        } else if ( repr->type() == Inkscape::XML::ELEMENT_NODE ) {
                vec = &element_repr_events;
        } else {
@@ -329,6 +340,20 @@ comment_content_changed (Inkscape::XML::Node *repr, const gchar * old_content, c
        g_free (label);
 }
 
+void
+pi_content_changed(Inkscape::XML::Node *repr, const gchar * old_content, const gchar *new_content, gpointer ptr)
+{
+       NodeData *data;
+       gchar *label;
+
+       data = (NodeData *) ptr;
+
+       if (data->tree->blocked) return;
+
+       label = g_strdup_printf ("<?%s %s?>", repr->name(), new_content);
+       gtk_ctree_node_set_text (GTK_CTREE (data->tree), data->node, 0, label);
+       g_free (label);
+}
 void
 tree_move (GtkCTree * tree, GtkCTreeNode * node, GtkCTreeNode * new_parent, GtkCTreeNode * new_sibling)
 {
index 0a95a206223b0f352d7d664300efec2e748070aa..ac7b03751a9b7a175b70339d046e6ea79dda24e9 100644 (file)
@@ -26,6 +26,7 @@ xml_libspxml_a_SOURCES =      \
        xml/log-builder.h       \
        xml/node-fns.cpp        \
        xml/node-fns.h  \
+       xml/pi-node.h   \
        xml/repr-io.cpp \
        xml/repr-sorting.cpp    \
        xml/repr-sorting.h      \
index de9164aa2a738dd505513397866d6bf64771b646..5065092d0ab6efea163326033bf38141516b7ae6 100644 (file)
@@ -37,6 +37,7 @@ public:
     virtual Node *createElement(char const *name)=0;
     virtual Node *createTextNode(char const *content)=0;
     virtual Node *createComment(char const *content)=0;
+    virtual Node *createPI(char const *target, char const *content)=0;
 };
 
 }
index 997f3ccda563d80029282e11ce023c4a19ca319d..ab7e2ba2f97ed34e40eb8d005ac1ae80a0da5235 100644 (file)
@@ -31,7 +31,8 @@ enum NodeType {
     DOCUMENT_NODE,
     ELEMENT_NODE,
     TEXT_NODE,
-    COMMENT_NODE
+    COMMENT_NODE,
+    PI_NODE
 };
 
 // careful; GC::Anchored should only appear once in the inheritance
diff --git a/src/xml/pi-node.h b/src/xml/pi-node.h
new file mode 100644 (file)
index 0000000..c3f84b6
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Inkscape::XML::PINode - simple XML comment implementation
+ *
+ * Copyright 2004-2005 MenTaLguY <mental@rydia.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * See the file COPYING for details.
+ *
+ */
+
+#ifndef SEEN_INKSCAPE_XML_PI_NODE_H
+#define SEEN_INKSCAPE_XML_PI_NODE_H
+
+#include <glib/gquark.h>
+#include "xml/simple-node.h"
+
+namespace Inkscape {
+
+namespace XML {
+
+struct PINode : public SimpleNode {
+    explicit PINode(GQuark target, Util::ptr_shared<char> content)
+    : SimpleNode(target)
+    {
+        setContent(content);
+    }
+
+    Inkscape::XML::NodeType type() const { return Inkscape::XML::PI_NODE; }
+
+protected:
+    SimpleNode *_duplicate(Document* doc) const { return new PINode(*this); }
+};
+
+}
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index 28e7c4f21ef6d7f48aa4ef6452fb89c6c38b1f0c..26537d750764a17031f7ceb84480a624f19bb95d 100644 (file)
@@ -395,10 +395,10 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns)
                 root = NULL;
                 break;
             }
-        } else if ( node->type == XML_COMMENT_NODE ) {
-            Node *comment=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
-            rdoc->appendChild(comment);
-            Inkscape::GC::release(comment);
+        } else if ( node->type == XML_COMMENT_NODE || node->type == XML_PI_NODE ) {
+            Node *repr=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+            rdoc->appendChild(repr);
+            Inkscape::GC::release(repr);
         }
     }
 
@@ -463,6 +463,9 @@ sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_
     if (node->type == XML_COMMENT_NODE)
         return xml_doc->createComment((const gchar *)node->content);
 
+    if (node->type == XML_PI_NODE)
+        return xml_doc->createPI((const gchar *)node->name, (const gchar *)node->content);
+
     if (node->type == XML_ENTITY_DECL) return NULL;
 
     sp_repr_qualified_name (c, 256, node->ns, node->name, default_ns, prefix_map);
@@ -717,6 +720,8 @@ sp_repr_write_stream (Node *repr, Writer &out, gint indent_level,
         repr_quote_write (out, repr->content());
     } else if (repr->type() == Inkscape::XML::COMMENT_NODE) {
         out.printf( "<!--%s-->", repr->content() );
+    } else if (repr->type() == Inkscape::XML::PI_NODE) {
+        out.printf( "<?%s %s?>", repr->name(), repr->content() );
     } else if (repr->type() == Inkscape::XML::ELEMENT_NODE) {
         sp_repr_write_stream_element(repr, out, indent_level, add_whitespace, elide_prefix, repr->attributeList(), inlineattrs, indent);
     } else {
index 30e74a4554dca54b2e49bfbca9e6d20cada5ff50..d0aa319390f09661bbf8ab1bc09f94afafb37dcb 100644 (file)
@@ -19,6 +19,7 @@
 #include "xml/element-node.h"
 #include "xml/text-node.h"
 #include "xml/comment-node.h"
+#include "xml/pi-node.h"
 
 namespace Inkscape {
 
@@ -65,6 +66,10 @@ Node *SimpleDocument::createComment(char const *content) {
     return new CommentNode(Util::share_string(content));
 }
 
+Node *SimpleDocument::createPI(char const *target, char const *content) {
+    return new PINode(g_quark_from_string(target), Util::share_string(content));
+}
+
 void SimpleDocument::notifyChildAdded(Node &parent,
                                       Node &child,
                                       Node *prev)
index 17e283f2a4ed0b5571770e3e363e32bba65522d7..cadda36cbf24634c47e83a62d6667ad6d634afa8 100644 (file)
@@ -49,6 +49,7 @@ public:
     Node *createElement(char const *name);
     Node *createTextNode(char const *content);
     Node *createComment(char const *content);
+    Node *createPI(char const *target, char const *content);
 
     void notifyChildAdded(Node &parent, Node &child, Node *prev);