diff options
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/xml/helper-observer.cpp | 43 | ||||
| -rw-r--r-- | src/xml/helper-observer.h | 35 |
3 files changed, 80 insertions, 0 deletions
diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert index 9ca81b231..3321031c9 100644 --- a/src/xml/Makefile_insert +++ b/src/xml/Makefile_insert @@ -18,6 +18,8 @@ xml_libspxml_a_SOURCES = \ xml/comment-node.h \ xml/composite-node-observer.cpp xml/composite-node-observer.h \ xml/element-node.h \ + xml/helper-observer.cpp \ + xml/helper-observer.h \ xml/node-observer.h \ xml/quote.cpp \ xml/quote.h \ diff --git a/src/xml/helper-observer.cpp b/src/xml/helper-observer.cpp new file mode 100644 index 000000000..620a88d8c --- /dev/null +++ b/src/xml/helper-observer.cpp @@ -0,0 +1,43 @@ +#include "helper-observer.h" + +namespace Inkscape { +namespace XML { + +// Very simple observer that just emits a signal if anything happens to a node +SignalObserver::SignalObserver() + : _oldsel(0) +{} + +// Add this observer to the SPObject and remove it from any previous object +void SignalObserver::set(SPObject* o) +{ + if(_oldsel && _oldsel->repr) + _oldsel->repr->removeObserver(*this); + if(o && o->repr) + o->repr->addObserver(*this); + _oldsel = o; +} + +void SignalObserver::notifyChildAdded(XML::Node&, XML::Node&, XML::Node*) +{ signal_changed()(); } + +void SignalObserver::notifyChildRemoved(XML::Node&, XML::Node&, XML::Node*) +{ signal_changed()(); } + +void SignalObserver::notifyChildOrderChanged(XML::Node&, XML::Node&, XML::Node*, XML::Node*) +{ signal_changed()(); } + +void SignalObserver::notifyContentChanged(XML::Node&, Util::ptr_shared<char>, Util::ptr_shared<char>) +{} + +void SignalObserver::notifyAttributeChanged(XML::Node&, GQuark, Util::ptr_shared<char>, Util::ptr_shared<char>) +{ signal_changed()(); } + +sigc::signal<void>& SignalObserver::signal_changed() +{ + return _signal_changed; +} + +} //namespace XML +} //namespace Inkscape + diff --git a/src/xml/helper-observer.h b/src/xml/helper-observer.h new file mode 100644 index 000000000..d028d390b --- /dev/null +++ b/src/xml/helper-observer.h @@ -0,0 +1,35 @@ +#ifndef __XML_HELPER_OBSERVER__ +#define __XML_HELPER_OBSERVER__ + +#include "node-observer.h" +#include "node.h" +#include "../sp-object.h" +//#include "../sp-object-repr.h" +#include <sigc++/sigc++.h> + +namespace Inkscape { + namespace XML { + class Node; + + // Very simple observer that just emits a signal if anything happens to a node + class SignalObserver : public NodeObserver + { + public: + SignalObserver(); + + // Add this observer to the SPObject and remove it from any previous object + void set(SPObject* o); + void notifyChildAdded(Node&, Node&, Node*); + void notifyChildRemoved(Node&, Node&, Node*); + void notifyChildOrderChanged(Node&, Node&, Node*, Node*); + void notifyContentChanged(Node&, Util::ptr_shared<char>, Util::ptr_shared<char>); + void notifyAttributeChanged(Node&, GQuark, Util::ptr_shared<char>, Util::ptr_shared<char>); + sigc::signal<void>& signal_changed(); + private: + sigc::signal<void> _signal_changed; + SPObject* _oldsel; + }; + } +} + +#endif //#ifndef __XML_HELPER_OBSERVER__ |
