Code

Added duplicate layer command. Fixes bug #171246.
authorjoncruz <joncruz@users.sourceforge.net>
Sat, 14 Jun 2008 08:08:21 +0000 (08:08 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Sat, 14 Jun 2008 08:08:21 +0000 (08:08 +0000)
src/dialogs/layers-panel.cpp
src/menus-skeleton.h
src/selection-chemistry.cpp
src/selection-chemistry.h
src/verbs.cpp
src/verbs.h

index ebb6d989d2086a7bd86259f8356dad284ab15da9..d54fb6fc770f6e48e175f35fee472c59f1530e7f 100644 (file)
@@ -62,7 +62,7 @@ enum {
     BUTTON_BOTTOM,
     BUTTON_UP,
     BUTTON_DOWN,
-//    BUTTON_DUPLICATE,
+    BUTTON_DUPLICATE,
     BUTTON_DELETE,
     BUTTON_SOLO
 };
@@ -350,6 +350,11 @@ bool LayersPanel::_executeAction()
                 _fireAction( SP_VERB_LAYER_LOWER );
             }
             break;
+            case BUTTON_DUPLICATE:
+            {
+                _fireAction( SP_VERB_LAYER_DUPLICATE );
+            }
+            break;
             case BUTTON_DELETE:
             {
                 _fireAction( SP_VERB_LAYER_DELETE );
@@ -781,6 +786,7 @@ LayersPanel::LayersPanel() :
     // -------------------------------------------------------
     {
         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
+        _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_DUPLICATE, 0, "Duplicate", (int)BUTTON_DUPLICATE ) );
         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
 
index 02c81adcf5cad0c5e196081fb21d73c0c632eb20..4ae213bc012811cc8a4706e7b89d9c2c067fdf9a 100644 (file)
@@ -136,6 +136,7 @@ static char const menus_skeleton[] =
 "   </submenu>\n"
 "   <submenu name=\"" N_("_Layer") "\">\n"
 "       <verb verb-id=\"LayerNew\" />\n"
+"       <verb verb-id=\"LayerDuplicate\" />\n"
 "       <verb verb-id=\"LayerRename\" />\n"
 "       <separator/>\n"
 "       <verb verb-id=\"LayerNext\" />\n"
index f35e28f9a7bce8acf7212cae82a8b777bc793186..0f92f96805aa93f1907f795fe1b2000d3c48cba8 100644 (file)
@@ -221,7 +221,7 @@ void sp_selection_delete()
 }
 
 /* fixme: sequencing */
-void sp_selection_duplicate()
+void sp_selection_duplicate(bool suppressDone)
 {
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
     if (desktop == NULL)
@@ -256,8 +256,10 @@ void sp_selection_duplicate()
         Inkscape::GC::release(copy);
     }
 
-    sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE,
-                     _("Duplicate"));
+    if ( !suppressDone ) {
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE,
+                         _("Duplicate"));
+    }
 
     selection->setReprList(newsel);
 
@@ -960,7 +962,7 @@ void sp_selection_paste_size_separately (bool apply_x, bool apply_y)
                      _("Paste size separately"));
 }
 
-void sp_selection_to_next_layer ()
+void sp_selection_to_next_layer(bool suppressDone)
 {
     SPDesktop *dt = SP_ACTIVE_DESKTOP;
 
@@ -992,8 +994,10 @@ void sp_selection_to_next_layer ()
         g_slist_free (copied);
         if (temp_clip) g_slist_free (temp_clip);
         if (next) dt->setCurrentLayer(next);
-        sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_NEXT,
-                         _("Raise to next layer"));
+        if ( !suppressDone ) {
+            sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_NEXT,
+                             _("Raise to next layer"));
+        }
     } else {
         no_more = true;
     }
@@ -1005,7 +1009,7 @@ void sp_selection_to_next_layer ()
     g_slist_free ((GSList *) items);
 }
 
-void sp_selection_to_prev_layer ()
+void sp_selection_to_prev_layer(bool suppressDone)
 {
     SPDesktop *dt = SP_ACTIVE_DESKTOP;
 
@@ -1037,8 +1041,10 @@ void sp_selection_to_prev_layer ()
         g_slist_free (copied);
         if (temp_clip) g_slist_free (temp_clip);
         if (next) dt->setCurrentLayer(next);
-        sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_PREV,
-                         _("Lower to previous layer"));
+        if ( !suppressDone ) {
+            sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_PREV,
+                             _("Lower to previous layer"));
+        }
     } else {
         no_more = true;
     }
index e5b2d9ef1d6af901f829b0866e023cf10bd12578..aa3c2b10054706661bb6949c3ce8f1df3b961f7f 100644 (file)
@@ -29,7 +29,7 @@ namespace LivePathEffect {
 class SPCSSAttr;
 
 void sp_selection_delete();
-void sp_selection_duplicate();
+void sp_selection_duplicate(bool suppressDone = false);
 void sp_edit_clear_all();
 
 void sp_edit_select_all();
@@ -71,8 +71,8 @@ void sp_set_style_clipboard (SPCSSAttr *css);
 void sp_selection_paste_size(bool apply_x, bool apply_y);
 void sp_selection_paste_size_separately(bool apply_x, bool apply_y);
 
-void sp_selection_to_next_layer ();
-void sp_selection_to_prev_layer ();
+void sp_selection_to_next_layer( bool suppressDone = false );
+void sp_selection_to_prev_layer( bool suppressDone = false );
 
 void sp_selection_apply_affine(Inkscape::Selection *selection, NR::Matrix const &affine, bool set_i2d = true);
 void sp_selection_remove_transform (void);
index a362d3c0f9e3678901c64648b3e6be595c61b7a3..4d859bab712c2f069fa40395a2e4dffcd6504899 100644 (file)
@@ -37,6 +37,7 @@
 #include <gtkmm/filechooserdialog.h>
 #include <gtkmm/stock.h>
 
+#include "layer-manager.h"
 #include "dialogs/text-edit.h"
 #include "dialogs/xml-tree.h"
 #include "dialogs/item-properties.h"
@@ -1219,6 +1220,31 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
 
             break;
         }
+        case SP_VERB_LAYER_DUPLICATE: {
+            if ( dt->currentLayer() != dt->currentRoot() ) {
+                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 );
+                    g_free(name);
+                }
+
+                sp_edit_select_all();
+                sp_selection_duplicate(true);
+                sp_selection_to_prev_layer(true);
+                dt->setCurrentLayer(new_layer);
+                sp_edit_select_all();
+
+                sp_document_done(sp_desktop_document(dt), SP_VERB_LAYER_DUPLICATE,
+                                 _("Duplicate layer"));
+                
+                // TRANSLATORS: this means "The layer has been duplicated."
+                dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Duplicated layer."));
+            } else {
+                dt->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No current layer."));
+            }
+            break;
+        }
         case SP_VERB_LAYER_DELETE: {
             if ( dt->currentLayer() != dt->currentRoot() ) {
                 sp_desktop_selection(dt)->clear();
@@ -2379,9 +2405,11 @@ Verb *Verb::_base_verbs[] = {
                   N_("Raise the current layer"), "raise_layer"),
     new LayerVerb(SP_VERB_LAYER_LOWER, "LayerLower", N_("_Lower Layer"),
                   N_("Lower the current layer"), "lower_layer"),
+    new LayerVerb(SP_VERB_LAYER_DUPLICATE, "LayerDuplicate", N_("Duplicate Current Layer..."),
+                  N_("Duplicate an existing layer"), 0),
     new LayerVerb(SP_VERB_LAYER_DELETE, "LayerDelete", N_("_Delete Current Layer"),
                   N_("Delete the current layer"), "delete_layer"),
-    new LayerVerb(SP_VERB_LAYER_SOLO, "LayerSolo", N_("_Solo Current Layer"),
+    new LayerVerb(SP_VERB_LAYER_SOLO, "LayerSolo", N_("_Show/hide other layers"),
                   N_("Solo the current layer"), 0),
 
     /* Object */
index 198a25521de91d0efc4a296112f013d37cdeebab..c1611092221f323d5300a72e0bb16a5b3fbd6265 100644 (file)
@@ -128,6 +128,7 @@ enum {
     SP_VERB_LAYER_TO_BOTTOM,
     SP_VERB_LAYER_RAISE,
     SP_VERB_LAYER_LOWER,
+    SP_VERB_LAYER_DUPLICATE,
     SP_VERB_LAYER_DELETE,
     SP_VERB_LAYER_SOLO,
     /* Object */