Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / layer-manager.cpp
index 2edc26de4104c41648ca251c43a188403c27d8ef..3e49edac5723299ab5699850b14ab31fe6c478c1 100644 (file)
 #include "desktop.h"
 #include "desktop-handles.h"
 #include "layer-manager.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "ui/view/view.h"
 #include "selection.h"
 #include "sp-object.h"
 #include "sp-item-group.h"
 #include "xml/node.h"
 #include "xml/node-observer.h"
+#include "util/format.h"
 // #include "debug/event-tracker.h"
 // #include "debug/simple-event.h"
 
@@ -82,13 +83,20 @@ Util::ptr_shared<char> stringify_obj(SPObject const &obj) {
 
 typedef Debug::SimpleEvent<Debug::Event::OTHER> DebugLayer;
 
+class DebugLayerNote : public DebugLayer {
+public:
+    DebugLayerNote(Util::ptr_shared<char> descr)
+        : DebugLayer(Util::share_static_string("layer-note"))
+    {
+        _addProperty("descr", descr);
+    }
+};
 
 class DebugLayerRebuild : public DebugLayer {
 public:
     DebugLayerRebuild()
         : DebugLayer(Util::share_static_string("rebuild-layers"))
     {
-        _addProperty("simple", Util::share_static_string("foo"));
     }
 };
 
@@ -110,7 +118,7 @@ public:
 };
 
 
-}
+} // end of namespace
 */
 
 LayerManager::LayerManager(SPDesktop *desktop)
@@ -142,7 +150,8 @@ void LayerManager::setCurrentLayer( SPObject* obj )
     if ( _desktop->currentRoot() ) {
         _desktop->setCurrentLayer( obj );
 
-        if ( prefs_get_int_attribute_limited("options.selection", "layerdeselect", 1, 0, 1) ) {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        if (prefs->getBool("/options/selection/layerdeselect", true)) {
             sp_desktop_selection( _desktop )->clear();
         }
     }
@@ -243,6 +252,7 @@ void LayerManager::_rebuild() {
 
         for ( GSList const *iter = layers; iter; iter = iter->next ) {
             SPObject *layer = static_cast<SPObject *>(iter->data);
+//             Debug::EventTracker<DebugLayerNote> tracker(Util::format("Examining %s", layer->label()));
             bool needsAdd = false;
             std::set<SPGroup*> additional;
 
@@ -254,10 +264,17 @@ void LayerManager::_rebuild() {
                         if ( group->layerMode() == SPGroup::LAYER ) {
                             // If we have a layer-group as the one or a parent, ensure it is listed as a valid layer.
                             needsAdd &= ( g_slist_find(const_cast<GSList *>(layers), curr) != NULL );
+                            if ( (!(group->repr)) || (!(group->repr->parent())) ) {
+                                needsAdd = false;
+                            }
                         } else {
                             // If a non-layer group is a parent of layer groups, then show it also as a layer.
                             // TODO add the magic Inkscape group mode?
-                            additional.insert(group);
+                            if ( group->repr && group->repr->parent() ) {
+                                additional.insert(group);
+                            } else {
+                                needsAdd = false;
+                            }
                         }
                     }
                 }
@@ -267,7 +284,9 @@ void LayerManager::_rebuild() {
                     layersToAdd.insert(SP_GROUP(layer));
                 }
                 for ( std::set<SPGroup*>::iterator it = additional.begin(); it != additional.end(); ++it ) {
-                    layersToAdd.insert(*it);
+                    if ( !includes(*it) ) {
+                        layersToAdd.insert(*it);
+                    }
                 }
             }
         }