summaryrefslogtreecommitdiffstats
path: root/src/xml/simple-document.cpp
blob: bae28e4b4d9525fa6674d7726426912c39764e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * @file
 * Garbage collected XML document 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.
 *
 */

#include <glib.h> // g_assert()

#include "xml/simple-document.h"
#include "xml/event-fns.h"
#include "xml/element-node.h"
#include "xml/text-node.h"
#include "xml/comment-node.h"
#include "xml/pi-node.h"

namespace Inkscape {

namespace XML {

void SimpleDocument::beginTransaction() {
    g_assert(!_in_transaction);
    _in_transaction = true;
}

void SimpleDocument::rollback() {
    g_assert(_in_transaction);
    _in_transaction = false;
    Event *log = _log_builder.detach();
    sp_repr_undo_log(log);
    sp_repr_free_log(log);
}

void SimpleDocument::commit() {
    g_assert(_in_transaction);
    _in_transaction = false;
    _log_builder.discard();
}

Inkscape::XML::Event *SimpleDocument::commitUndoable() {
    g_assert(_in_transaction);
    _in_transaction = false;
    return _log_builder.detach();
}

Node *SimpleDocument::createElement(char const *name) {
    return new ElementNode(g_quark_from_string(name), this);
}

Node *SimpleDocument::createTextNode(char const *content) {
    return new TextNode(Util::share_string(content), this);
}

Node *SimpleDocument::createTextNode(char const *content, bool const is_CData) {
    return new TextNode(Util::share_string(content), this, is_CData);
}

Node *SimpleDocument::createComment(char const *content) {
    return new CommentNode(Util::share_string(content), this);
}

Node *SimpleDocument::createPI(char const *target, char const *content) {
    return new PINode(g_quark_from_string(target), Util::share_string(content), this);
}

void SimpleDocument::notifyChildAdded(Node &parent,
                                      Node &child,
                                      Node *prev)
{
    if (_in_transaction) {
        _log_builder.addChild(parent, child, prev);
    }
}

void SimpleDocument::notifyChildRemoved(Node &parent,
                                        Node &child,
                                        Node *prev)
{
    if (_in_transaction) {
        _log_builder.removeChild(parent, child, prev);
    }
}

void SimpleDocument::notifyChildOrderChanged(Node &parent,
                                             Node &child,
                                             Node *old_prev,
                                             Node *new_prev)
{
    if (_in_transaction) {
        _log_builder.setChildOrder(parent, child, old_prev, new_prev);
    }
}

void SimpleDocument::notifyContentChanged(Node &node,
                                          Util::ptr_shared<char> old_content,
                                          Util::ptr_shared<char> new_content)
{
    if (_in_transaction) {
        _log_builder.setContent(node, old_content, new_content);
    }
}

void SimpleDocument::notifyAttributeChanged(Node &node,
                                            GQuark name,
                                            Util::ptr_shared<char> old_value,
                                            Util::ptr_shared<char> new_value)
{
    if (_in_transaction) {
        _log_builder.setAttribute(node, name, old_value, new_value);
    }
}

}

}

/*
  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:fileencoding=utf-8:textwidth=99 :