1 /*
2 * Inkscape::XML::SimpleDocument - generic XML document implementation
3 *
4 * Copyright 2004-2005 MenTaLguY <mental@rydia.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #include <glib/gtestutils.h>
17 #include "xml/simple-document.h"
18 #include "xml/event-fns.h"
19 #include "xml/element-node.h"
20 #include "xml/text-node.h"
21 #include "xml/comment-node.h"
23 namespace Inkscape {
25 namespace XML {
27 void SimpleDocument::_initBindings() {
28 _bindDocument(*this);
29 }
31 void SimpleDocument::beginTransaction() {
32 g_assert(!_in_transaction);
33 _in_transaction = true;
34 }
36 void SimpleDocument::rollback() {
37 g_assert(_in_transaction);
38 _in_transaction = false;
39 Event *log = _log_builder.detach();
40 sp_repr_undo_log(log);
41 sp_repr_free_log(log);
42 }
44 void SimpleDocument::commit() {
45 g_assert(_in_transaction);
46 _in_transaction = false;
47 _log_builder.discard();
48 }
50 Inkscape::XML::Event *SimpleDocument::commitUndoable() {
51 g_assert(_in_transaction);
52 _in_transaction = false;
53 return _log_builder.detach();
54 }
56 Node *SimpleDocument::createElement(char const *name) {
57 return new ElementNode(g_quark_from_string(name));
58 }
60 Node *SimpleDocument::createTextNode(char const *content) {
61 return new TextNode(Util::share_string(content));
62 }
64 Node *SimpleDocument::createComment(char const *content) {
65 return new CommentNode(Util::share_string(content));
66 }
68 void SimpleDocument::notifyChildAdded(Node &parent,
69 Node &child,
70 Node *prev)
71 {
72 if (_in_transaction) {
73 _log_builder.addChild(parent, child, prev);
74 }
75 }
77 void SimpleDocument::notifyChildRemoved(Node &parent,
78 Node &child,
79 Node *prev)
80 {
81 if (_in_transaction) {
82 _log_builder.removeChild(parent, child, prev);
83 }
84 }
86 void SimpleDocument::notifyChildOrderChanged(Node &parent,
87 Node &child,
88 Node *old_prev,
89 Node *new_prev)
90 {
91 if (_in_transaction) {
92 _log_builder.setChildOrder(parent, child, old_prev, new_prev);
93 }
94 }
96 void SimpleDocument::notifyContentChanged(Node &node,
97 Util::ptr_shared<char> old_content,
98 Util::ptr_shared<char> new_content)
99 {
100 if (_in_transaction) {
101 _log_builder.setContent(node, old_content, new_content);
102 }
103 }
105 void SimpleDocument::notifyAttributeChanged(Node &node,
106 GQuark name,
107 Util::ptr_shared<char> old_value,
108 Util::ptr_shared<char> new_value)
109 {
110 if (_in_transaction) {
111 _log_builder.setAttribute(node, name, old_value, new_value);
112 }
113 }
115 }
117 }
119 /*
120 Local Variables:
121 mode:c++
122 c-file-style:"stroustrup"
123 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
124 indent-tabs-mode:nil
125 fill-column:99
126 End:
127 */
128 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :