1 /*
2 * Inkscape::XML::SimpleSession - simple session/logging implementation
3 *
4 * Copyright 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 "xml/simple-session.h"
16 #include "xml/event-fns.h"
17 #include "xml/element-node.h"
18 #include "xml/text-node.h"
19 #include "xml/comment-node.h"
21 namespace Inkscape {
23 namespace XML {
25 void SimpleSession::beginTransaction() {
26 g_assert(!_in_transaction);
27 _in_transaction = true;
28 }
30 void SimpleSession::rollback() {
31 g_assert(_in_transaction);
32 _in_transaction = false;
33 Event *log = _log_builder.detach();
34 sp_repr_undo_log(log);
35 sp_repr_free_log(log);
36 }
38 void SimpleSession::commit() {
39 g_assert(_in_transaction);
40 _in_transaction = false;
41 _log_builder.discard();
42 }
44 Inkscape::XML::Event *SimpleSession::commitUndoable() {
45 g_assert(_in_transaction);
46 _in_transaction = false;
47 return _log_builder.detach();
48 }
50 Node *SimpleSession::createElementNode(char const *name) {
51 return new ElementNode(g_quark_from_string(name));
52 }
54 Node *SimpleSession::createTextNode(char const *content) {
55 return new TextNode(Util::share_string(content));
56 }
58 Node *SimpleSession::createCommentNode(char const *content) {
59 return new CommentNode(Util::share_string(content));
60 }
62 void SimpleSession::notifyChildAdded(Node &parent,
63 Node &child,
64 Node *prev)
65 {
66 if (_in_transaction) {
67 _log_builder.addChild(parent, child, prev);
68 }
69 }
71 void SimpleSession::notifyChildRemoved(Node &parent,
72 Node &child,
73 Node *prev)
74 {
75 if (_in_transaction) {
76 _log_builder.removeChild(parent, child, prev);
77 }
78 }
80 void SimpleSession::notifyChildOrderChanged(Node &parent,
81 Node &child,
82 Node *old_prev,
83 Node *new_prev)
84 {
85 if (_in_transaction) {
86 _log_builder.setChildOrder(parent, child, old_prev, new_prev);
87 }
88 }
90 void SimpleSession::notifyContentChanged(Node &node,
91 Util::ptr_shared<char> old_content,
92 Util::ptr_shared<char> new_content)
93 {
94 if (_in_transaction) {
95 _log_builder.setContent(node, old_content, new_content);
96 }
97 }
99 void SimpleSession::notifyAttributeChanged(Node &node,
100 GQuark name,
101 Util::ptr_shared<char> old_value,
102 Util::ptr_shared<char> new_value)
103 {
104 if (_in_transaction) {
105 _log_builder.setAttribute(node, name, old_value, new_value);
106 }
107 }
109 }
111 }
113 /*
114 Local Variables:
115 mode:c++
116 c-file-style:"stroustrup"
117 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
118 indent-tabs-mode:nil
119 fill-column:99
120 End:
121 */
122 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :