diff options
| author | Ed Halley <ed@halley.cc> | 2009-03-08 20:37:15 +0000 |
|---|---|---|
| committer | speare <speare@users.sourceforge.net> | 2009-03-08 20:37:15 +0000 |
| commit | 0dab4271d0ca744c89a5001e513a3760b8331d27 (patch) | |
| tree | ae07c172eceadbd48f4563af78bd2ef37809d856 /src/layer-manager.cpp | |
| parent | Should be pointing to 047 really (diff) | |
| download | inkscape-0dab4271d0ca744c89a5001e513a3760b8331d27.tar.gz inkscape-0dab4271d0ca744c89a5001e513a3760b8331d27.zip | |
part of #339660; layers dialog allows non-unique inkscape:label attributes
(bzr r7443)
Diffstat (limited to 'src/layer-manager.cpp')
| -rw-r--r-- | src/layer-manager.cpp | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index 3e49edac5..8c45c7e53 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -157,49 +157,53 @@ void LayerManager::setCurrentLayer( SPObject* obj ) } } -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() ); |
