Code

Corrected base structure and avoiding infinite loop.
authorjoncruz <joncruz@users.sourceforge.net>
Sun, 14 May 2006 07:21:09 +0000 (07:21 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Sun, 14 May 2006 07:21:09 +0000 (07:21 +0000)
ChangeLog
src/document-subset.cpp
src/layer-manager.cpp
src/layer-manager.h

index f2d8b0dd53436a9523e84eae3ecedfe4f36f86cc..cdf959df9280ab6fa49ad5c7c19ff984b262d1e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-14  Jon A. Cruz  <jon@joncruz.org>
+
+       * src/document-subset.cpp, src/layer-manager.h, src/layer-manager.cpp:
+         Corrected base structure and avoiding infinite loop.
+
 2006-05-14  Michael Wybrow  <mjwybrow@users.sourceforge.net>
 
        * src/widgets/toolbox.cpp: Slightly increase size of the
index 217176f4e78dff0e2631ef1ac829326f771aae22..4e7e9f694f6a49e00fe995aa6aebe263c8572fa0 100644 (file)
@@ -57,17 +57,32 @@ struct DocumentSubset::Relations : public GC::Managed<GC::ATOMIC>,
             } else {
                 Siblings::const_iterator first=children.begin();
                 Siblings::const_iterator last=children.end() - 1;
-                while ( first != last ) {
-                    Siblings::const_iterator mid=first + ( last - first + 1 ) / 2;
-                    int pos=sp_object_compare_position(*mid, obj);
+                if ( children.size() == 1 ) {
+                    int pos = sp_object_compare_position(*first, obj);
                     if ( pos < 0 ) {
-                        first = mid;
+                        // All good.
                     } else if ( pos > 0 ) {
-                        last = mid;
+                        last++;
                     } else {
                         g_assert_not_reached();
                     }
+                } else {
+                    while ( first != last ) {
+                        Siblings::const_iterator mid=first + ( last - first + 1 ) / 2;
+                        int pos=sp_object_compare_position(*mid, obj);
+                        if ( pos < 0 ) {
+                            first = mid;
+                        } else if ( pos > 0 ) {
+                            if ( last == mid ) {
+                                break;
+                            }
+                            last = mid;
+                        } else {
+                            g_assert_not_reached();
+                        }
+                    }
                 }
+
                 return last - children.begin();
             }
         }
index 01af95424e53d6dec6bbdbcf2b42560d5b8b7a6b..15bd57fd9a189be0ef8cdea74c9225856e247eea 100644 (file)
@@ -22,8 +22,18 @@ namespace Inkscape {
 LayerManager::LayerManager(SPDesktop *desktop)
 : _desktop(desktop), _document(NULL)
 {
-    _layer_connection = desktop->connectCurrentLayerChanged(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_rebuild)));
-    _document_connection = desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_setDocument)));
+    sigc::slot<void> base = sigc::mem_fun(*this, &LayerManager::_rebuild);
+    sigc::slot<void, SPObject *> slot = sigc::hide<0>(base);
+    _layer_connection = desktop->connectCurrentLayerChanged(slot);
+
+    sigc::bound_mem_functor1<void, Inkscape::LayerManager, SPDocument*> first = sigc::mem_fun(*this, &LayerManager::_setDocument);
+
+    // This next line has problems on gcc 4.0.2
+    sigc::slot<void, SPDocument*> base2 = first;
+
+    sigc::slot<void,SPDesktop*,SPDocument*> slot2 = sigc::hide<0>( base2 );
+    _document_connection = desktop->connectDocumentReplaced( slot2 );
+
     _setDocument(desktop->doc());
 }
 
@@ -40,19 +50,26 @@ void LayerManager::_setDocument(SPDocument *document) {
 
 void LayerManager::_rebuild() {
     _clear();
-    GSList const *layers=sp_document_get_resource_list(_document, "layers");
+    GSList const *layers=sp_document_get_resource_list(_document, "layer");
+    SPObject *root=_desktop->currentRoot();
+    if ( root ) {
+        _addOne(root);
+    }
     for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
         SPObject *layer=static_cast<SPObject *>(iter->data);
-        _addOne(layer);
-    }
-    SPObject *root=_desktop->currentRoot();
-    SPObject *layer=_desktop->currentLayer();
-    for ( ; layer ; layer = SP_OBJECT_PARENT(layer) ) {
-        if (!includes(layer)) {
-            _addOne(layer);
-        }
-        if ( layer == root ) {
-            break;
+
+        for ( SPObject* curr = layer; curr && (curr != root) ; curr = SP_OBJECT_PARENT(curr) ) {
+            if ( (curr != root) && root->isAncestorOf(curr) && !includes(curr) ) {
+                // Filter out objects in the middle of being deleted
+                SPObject const *higher = curr;
+                while ( higher && (SP_OBJECT_PARENT(higher) != root) ) {
+                    higher = SP_OBJECT_PARENT(higher);
+                }
+                Inkscape::XML::Node* node = higher ? SP_OBJECT_REPR(higher) : 0;
+                if ( node && node->parent() ) {
+                    _addOne(curr);
+                }
+            }
         }
     }
 }
index 622cda1f247f5c7b7b2eedf853d561e2c792b9c7..48ef73c73585de665f2c85dd1f55c3698010a235 100644 (file)
@@ -14,7 +14,7 @@
 #include "gc-finalized.h"
 #include "gc-soft-ptr.h"
 
-class SPDocument;
+class SPDesktop;
 class SPDocument;
 
 namespace Inkscape {
@@ -26,6 +26,7 @@ public:
     LayerManager(SPDesktop *desktop);
 
 private:
+
     void _setDocument(SPDocument *document);
     void _rebuild();