From 4527f6c136612e318804db902fa46d53238c7648 Mon Sep 17 00:00:00 2001 From: mental Date: Fri, 7 Mar 2008 22:18:56 +0000 Subject: [PATCH] add basic support for preserving processing instructions in the AST --- src/dialogs/xml-tree.cpp | 4 +- src/jabber_whiteboard/inkboard-document.cpp | 8 ++++ src/jabber_whiteboard/inkboard-document.h | 1 + src/widgets/sp-xmlview-tree.cpp | 25 ++++++++++ src/xml/Makefile_insert | 1 + src/xml/document.h | 1 + src/xml/node.h | 3 +- src/xml/pi-node.h | 52 +++++++++++++++++++++ src/xml/repr-io.cpp | 13 ++++-- src/xml/simple-document.cpp | 5 ++ src/xml/simple-document.h | 1 + 11 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 src/xml/pi-node.h diff --git a/src/dialogs/xml-tree.cpp b/src/dialogs/xml-tree.cpp index 6da0096e2..a9db979d6 100644 --- a/src/dialogs/xml-tree.cpp +++ b/src/dialogs/xml-tree.cpp @@ -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)); diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index 9f3d8ce42..36295dd28 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -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, diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index 26d79396e..23ce9f3b9 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -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 diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp index ee5ca1823..b2d1a2531 100644 --- a/src/widgets/sp-xmlview-tree.cpp +++ b/src/widgets/sp-xmlview-tree.cpp @@ -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 ("", 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) { diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert index 0a95a2062..ac7b03751 100644 --- a/src/xml/Makefile_insert +++ b/src/xml/Makefile_insert @@ -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 \ diff --git a/src/xml/document.h b/src/xml/document.h index de9164aa2..5065092d0 100644 --- a/src/xml/document.h +++ b/src/xml/document.h @@ -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; }; } diff --git a/src/xml/node.h b/src/xml/node.h index 997f3ccda..ab7e2ba2f 100644 --- a/src/xml/node.h +++ b/src/xml/node.h @@ -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 index 000000000..c3f84b636 --- /dev/null +++ b/src/xml/pi-node.h @@ -0,0 +1,52 @@ +/* + * Inkscape::XML::PINode - simple XML comment implementation + * + * Copyright 2004-2005 MenTaLguY + * + * 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 +#include "xml/simple-node.h" + +namespace Inkscape { + +namespace XML { + +struct PINode : public SimpleNode { + explicit PINode(GQuark target, Util::ptr_shared 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 : diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 28e7c4f21..26537d750 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -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( "", repr->content() ); + } else if (repr->type() == Inkscape::XML::PI_NODE) { + out.printf( "", 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 { diff --git a/src/xml/simple-document.cpp b/src/xml/simple-document.cpp index 30e74a455..d0aa31939 100644 --- a/src/xml/simple-document.cpp +++ b/src/xml/simple-document.cpp @@ -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) diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h index 17e283f2a..cadda36cb 100644 --- a/src/xml/simple-document.h +++ b/src/xml/simple-document.h @@ -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); -- 2.30.2