Code

Fix self-snapping when dragging the transformation center of a selection containing...
[inkscape.git] / src / layer-manager.cpp
index c7ba0e9045f93778b15cf6b6b7d6ce5966e5762f..db7384622ee6dc6d007b73e69588402baabfe551 100644 (file)
@@ -16,7 +16,7 @@
 #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"
@@ -142,6 +142,7 @@ LayerManager::~LayerManager()
     _layer_connection.disconnect();
     _document_connection.disconnect();
     _resource_connection.disconnect();
+    _document = 0;
 }
 
 void LayerManager::setCurrentLayer( SPObject* obj )
@@ -150,55 +151,60 @@ 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();
         }
     }
 }
 
-void LayerManager::renameLayer( SPObject* obj, gchar const *label )
+void LayerManager::renameLayer( SPObject* obj, gchar const *label, bool uniquify )
 {
     Glib::ustring incoming( label ? label : "" );
     Glib::ustring result(incoming);
     Glib::ustring base(incoming);
     guint startNum = 1;
 
-    Glib::ustring::size_type pos = base.rfind('#');
-    if ( pos != Glib::ustring::npos ) {
-        gchar* numpart = g_strdup(base.substr(pos+1).c_str());
-        if ( numpart ) {
-            gchar* endPtr = 0;
-            guint64 val = g_ascii_strtoull( numpart, &endPtr, 10);
-            if ( ((val > 0) || (endPtr != numpart)) && (val < 65536) ) {
-                base.erase( pos );
-                result = base;
-                startNum = static_cast<int>(val);
+    if (uniquify) {
+
+        Glib::ustring::size_type pos = base.rfind('#');
+        if ( pos != Glib::ustring::npos ) {
+            gchar* numpart = g_strdup(base.substr(pos+1).c_str());
+            if ( numpart ) {
+                gchar* endPtr = 0;
+                guint64 val = g_ascii_strtoull( numpart, &endPtr, 10);
+                if ( ((val > 0) || (endPtr != numpart)) && (val < 65536) ) {
+                    base.erase( pos );
+                    result = base;
+                    startNum = static_cast<int>(val);
+                }
+                g_free(numpart);
             }
-            g_free(numpart);
         }
-    }
 
-    std::set<Glib::ustring> currentNames;
-    GSList const *layers=sp_document_get_resource_list(_document, "layer");
-    SPObject *root=_desktop->currentRoot();
-    if ( root ) {
-        for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
-            SPObject *layer=static_cast<SPObject *>(iter->data);
-            if ( layer != obj ) {
-                currentNames.insert( layer->label() ? Glib::ustring(layer->label()) : Glib::ustring() );
+        std::set<Glib::ustring> currentNames;
+        GSList const *layers=sp_document_get_resource_list(_document, "layer");
+        SPObject *root=_desktop->currentRoot();
+        if ( root ) {
+            for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
+                SPObject *layer=static_cast<SPObject *>(iter->data);
+                if ( layer != obj ) {
+                    currentNames.insert( layer->label() ? Glib::ustring(layer->label()) : Glib::ustring() );
+                }
             }
         }
-    }
 
-    // Not sure if we need to cap it, but we'll just be paranoid for the moment
-    // Intentionally unsigned
-    guint endNum = startNum + 3000;
-    for ( guint i = startNum; (i < endNum) && (currentNames.find(result) != currentNames.end()); i++ ) {
-        gchar* suffix = g_strdup_printf("#%d", i);
-        result = base;
-        result += suffix;
+        // Not sure if we need to cap it, but we'll just be paranoid for the moment
+        // Intentionally unsigned
+        guint endNum = startNum + 3000;
+        for ( guint i = startNum; (i < endNum) && (currentNames.find(result) != currentNames.end()); i++ ) {
+            gchar* suffix = g_strdup_printf("#%d", i);
+            result = base;
+            result += suffix;
+
+            g_free(suffix);
+        }
 
-        g_free(suffix);
     }
 
     obj->setLabel( result.c_str() );
@@ -310,7 +316,7 @@ void LayerManager::_rebuild() {
                 LayerWatcher *eye = new LayerWatcher(this, layer, connection);
                 _watchers.push_back( eye );
                 SP_OBJECT_REPR(layer)->addObserver(*eye);
-                
+
                 _addOne(layer);
             }
         }