Code

r11451@tres: ted | 2006-04-17 22:21:33 -0700
[inkscape.git] / src / document-subset.cpp
index 08638b9f3fd517d9aaf00c56ad9e4a9a176dc336..ba6e416cd49a09c08157be7a6c4625c384eb165d 100644 (file)
@@ -15,6 +15,7 @@
 #include <glib/gmessages.h>
 
 #include <sigc++/signal.h>
+#include <sigc++/functors/mem_fun.h>
 
 #include "util/list.h"
 #include "util/reverse-list.h"
@@ -36,6 +37,7 @@ struct DocumentSubset::Relations : public GC::Managed<GC::ATOMIC>,
         Siblings children;
 
         gulong release_connection;
+        sigc::connection position_changed_connection;
 
         Record() : parent(NULL), release_connection(0) {}
 
@@ -140,6 +142,7 @@ struct DocumentSubset::Relations : public GC::Managed<GC::ATOMIC>,
     void addOne(SPObject *obj);
     void remove(SPObject *obj, bool subtree);
     void reorder(SPObject *obj);
+    void clear();
 
 private:
     Record &_doAdd(SPObject *obj) {
@@ -148,6 +151,10 @@ private:
         record.release_connection
           = g_signal_connect(obj, "release",
                              (GCallback)&Relations::_release_object, this);
+        record.position_changed_connection
+          = obj->connectPositionChanged(
+              sigc::mem_fun(this, &Relations::reorder)
+            );
         return record;
     }
 
@@ -161,6 +168,7 @@ private:
             g_signal_handler_disconnect(obj, record.release_connection);
             record.release_connection = 0;
         }
+        record.position_changed_connection.disconnect();
         records.erase(obj);
         removed_signal.emit(obj);
         sp_object_unref(obj);
@@ -187,8 +195,8 @@ private:
     }
 };
 
-DocumentSubset::DocumentSubset(SPDocument *document)
-: _document(document), _relations(new DocumentSubset::Relations())
+DocumentSubset::DocumentSubset()
+: _relations(new DocumentSubset::Relations())
 {
 }
 
@@ -270,6 +278,16 @@ void DocumentSubset::Relations::remove(SPObject *obj, bool subtree) {
     changed_signal.emit();
 }
 
+void DocumentSubset::Relations::clear() {
+    Record &root=records[NULL];
+
+    while (!root.children.empty()) {
+        _doRemoveSubtree(root.children.front());
+    }
+
+    changed_signal.emit();
+}
+
 void DocumentSubset::Relations::reorder(SPObject *obj) {
     SPObject::ParentIterator parent=obj;
 
@@ -309,6 +327,10 @@ void DocumentSubset::_remove(SPObject *obj, bool subtree) {
     _relations->remove(obj, subtree);
 }
 
+void DocumentSubset::_clear() {
+    _relations->clear();
+}
+
 bool DocumentSubset::includes(SPObject *obj) const {
     return _relations->get(obj);
 }