Code

Edit > Duplicate Layer should duplicate hidden items, locked items, sublayers, everything
authorspeare <speare@users.sourceforge.net>
Tue, 10 Mar 2009 02:43:40 +0000 (02:43 +0000)
committerspeare <speare@users.sourceforge.net>
Tue, 10 Mar 2009 02:43:40 +0000 (02:43 +0000)
src/verbs.cpp

index 5e911552cde796e3afa7fc839690bef289446762..06abe93693462ba23036c9908082033ff38550b7 100644 (file)
@@ -1227,19 +1227,38 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
         }
         case SP_VERB_LAYER_DUPLICATE: {
             if ( dt->currentLayer() != dt->currentRoot() ) {
+                // Note with either approach:
+                // Any clone masters are duplicated, their clones use the *original*,
+                // but the duplicated master is not linked up as master nor clone of the original.
+#if 0
+                // Only copies selectable things, honoring locks, visibility, avoids sublayers.
                 SPObject *new_layer = Inkscape::create_layer(dt->currentRoot(), dt->currentLayer(), LPOS_BELOW);
                 if ( dt->currentLayer()->label() ) {
                     gchar* name = g_strdup_printf(_("%s copy"), dt->currentLayer()->label());
                     dt->layer_manager->renameLayer( new_layer, name, TRUE );
                     g_free(name);
                 }
-
                 sp_edit_select_all(dt);
                 sp_selection_duplicate(dt, true);
                 sp_selection_to_prev_layer(dt, true);
                 dt->setCurrentLayer(new_layer);
                 sp_edit_select_all(dt);
-
+#else
+                // Copies everything, regardless of locks, visibility, sublayers.
+                Inkscape::XML::Node *selected = dt->currentLayer()->repr;
+                Inkscape::XML::Node *parent = sp_repr_parent(selected);
+                Inkscape::XML::Node *dup = selected->duplicate(parent->document());
+                parent->addChild(dup, selected);
+                SPObject *new_layer = dt->currentLayer()->next;
+                if (new_layer) {
+                    if (new_layer->label()) {
+                        gchar* name = g_strdup_printf(_("%s copy"), new_layer->label());
+                        dt->layer_manager->renameLayer( new_layer, name, TRUE );
+                        g_free(name);
+                    }
+                    dt->setCurrentLayer(new_layer);
+                }
+#endif
                 sp_document_done(sp_desktop_document(dt), SP_VERB_LAYER_DUPLICATE,
                                  _("Duplicate layer"));