Code

merge XML::Session into XML::Document
authormental <mental@users.sourceforge.net>
Sat, 20 Jan 2007 05:49:10 +0000 (05:49 +0000)
committermental <mental@users.sourceforge.net>
Sat, 20 Jan 2007 05:49:10 +0000 (05:49 +0000)
18 files changed:
src/jabber_whiteboard/Makefile_insert
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/inkboard-document.h
src/jabber_whiteboard/inkboard-session.cpp [deleted file]
src/jabber_whiteboard/inkboard-session.h [deleted file]
src/jabber_whiteboard/session-manager.h
src/xml/Makefile_insert
src/xml/document.h
src/xml/event.cpp
src/xml/node.h
src/xml/session.h [deleted file]
src/xml/simple-document.cpp
src/xml/simple-document.h
src/xml/simple-node.cpp
src/xml/simple-node.h
src/xml/simple-session.cpp [deleted file]
src/xml/simple-session.h [deleted file]
src/xml/transaction-logger.h [deleted file]

index e529a196a1a7d1f7ef0d83ed15b9562c4208b117..a638377e8b9cb0ba2415356e8d69f9fb70a55242 100644 (file)
@@ -26,8 +26,6 @@ jabber_whiteboard_SOURCES = \
        jabber_whiteboard/node-utilities.h \
        jabber_whiteboard/node-tracker.h \
        jabber_whiteboard/inkboard-node.cpp \
-       jabber_whiteboard/inkboard-session.cpp \
-       jabber_whiteboard/inkboard-session.h \
        jabber_whiteboard/inkboard-document.cpp \
        jabber_whiteboard/inkboard-document.h \
        jabber_whiteboard/invitation-confirm-dialog.cpp \
index a8b3567da2a170e2fe72ca9391ac51d018ee1fc1..c2178b78d2adf38fc29c7288eff466a14acfe2af 100644 (file)
 
 #include "util/ucompose.hpp"
 
-#include "xml/simple-session.h"
-#include "jabber_whiteboard/inkboard-session.h"
 #include "jabber_whiteboard/message-utilities.h"
 #include "jabber_whiteboard/defines.h"
 #include "jabber_whiteboard/session-manager.h"
 #include "jabber_whiteboard/node-tracker.h"
 
+#include <glibmm.h>
+#include <glib/gmessages.h>
+#include <glib/gquark.h>
+
+#include "jabber_whiteboard/inkboard-document.h"
+#include "jabber_whiteboard/defines.h"
+
+#include "xml/node.h"
+#include "xml/event.h"
+#include "xml/element-node.h"
+#include "xml/text-node.h"
+#include "xml/comment-node.h"
+
+#include "util/share.h"
+#include "util/ucompose.hpp"
+
 namespace Inkscape {
 
 namespace Whiteboard {
 
-InkboardDocument::InkboardDocument(int code, State::SessionType sessionType, Glib::ustring const& to) :
-       XML::SimpleNode(code), sessionType(sessionType), recipient(to)
+InkboardDocument::InkboardDocument(int code, State::SessionType sessionType,
+                                   Glib::ustring const& to)
+: XML::SimpleNode(code), sessionType(sessionType), recipient(to),
+  _in_transaction(false)
 {
     _initBindings();
 }
@@ -40,7 +56,6 @@ InkboardDocument::_initBindings()
     this->state = State::INITIAL;
     this->tracker = new KeyNodeTable();
     _bindDocument(*this);
-    _bindLogger(*(new InkboardSession(this)));
 }
 
 void
@@ -300,17 +315,162 @@ InkboardDocument::handleChange(Message::Wrapper &wrapper, Pedro::Element* data)
     }
 }
 
-} // namespace Whiteboard
-} // namespace Inkscape
+void
+InkboardDocument::beginTransaction()
+{
+    g_assert(!_in_transaction);
+    _in_transaction = true;
+}
+
+void
+InkboardDocument::rollback()
+{
+    g_assert(_in_transaction);
+    _in_transaction = false;
+}
+
+void 
+InkboardDocument::commit()
+{
+    g_assert(_in_transaction);
+    _in_transaction = false;
+}
+
+XML::Event*
+InkboardDocument::commitUndoable()
+{
+    g_assert(_in_transaction);
+    _in_transaction = false;
+    return NULL;
+}
+
+XML::Node*
+InkboardDocument::createElementNode(char const* name)
+{
+    return new XML::ElementNode(g_quark_from_string(name));
+}
+
+XML::Node*
+InkboardDocument::createTextNode(char const* content)
+{
+    return new XML::TextNode(Util::share_string(content));
+}
+
+XML::Node*
+InkboardDocument::createCommentNode(char const* content)
+{
+    return new XML::CommentNode(Util::share_string(content));
+}
+
+
+void InkboardDocument::notifyChildAdded(XML::Node &parent,
+                                        XML::Node &child,
+                                        XML::Node *prev)
+{
+    if (_in_transaction && state == State::IN_WHITEBOARD) {
+
+        XML::Node *node = (XML::Node *)&child;
+
+        if(tracker->get(node) == "")
+        {
+            addNodeToTracker(node);
+            Message::Message message = composeNewMessage(node);
+
+            send(getRecipient(),Message::NEW,message);
+        }
+    }
+}
+
+void InkboardDocument::notifyChildRemoved(XML::Node &parent,
+                                          XML::Node &child,
+                                          XML::Node *prev)
+{
+    if (_in_transaction && state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&child;
+
+        Message::Message message = String::ucompose(Vars::REMOVE_MESSAGE,
+            tracker->get(element));
+
+        send(getRecipient(),Message::REMOVE,message);
+   }
+}
+
+void InkboardDocument::notifyChildOrderChanged(XML::Node &parent,
+                                               XML::Node &child,
+                                               XML::Node *old_prev,
+                                               XML::Node *new_prev)
+{
+    if (_in_transaction && state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&child;
+        XML::Node *parentElement = (XML::Node *)&parent;
+
+        unsigned int index = parentElement->_childPosition(*element);
+
+        Message::Message message = String::ucompose(Vars::MOVE_MESSAGE,
+                tracker->get(element),index);
+
+        send(getRecipient(),Message::MOVE,message);
+    }
+}
+
+void InkboardDocument::notifyContentChanged(XML::Node &node,
+                                            Util::ptr_shared<char> old_content,
+                                            Util::ptr_shared<char> new_content)
+{
+    if (_in_transaction && state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&node;
+
+        Glib::ustring value(new_content.pointer());
+
+        Glib::ustring change = tracker->getLastHistory(element,"text");
+
+        if(change.size() > 0 && change == value)
+            return;
+
+        if(new_content.pointer())
+        {
+            unsigned int version = tracker->incrementVersion(element);
 
+            Message::Message message = String::ucompose(Vars::CONFIGURE_TEXT_MESSAGE,
+                tracker->get(element),version,new_content.pointer());
 
-/*
-  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 :
+            send(getRecipient(),Message::CONFIGURE,message);
+        }
+    }
+}
+
+void InkboardDocument::notifyAttributeChanged(XML::Node &node,
+                                              GQuark name,
+                                              Util::ptr_shared<char> old_value,
+                                              Util::ptr_shared<char> new_value)
+{
+    if (_in_transaction && state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&node;
+
+        Glib::ustring value(new_value.pointer());
+        Glib::ustring attribute(g_quark_to_string(name));
+
+        Glib::ustring change = tracker->getLastHistory(element,attribute);
+
+        if(change.size() > 0 && change == value)
+            return;
+
+        if(attribute.size() > 0 && value.size() > 0)
+        {
+            unsigned int version = tracker->incrementVersion(element);
+
+            Message::Message message = String::ucompose(Vars::CONFIGURE_MESSAGE,
+                tracker->get(element),version,attribute.c_str(),value.c_str());
+
+            send(getRecipient(),Message::CONFIGURE,message);
+        }
+    }
+}
+
+}
+
+}
index 5eaeffca8e65ee8434f5707f77fe8003acc63d2a..fba6691aa876bb2e404ba02cfe4f343780039b46 100644 (file)
@@ -17,6 +17,7 @@
 #include "document.h"
 #include "xml/document.h"
 #include "xml/simple-node.h"
+#include "xml/node-observer.h"
 #include "jabber_whiteboard/defines.h"
 #include "jabber_whiteboard/keynode.h"
 #include "jabber_whiteboard/session-manager.h"
@@ -25,7 +26,10 @@ namespace Inkscape {
 
 namespace Whiteboard {
 
-class InkboardDocument : public XML::SimpleNode, public XML::Document {
+class InkboardDocument : public XML::SimpleNode,
+                         public XML::Document,
+                         public XML::NodeObserver
+{
 public:
        
     explicit InkboardDocument(int code, State::SessionType sessionType, Glib::ustring const& to);
@@ -61,6 +65,43 @@ public:
 
     void handleChange(Message::Wrapper &wrapper, Pedro::Element* data);
 
+    NodeObserver *logger() { return this; }
+
+    // 
+    // XML::Session methods
+    // 
+    bool inTransaction() 
+    {
+       return _in_transaction;
+    }
+
+    void beginTransaction();
+    void rollback();
+    void commit();
+
+    XML::Event* commitUndoable();
+
+    XML::Node* createElementNode(char const* name);
+    XML::Node* createTextNode(char const* content);
+    XML::Node* createCommentNode(char const* content);
+
+    //
+    // XML::NodeObserver methods
+    //
+    void notifyChildAdded(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
+
+    void notifyChildRemoved(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
+
+    void notifyChildOrderChanged(Inkscape::XML::Node &parent, Inkscape::XML::Node &child,
+                                 Inkscape::XML::Node *old_prev, Inkscape::XML::Node *new_prev);
+
+    void notifyContentChanged(Inkscape::XML::Node &node,
+                              Util::ptr_shared<char> old_content,
+                              Util::ptr_shared<char> new_content);
+
+    void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark name,
+                                Util::ptr_shared<char> old_value,
+                                Util::ptr_shared<char> new_value);
 
     /* Functions below are defined in inkboard-node.cpp */
     Glib::ustring addNodeToTracker(Inkscape::XML::Node* node);
@@ -75,7 +116,6 @@ public:
     void changeConfigureText(Glib::ustring target, unsigned int version,
             Glib::ustring text);
 
-
 protected:
        /**
         * Copy constructor.
@@ -83,7 +123,9 @@ protected:
         * \param orig Instance to copy.
         */
        InkboardDocument(InkboardDocument const& orig) :
-               XML::Node(), XML::SimpleNode(orig), XML::Document(), recipient(orig.recipient)
+               XML::Node(), XML::SimpleNode(orig),
+                XML::Document(), XML::NodeObserver(),
+                recipient(orig.recipient), _in_transaction(false)
        {
                _initBindings();
        }
@@ -94,7 +136,6 @@ protected:
        }
 
 private:
-
     void _initBindings();
 
     SessionManager      *sm;
@@ -103,6 +144,8 @@ private:
 
     Glib::ustring sessionId;
     Glib::ustring recipient;
+
+    bool _in_transaction;
 };
 
 }
diff --git a/src/jabber_whiteboard/inkboard-session.cpp b/src/jabber_whiteboard/inkboard-session.cpp
deleted file mode 100644 (file)
index 76307e3..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/**
- * Inkscape::Whiteboard::InkboardSession - Whiteboard implementation of XML::Session
- *
- * Authors:
- * David Yip <yipdw@rose-hulman.edu>
- *
- * Copyright (c) 2005 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include <glibmm.h>
-#include <glib/gmessages.h>
-#include <glib/gquark.h>
-
-#include "jabber_whiteboard/inkboard-session.h"
-#include "jabber_whiteboard/inkboard-document.h"
-#include "jabber_whiteboard/defines.h"
-
-#include "xml/node.h"
-#include "xml/event.h"
-#include "xml/element-node.h"
-#include "xml/text-node.h"
-#include "xml/comment-node.h"
-
-#include "util/share.h"
-#include "util/ucompose.hpp"
-
-namespace Inkscape {
-
-namespace Whiteboard {
-
-using XML::Node;
-
-void
-InkboardSession::beginTransaction()
-{
-    g_assert(!_in_transaction);
-    _in_transaction = true;
-}
-
-void
-InkboardSession::rollback()
-{
-    g_assert(_in_transaction);
-    _in_transaction = false;
-}
-
-void 
-InkboardSession::commit()
-{
-    g_assert(_in_transaction);
-    _in_transaction = false;
-}
-
-XML::Event*
-InkboardSession::commitUndoable()
-{
-    g_assert(_in_transaction);
-    _in_transaction = false;
-    return NULL;
-}
-
-XML::Node*
-InkboardSession::createElementNode(char const* name)
-{
-    return new XML::ElementNode(g_quark_from_string(name));
-}
-
-XML::Node*
-InkboardSession::createTextNode(char const* content)
-{
-    return new XML::TextNode(Util::share_string(content));
-}
-
-XML::Node*
-InkboardSession::createCommentNode(char const* content)
-{
-    return new XML::CommentNode(Util::share_string(content));
-}
-
-
-void InkboardSession::notifyChildAdded(Node &parent,
-                                     Node &child,
-                                     Node *prev)
-{
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
-
-        XML::Node *node = (XML::Node *)&child;
-
-        if(this->doc->tracker->get(node) == "")
-        {
-            this->doc->addNodeToTracker(node);
-            Message::Message message = this->doc->composeNewMessage(node);
-
-            this->doc->send(this->doc->getRecipient(),Message::NEW,message);
-        }
-    }
-}
-
-void InkboardSession::notifyChildRemoved(Node &parent,
-                                       Node &child,
-                                       Node *prev)
-{
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
-    {
-        XML::Node *element = (XML::Node *)&child;
-
-        Message::Message message = String::ucompose(Vars::REMOVE_MESSAGE,
-            this->doc->tracker->get(element));
-
-        this->doc->send(this->doc->getRecipient(),Message::REMOVE,message);
-   }
-}
-
-void InkboardSession::notifyChildOrderChanged(Node &parent,
-                                            Node &child,
-                                            Node *old_prev,
-                                            Node *new_prev)
-{
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
-    {
-        XML::Node *element = (XML::Node *)&child;
-        XML::Node *parentElement = (XML::Node *)&parent;
-
-        unsigned int index = parentElement->_childPosition(*element);
-
-        Message::Message message = String::ucompose(Vars::MOVE_MESSAGE,
-                this->doc->tracker->get(element),index);
-
-        this->doc->send(this->doc->getRecipient(),Message::MOVE,message);
-    }
-}
-
-void InkboardSession::notifyContentChanged(Node &node,
-                                         Util::ptr_shared<char> old_content,
-                                         Util::ptr_shared<char> new_content)
-{
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
-    {
-        XML::Node *element = (XML::Node *)&node;
-
-        Glib::ustring value(new_content.pointer());
-
-        Glib::ustring change = this->doc->tracker->getLastHistory(element,"text");
-
-        if(change.size() > 0 && change == value)
-            return;
-
-        if(new_content.pointer())
-        {
-            unsigned int version = this->doc->tracker->incrementVersion(element);
-
-            Message::Message message = String::ucompose(Vars::CONFIGURE_TEXT_MESSAGE,
-                this->doc->tracker->get(element),version,new_content.pointer());
-
-            this->doc->send(this->doc->getRecipient(),Message::CONFIGURE,message);
-        }
-    }
-}
-
-void InkboardSession::notifyAttributeChanged(Node &node,
-                                           GQuark name,
-                                           Util::ptr_shared<char> old_value,
-                                           Util::ptr_shared<char> new_value)
-{
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
-    {
-        XML::Node *element = (XML::Node *)&node;
-
-        Glib::ustring value(new_value.pointer());
-        Glib::ustring attribute(g_quark_to_string(name));
-
-        Glib::ustring change = this->doc->tracker->getLastHistory(element,attribute);
-
-        if(change.size() > 0 && change == value)
-            return;
-
-        if(attribute.size() > 0 && value.size() > 0)
-        {
-            unsigned int version = this->doc->tracker->incrementVersion(element);
-
-            Message::Message message = String::ucompose(Vars::CONFIGURE_MESSAGE,
-                this->doc->tracker->get(element),version,attribute.c_str(),value.c_str());
-
-            this->doc->send(this->doc->getRecipient(),Message::CONFIGURE,message);
-        }
-    }
-}
-
-}
-
-}
diff --git a/src/jabber_whiteboard/inkboard-session.h b/src/jabber_whiteboard/inkboard-session.h
deleted file mode 100644 (file)
index 10eeb63..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Inkscape::Whiteboard::InkboardSession - Whiteboard implementation of XML::Session interface
- *
- * Authors:
- * David Yip <yipdw@rose-hulman.edu>
- *
- * Copyright (c) 2005 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef __INKSCAPE_WHITEBOARD_SESSION_H__
-#define __INKSCAPE_WHITEBOARD_SESSION_H__
-
-#include <glibmm.h>
-#include <bitset>
-
-#include "gc-managed.h"
-
-#include "xml/session.h"
-#include "xml/transaction-logger.h"
-#include "xml/log-builder.h"
-#include "xml/node-observer.h"
-#include "xml/simple-session.h"
-
-#include "pedro/pedroxmpp.h"
-
-#include "jabber_whiteboard/inkboard-document.h"
-#include "jabber_whiteboard/defines.h"
-
-#include "util/share.h"
-
-namespace Inkscape {
-
-namespace Whiteboard {
-
-class InkboardDocument;
-
-class InkboardSession : public GC::Managed<>, public XML::Session,
-                         public XML::TransactionLogger
-{
-public:
-
-    InkboardSession() : _in_transaction(false) { }
-    InkboardSession(InkboardDocument *document) : _in_transaction(false), doc(document) {}
-    virtual ~InkboardSession() { }
-
-    //
-    // XML::TransactionLogger methods
-    //
-    Session& session()
-    {
-       return *this;
-    }
-
-    // 
-    // XML::Session methods
-    // 
-    bool inTransaction() 
-    {
-       return _in_transaction;
-    }
-
-    void beginTransaction();
-    void rollback();
-    void commit();
-
-    XML::Event* commitUndoable();
-
-    XML::Node* createElementNode(char const* name);
-    XML::Node* createTextNode(char const* content);
-    XML::Node* createCommentNode(char const* content);
-
-    //
-    // XML::NodeObserver methodscd ../
-    // (inherited from XML::TransactionLogger)
-    //
-    void notifyChildAdded(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
-
-    void notifyChildRemoved(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
-
-    void notifyChildOrderChanged(Inkscape::XML::Node &parent, Inkscape::XML::Node &child,
-                                 Inkscape::XML::Node *old_prev, Inkscape::XML::Node *new_prev);
-
-    void notifyContentChanged(Inkscape::XML::Node &node,
-                              Util::ptr_shared<char> old_content,
-                              Util::ptr_shared<char> new_content);
-
-    void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark name,
-                                Util::ptr_shared<char> old_value,
-                                Util::ptr_shared<char> new_value);
-
-private:
-
-    InkboardSession(InkboardSession const &); // no copy
-    void operator=(InkboardSession const &); // no assign
-
-    bool _in_transaction;
-
-    InkboardDocument *doc;
-};
-
-}
-
-}
-
-#endif
index ed1b5edf6287570d97e94fc728a535252006a4c0..3187612590c8ee5d92de6f0cbbc67b00d51bcb1d 100644 (file)
@@ -23,7 +23,6 @@
 #include "jabber_whiteboard/pedrogui.h"
 #include "jabber_whiteboard/message-queue.h"
 #include "jabber_whiteboard/defines.h"
-#include "jabber_whiteboard/inkboard-session.h"
 
 #include "gc-alloc.h"
 
index 41aa13dcb8dea024add28a5041c1409c670abed6..69f8952a9572faa5fc4bd6d95e8ccc81c9d78d27 100644 (file)
@@ -32,13 +32,10 @@ xml_libspxml_a_SOURCES =    \
        xml/repr-util.cpp       \
        xml/repr.cpp    \
        xml/repr.h      \
-       xml/session.h \
        xml/simple-document.h \
        xml/simple-document.cpp \
        xml/simple-node.h \
        xml/simple-node.cpp \
-       xml/simple-session.cpp \
-       xml/simple-session.h \
        xml/node.h \
        xml/croco-node-iface.cpp        \
        xml/croco-node-iface.h  \
@@ -50,7 +47,6 @@ xml_libspxml_a_SOURCES =      \
        xml/node-iterators.h    \
        xml/sp-css-attr.h \
        xml/text-node.h \
-       xml/transaction-logger.h \
        xml/invalid-operation-exception.h
 
 xml/test-xml-main.cpp: xml/test-xml.cpp $(xml_test_xml_includes)
index 8dc286a38979587d8ee79eaa3cf547461e5969cb..eeb16e74f78d58bfba1c254289b549906f388063 100644 (file)
 #define SEEN_INKSCAPE_XML_SP_REPR_DOC_H
 
 #include "xml/node.h"
-#include "xml/session.h"
 
 namespace Inkscape {
 namespace XML {
 
+class Event;
+class NodeObserver;
+
 struct Document : virtual public Node {
 public:
-    Node *createElementNode(char const *name) {
-        return session()->createElementNode(name);
-    }
-    Node *createTextNode(char const *content) {
-        return session()->createTextNode(content);
-    }
-    Node *createCommentNode(char const *content) {
-        return session()->createCommentNode(content);
-    }
+    virtual NodeObserver *logger()=0;
+
+    virtual bool inTransaction()=0;
+
+    virtual void beginTransaction()=0;
+    virtual void rollback()=0;
+    virtual void commit()=0;
+    virtual Inkscape::XML::Event *commitUndoable()=0;
+
+    virtual Node *createElementNode(char const *name)=0;
+    virtual Node *createTextNode(char const *content)=0;
+    virtual Node *createCommentNode(char const *content)=0;
 };
 
 }
index d91dd681fb5ae912cb7f3909952d82b874cc5b7d..cc130042e52eb7da0e474360d4da92e51f120deb 100644 (file)
@@ -26,8 +26,6 @@ using Inkscape::Util::reverse_list;
 
 int Inkscape::XML::Event::_next_serial=0;
 
-using Inkscape::XML::Session;
-
 void
 sp_repr_begin_transaction (Inkscape::XML::Document *doc)
 {
@@ -38,9 +36,7 @@ sp_repr_begin_transaction (Inkscape::XML::Document *doc)
        EventTracker<SimpleEvent<Event::XML> > tracker("begin-transaction");
 
        g_assert(doc != NULL);
-       Session *session=doc->session();
-       g_assert(session != NULL);
-       session->beginTransaction();
+       doc->beginTransaction();
 }
 
 void
@@ -53,9 +49,7 @@ sp_repr_rollback (Inkscape::XML::Document *doc)
        EventTracker<SimpleEvent<Event::XML> > tracker("rollback");
 
        g_assert(doc != NULL);
-       Session *session=doc->session();
-       g_assert(session != NULL);
-       session->rollback();
+       doc->rollback();
 }
 
 void
@@ -68,9 +62,7 @@ sp_repr_commit (Inkscape::XML::Document *doc)
        EventTracker<SimpleEvent<Event::XML> > tracker("commit");
 
        g_assert(doc != NULL);
-       Session *session=doc->session();
-       g_assert(session != NULL);
-       session->commit();
+       doc->commit();
 }
 
 Inkscape::XML::Event *
@@ -83,9 +75,7 @@ sp_repr_commit_undoable (Inkscape::XML::Document *doc)
        EventTracker<SimpleEvent<Event::XML> > tracker("commit");
 
        g_assert(doc != NULL);
-       Session *session=doc->session();
-       g_assert(session != NULL);
-       return session->commitUndoable();
+       return doc->commitUndoable();
 }
 
 namespace {
@@ -149,7 +139,7 @@ sp_repr_undo_log (Inkscape::XML::Event *log)
        EventTracker<SimpleEvent<Event::XML> > tracker("undo-log");
 
        if (log) {
-               g_assert(!log->repr->session()->inTransaction());
+               g_assert(!log->repr->document()->inTransaction());
        }
 
        Inkscape::XML::undo_log_to_observer(log, LogPerformer::instance());
@@ -206,12 +196,8 @@ sp_repr_replay_log (Inkscape::XML::Event *log)
        EventTracker<SimpleEvent<Event::XML> > tracker("replay-log");
 
        if (log) {
-               // Nodes created by the whiteboard deserializer tend to not 
-               // have an associated session.  This conditional hacks a way around that,
-               // but what's the best way to fix the whiteboard code so that new nodes
-               // will have an associated session? -- yipdw
-               if (log->repr->session()) {
-                       g_assert(!log->repr->session()->inTransaction());
+               if (log->repr->document()) {
+                       g_assert(!log->repr->document()->inTransaction());
                }
        }
 
index 413d81a11cc068debc10ae435bcf3100657314c3..7e27f1ff6ce238e12b7fc61f04b745544d302f9d 100644 (file)
@@ -22,8 +22,6 @@
 namespace Inkscape {
 namespace XML {
 
-class Session;
-class TransactionLogger;
 class AttributeRecord;
 class Document;
 class NodeEventVector;
@@ -46,8 +44,6 @@ public:
 
     virtual NodeType type() const=0;
 
-    virtual Session *session()=0;
-
     virtual gchar const *name() const=0;
     virtual int code() const=0;
     virtual void setCodeUnsafe(int code)=0;
@@ -108,7 +104,6 @@ public: // ideally these should be protected too somehow...
     virtual void _setParent(Node *parent)=0;
     virtual void _setNext(Node *next)=0;
     virtual void _bindDocument(Document &document)=0;
-    virtual void _bindLogger(TransactionLogger &logger)=0;
 
     virtual unsigned _childPosition(Node const &child) const=0;
     virtual unsigned _cachedPosition() const=0;
diff --git a/src/xml/session.h b/src/xml/session.h
deleted file mode 100644 (file)
index 967373a..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Inkscape::XML::Session - context for transactions
- *
- * Copyright 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_SESSION_H
-#define SEEN_INKSCAPE_XML_SESSION_H
-
-namespace Inkscape {
-
-namespace XML {
-
-class Event;
-class Node;
-
-class Session {
-public:
-    Session() {}
-    virtual ~Session() {}
-    
-    virtual bool inTransaction()=0;
-
-    virtual void beginTransaction()=0;
-    virtual void rollback()=0;
-    virtual void commit()=0;
-    virtual Inkscape::XML::Event *commitUndoable()=0;
-
-    virtual Node *createElementNode(char const *name)=0;
-    virtual Node *createTextNode(char const *content)=0;
-    virtual Node *createCommentNode(char const *content)=0;
-};
-
-}
-
-}
-
-#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 3e7a17ff5dd8cc99db57a8f7fe6b828dee6e622c..e8c652b2deaa45eeb2098e6443bfa96ed1fc273b 100644 (file)
  */
 
 #include "xml/simple-document.h"
-#include "xml/simple-session.h"
+#include "xml/event-fns.h"
+#include "xml/element-node.h"
+#include "xml/text-node.h"
+#include "xml/comment-node.h"
 
 namespace Inkscape {
 
@@ -21,7 +24,90 @@ namespace XML {
 
 void SimpleDocument::_initBindings() {
     _bindDocument(*this);
-    _bindLogger(*(new Inkscape::XML::SimpleSession()));
+}
+
+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::createElementNode(char const *name) {
+    return new ElementNode(g_quark_from_string(name));
+}
+
+Node *SimpleDocument::createTextNode(char const *content) {
+    return new TextNode(Util::share_string(content));
+}
+
+Node *SimpleDocument::createCommentNode(char const *content) {
+    return new CommentNode(Util::share_string(content));
+}
+
+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);
+    }
 }
 
 }
index a2e58fe791cd6a91f17c45ed87e215ed36607214..ca130e62bcf80bdd2fa61ae87b57a2efde5c6edf 100644 (file)
 
 #include "xml/document.h"
 #include "xml/simple-node.h"
+#include "xml/node-observer.h"
+#include "xml/log-builder.h"
 
 namespace Inkscape {
 
 namespace XML {
 
-struct SimpleDocument : public SimpleNode, public Inkscape::XML::Document {
-    explicit SimpleDocument(int code) : SimpleNode(code) {
+class SimpleDocument : public SimpleNode,
+                       public Document,
+                       public NodeObserver
+{
+public:
+    explicit SimpleDocument(int code)
+    : SimpleNode(code), _in_transaction(false)
+    {
         _initBindings();
     }
 
-    Inkscape::XML::NodeType type() const { return Inkscape::XML::DOCUMENT_NODE; }
+    NodeType type() const { return Inkscape::XML::DOCUMENT_NODE; }
+
+    NodeObserver *logger() { return this; }
+
+    bool inTransaction() { return _in_transaction; }
+
+    void beginTransaction();
+    void rollback();
+    void commit();
+    Inkscape::XML::Event *commitUndoable();
+
+    Node *createElementNode(char const *name);
+    Node *createTextNode(char const *content);
+    Node *createCommentNode(char const *content);
+
+    void notifyChildAdded(Node &parent, Node &child, Node *prev);
+
+    void notifyChildRemoved(Node &parent, Node &child, Node *prev);
+
+    void notifyChildOrderChanged(Node &parent, Node &child,
+                                 Node *old_prev, Node *new_prev);
+
+    void notifyContentChanged(Node &node,
+                              Util::ptr_shared<char> old_content,
+                              Util::ptr_shared<char> new_content);
+
+    void notifyAttributeChanged(Node &node, GQuark name,
+                                Util::ptr_shared<char> old_value,
+                                Util::ptr_shared<char> new_value);
 
 protected:
-    SimpleDocument(SimpleDocument const &doc) : Inkscape::XML::Node(), SimpleNode(doc), Inkscape::XML::Document() {
+    SimpleDocument(SimpleDocument const &doc)
+    : Node(), SimpleNode(doc), Document(), NodeObserver(),
+      _in_transaction(false)
+    {
         _initBindings();
     }
 
@@ -38,6 +77,9 @@ protected:
 
 private:
     void _initBindings();
+
+    bool _in_transaction;
+    LogBuilder _log_builder;
 };
 
 }
index 7f8dd29b29136c791621323cc4f3604b7393de9a..f439243cdb2ccb49761abc03d9cc00144ef3ebc4 100644 (file)
@@ -161,7 +161,7 @@ SimpleNode::SimpleNode(int code)
 : Node(), _name(code), _attributes(), _child_count(0),
   _cached_positions_valid(false)
 {
-    this->_logger = NULL;
+    this->_document = NULL;
     this->_document = NULL;
     this->_parent = this->_next = NULL;
     this->_first_child = this->_last_child = NULL;
@@ -174,7 +174,7 @@ SimpleNode::SimpleNode(SimpleNode const &node)
   _child_count(node._child_count),
   _cached_positions_valid(node._cached_positions_valid)
 {
-    _logger = NULL;
+    _document = NULL;
     _document = NULL;
     _parent = _next = NULL;
     _first_child = _last_child = NULL;
@@ -282,8 +282,8 @@ void SimpleNode::setContent(gchar const *content) {
     _content = new_content;
 
     if ( _content != old_content ) {
-        if (_logger) {
-            _logger->notifyContentChanged(*this, old_content, _content);
+        if (_document) {
+            _document->logger()->notifyContentChanged(*this, old_content, _content);
         }
 
         _observers.notifyContentChanged(*this, old_content, _content);
@@ -336,8 +336,8 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const is_in
     }
 
     if ( new_value != old_value && (!old_value || !new_value || strcmp(old_value, new_value))) {
-        if (_logger) {
-            _logger->notifyAttributeChanged(*this, key, old_value, new_value);
+        if (_document) {
+            _document->logger()->notifyAttributeChanged(*this, key, old_value, new_value);
         }
 
         _observers.notifyAttributeChanged(*this, key, old_value, new_value);
@@ -380,10 +380,7 @@ void SimpleNode::addChild(Node *child, Node *ref) {
 
     if (_document) {
         child->_bindDocument(*_document);
-    }
-    if (_logger) {
-        child->_bindLogger(*_logger);
-        _logger->notifyChildAdded(*this, *child, ref);
+        _document->logger()->notifyChildAdded(*this, *child, ref);
     }
 
     _observers.notifyChildAdded(*this, *child, ref);
@@ -401,18 +398,6 @@ void SimpleNode::_bindDocument(Document &document) {
     }
 }
 
-void SimpleNode::_bindLogger(TransactionLogger &logger) {
-    g_assert(!_logger || _logger == &logger);
-
-    if (!_logger) {
-        _logger = &logger;
-
-        for ( Node *child = _first_child ; child != NULL ; child = child->next() ) {
-            child->_bindLogger(logger);
-        }
-    }
-}
-
 void SimpleNode::removeChild(Node *child) {
     g_assert(child);
     g_assert(child->parent() == this);
@@ -438,8 +423,8 @@ void SimpleNode::removeChild(Node *child) {
     child->_setParent(NULL);
     _child_count--;
 
-    if (_logger) {
-        _logger->notifyChildRemoved(*this, *child, ref);
+    if (_document) {
+        _document->logger()->notifyChildRemoved(*this, *child, ref);
     }
 
     _observers.notifyChildRemoved(*this, *child, ref);
@@ -485,8 +470,8 @@ void SimpleNode::changeOrder(Node *child, Node *ref) {
 
     _cached_positions_valid = false;
 
-    if (_logger) {
-        _logger->notifyChildOrderChanged(*this, *child, prev, ref);
+    if (_document) {
+        _document->logger()->notifyChildOrderChanged(*this, *child, prev, ref);
     }
 
     _observers.notifyChildOrderChanged(*this, *child, prev, ref);
index 367516ee797fbbf93f3ee5d68af855fe64aaf45f..7c32ebee67c68d487b37d172946429396b701871 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "xml/node.h"
 #include "xml/attribute-record.h"
-#include "xml/transaction-logger.h"
 #include "xml/composite-node-observer.h"
 #include "util/list-container.h"
 
@@ -29,14 +28,10 @@ class SimpleNode
 : virtual public Node, public Inkscape::GC::Managed<>
 {
 public:
-    Session *session() {
-        return ( _logger ? &_logger->session() : NULL );
-    }
-
     gchar const *name() const;
     int code() const { return _name; }
     void setCodeUnsafe(int code) {
-        g_assert(_logger == NULL);
+        g_assert(_document == NULL);
         _name = code;
     }
 
@@ -119,7 +114,6 @@ public: // ideally these should be protected somehow...
     void _setParent(Node *parent) { _parent = parent; }
     void _setNext(Node *next) { _next = next; }
     void _bindDocument(Document &document);
-    void _bindLogger(TransactionLogger &logger);
 
     unsigned _childPosition(Node const &child) const;
     unsigned _cachedPosition() const { return _cached_position; }
@@ -133,7 +127,6 @@ private:
     Node *_parent;
     Node *_next;
     Document *_document;
-    TransactionLogger *_logger;
     mutable unsigned _cached_position;
 
     int _name;
diff --git a/src/xml/simple-session.cpp b/src/xml/simple-session.cpp
deleted file mode 100644 (file)
index d5c17a5..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Inkscape::XML::SimpleSession - simple session/logging implementation
- *
- * Copyright 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 "xml/simple-session.h"
-#include "xml/event-fns.h"
-#include "xml/element-node.h"
-#include "xml/text-node.h"
-#include "xml/comment-node.h"
-
-namespace Inkscape {
-
-namespace XML {
-
-void SimpleSession::beginTransaction() {
-    g_assert(!_in_transaction);
-    _in_transaction = true;
-}
-
-void SimpleSession::rollback() {
-    g_assert(_in_transaction);
-    _in_transaction = false;
-    Event *log = _log_builder.detach();
-    sp_repr_undo_log(log);
-    sp_repr_free_log(log);
-}
-
-void SimpleSession::commit() {
-    g_assert(_in_transaction);
-    _in_transaction = false;
-    _log_builder.discard();
-}
-
-Inkscape::XML::Event *SimpleSession::commitUndoable() {
-    g_assert(_in_transaction);
-    _in_transaction = false;
-    return _log_builder.detach();
-}
-
-Node *SimpleSession::createElementNode(char const *name) {
-    return new ElementNode(g_quark_from_string(name));
-}
-
-Node *SimpleSession::createTextNode(char const *content) {
-    return new TextNode(Util::share_string(content));
-}
-
-Node *SimpleSession::createCommentNode(char const *content) {
-    return new CommentNode(Util::share_string(content));
-}
-
-void SimpleSession::notifyChildAdded(Node &parent,
-                                     Node &child,
-                                     Node *prev)
-{
-    if (_in_transaction) {
-        _log_builder.addChild(parent, child, prev);
-    }
-}
-
-void SimpleSession::notifyChildRemoved(Node &parent,
-                                       Node &child,
-                                       Node *prev)
-{
-    if (_in_transaction) {
-        _log_builder.removeChild(parent, child, prev);
-    }
-}
-
-void SimpleSession::notifyChildOrderChanged(Node &parent,
-                                            Node &child,
-                                            Node *old_prev,
-                                            Node *new_prev)
-{
-    if (_in_transaction) {
-        _log_builder.setChildOrder(parent, child, old_prev, new_prev);
-    }
-}
-
-void SimpleSession::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 SimpleSession::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:encoding=utf-8:textwidth=99 :
diff --git a/src/xml/simple-session.h b/src/xml/simple-session.h
deleted file mode 100644 (file)
index ecd61ba..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Inkscape::XML::SimpleSession - simple session/logging implementation
- *
- * Copyright 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_SIMPLE_SESSION_H
-#define SEEN_INKSCAPE_XML_SIMPLE_SESSION_H
-
-#include "gc-managed.h"
-#include "xml/session.h"
-#include "xml/transaction-logger.h"
-#include "xml/log-builder.h"
-
-namespace Inkscape {
-
-namespace XML {
-
-class SimpleSession : public GC::Managed<>,
-                      public Session,
-                      public TransactionLogger
-{
-public:
-    SimpleSession() : _in_transaction(false) {}
-
-    bool inTransaction() { return _in_transaction; }
-
-    void beginTransaction();
-    void rollback();
-    void commit();
-    Inkscape::XML::Event *commitUndoable();
-
-    Node *createElementNode(char const *name);
-    Node *createTextNode(char const *content);
-    Node *createCommentNode(char const *content);
-
-    Session &session() { return *this; }
-
-    void notifyChildAdded(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
-
-    void notifyChildRemoved(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
-
-    void notifyChildOrderChanged(Inkscape::XML::Node &parent, Inkscape::XML::Node &child,
-                                 Inkscape::XML::Node *old_prev, Inkscape::XML::Node *new_prev);
-
-    void notifyContentChanged(Inkscape::XML::Node &node,
-                              Util::ptr_shared<char> old_content,
-                              Util::ptr_shared<char> new_content);
-
-    void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark name,
-                                Util::ptr_shared<char> old_value,
-                                Util::ptr_shared<char> new_value);
-
-private:
-    SimpleSession(SimpleSession const &); // no copy
-    void operator=(SimpleSession const &); // no assign
-
-    bool _in_transaction;
-    LogBuilder _log_builder;
-};
-
-}
-
-}
-
-#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/transaction-logger.h b/src/xml/transaction-logger.h
deleted file mode 100644 (file)
index 9f7bfbc..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Inkscape::XML::TransactionLogger - logs changes for transactions
- *
- * Copyright 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_TRANSACTION_LOGGER_H
-#define SEEN_INKSCAPE_XML_TRANSACTION_LOGGER_H
-
-#include "xml/node-observer.h"
-
-namespace Inkscape {
-namespace XML {
-class Event;
-}
-}
-
-
-namespace Inkscape {
-
-namespace XML {
-
-class Session;
-
-class TransactionLogger : public NodeObserver {
-public:
-    virtual Session &session()=0;
-};
-
-}
-
-}
-
-#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 :