Fix 1894723: export the Index parameter of all Duplicate layers when copy/pasting...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sat, 16 Feb 2008 04:56:38 +0000 (04:56 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sat, 16 Feb 2008 04:56:38 +0000 (04:56 +0000)
git-svn-id: http://svn.voria.com/code@1711 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-studio/trunk/src/gtkmm/layeractionmanager.cpp
synfig-studio/trunk/src/gtkmm/layeractionmanager.h
synfig-studio/trunk/src/synfigapp/actions/layerduplicate.cpp
synfig-studio/trunk/src/synfigapp/actions/layerduplicate.h

index 86addd6..34d7f20 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "layeractionmanager.h"
 #include "layertree.h"
+#include <synfig/context.h>
 #include <synfigapp/action_param.h>
 #include "instance.h"
 #include <synfigapp/selectionmanager.h>
@@ -425,26 +426,59 @@ LayerActionManager::paste()
                depth++;
 
                // automatically export the Index parameter of Duplicate layers when pasting
-               if (layer->get_name() == "duplicate")
-                       for (int i = 1; ; i++)
-                       {
-                               String name = strprintf(_("Index %d"), i);
-                               try
-                               {
-                                       canvas->find_value_node(name);
-                               }
-                               catch (Exception::IDNotFound x)
-                               {
-                                       get_canvas_interface()->add_value_node(layer->dynamic_param_list().find("index")->second, name);
-                                       break;
-                               }
-                       }
+               int index = 1;
+               export_dup_nodes(layer, canvas, index);
        }
        get_canvas_interface()->get_selection_manager()->clear_selected_layers();
        get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
 }
 
 void
+LayerActionManager::export_dup_nodes(synfig::Layer::Handle layer, Canvas::Handle canvas, int &index)
+{
+       // automatically export the Index parameter of Duplicate layers when pasting
+       if (layer->get_name() == "duplicate")
+               while (true)
+               {
+                       String name = strprintf(_("Index %d"), index++);
+                       try
+                       {
+                               canvas->find_value_node(name);
+                       }
+                       catch (Exception::IDNotFound x)
+                       {
+                               get_canvas_interface()->add_value_node(layer->dynamic_param_list().find("index")->second, name);
+                               break;
+                       }
+               }
+       else
+       {
+               Layer::ParamList param_list(layer->get_param_list());
+               for (Layer::ParamList::const_iterator iter(param_list.begin())
+                                ; iter != param_list.end()
+                                ; iter++)
+                       if (layer->dynamic_param_list().count(iter->first)==0 && iter->second.get_type()==ValueBase::TYPE_CANVAS)
+                       {
+                               Canvas::Handle subcanvas(iter->second.get(Canvas::Handle()));
+                               if (subcanvas && subcanvas->is_inline())
+                                       for (Context iter = subcanvas->get_context(); iter != subcanvas->end(); iter++)
+                                               export_dup_nodes(*iter, canvas, index);
+                       }
+
+               for (Layer::DynamicParamList::const_iterator iter(layer->dynamic_param_list().begin())
+                                ; iter != layer->dynamic_param_list().end()
+                                ; iter++)
+                       if (iter->second->get_type()==ValueBase::TYPE_CANVAS)
+                       {
+                               Canvas::Handle canvas((*iter->second)(0).get(Canvas::Handle()));
+                               if (canvas->is_inline())
+                                       //! \todo do we need to implement this?  and if so, shouldn't we check all canvases, not just the one at t=0s?
+                                       warning("%s:%d not yet implemented - do we need to export duplicate valuenodes in dynamic canvas parameters?", __FILE__, __LINE__);
+                       }
+       }
+}
+
+void
 LayerActionManager::amount_inc()
 {
        float adjust(0.1);
index bde377d..0e9305a 100644 (file)
@@ -76,6 +76,7 @@ class LayerActionManager
        void cut();
        void copy();
        void paste();
+       void export_dup_nodes(synfig::Layer::Handle, synfig::Canvas::Handle, int &);
 
        void amount_inc();
        void amount_dec();
index 530dc84..115d631 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "layerduplicate.h"
 #include "layeradd.h"
+#include <synfig/context.h>
 #include <synfigapp/canvasinterface.h>
 
 #include <synfigapp/general.h>
@@ -162,27 +163,60 @@ Action::LayerDuplicate::prepare()
                }
 
                // automatically export the Index parameter of Duplicate layers when duplicating
-               if (new_layer->get_name() == "duplicate")
-                       for (int i = 1; ; i++)
+               int index = 1;
+               export_dup_nodes(new_layer, subcanvas, index);
+       }
+}
+
+void
+Action::LayerDuplicate::export_dup_nodes(synfig::Layer::Handle layer, Canvas::Handle canvas, int &index)
+{
+       // automatically export the Index parameter of Duplicate layers when duplicating
+       if (layer->get_name() == "duplicate")
+               while (true)
+               {
+                       String name = strprintf(_("Index %d"), index++);
+                       try
+                       {
+                               canvas->find_value_node(name);
+                       }
+                       catch (Exception::IDNotFound x)
+                       {
+                               Action::Handle action(Action::create("value_node_add"));
+
+                               action->set_param("canvas",canvas);
+                               action->set_param("canvas_interface",get_canvas_interface());
+                               action->set_param("new",layer->dynamic_param_list().find("index")->second);
+                               action->set_param("name",name);
+
+                               add_action_front(action);
+
+                               break;
+                       }
+               }
+       else
+       {
+               Layer::ParamList param_list(layer->get_param_list());
+               for (Layer::ParamList::const_iterator iter(param_list.begin())
+                                ; iter != param_list.end()
+                                ; iter++)
+                       if (layer->dynamic_param_list().count(iter->first)==0 && iter->second.get_type()==ValueBase::TYPE_CANVAS)
+                       {
+                               Canvas::Handle subcanvas(iter->second.get(Canvas::Handle()));
+                               if (subcanvas && subcanvas->is_inline())
+                                       for (Context iter = subcanvas->get_context(); iter != subcanvas->end(); iter++)
+                                               export_dup_nodes(*iter, canvas, index);
+                       }
+
+               for (Layer::DynamicParamList::const_iterator iter(layer->dynamic_param_list().begin())
+                                ; iter != layer->dynamic_param_list().end()
+                                ; iter++)
+                       if (iter->second->get_type()==ValueBase::TYPE_CANVAS)
                        {
-                               String name = strprintf(_("Index %d"), i);
-                               try
-                               {
-                                       subcanvas->find_value_node(name);
-                               }
-                               catch (Exception::IDNotFound x)
-                               {
-                                       Action::Handle action(Action::create("value_node_add"));
-
-                                       action->set_param("canvas",subcanvas);
-                                       action->set_param("canvas_interface",get_canvas_interface());
-                                       action->set_param("new",new_layer->dynamic_param_list().find("index")->second);
-                                       action->set_param("name",name);
-
-                                       add_action_front(action);
-
-                                       break;
-                               }
+                               Canvas::Handle canvas((*iter->second)(0).get(Canvas::Handle()));
+                               if (canvas->is_inline())
+                                       //! \todo do we need to implement this?  and if so, shouldn't we check all canvases, not just the one at t=0s?
+                                       warning("%s:%d not yet implemented - do we need to export duplicate valuenodes in dynamic canvas parameters?", __FILE__, __LINE__);
                        }
        }
 }
index 65c2558..1aba3a5 100644 (file)
@@ -62,6 +62,8 @@ public:
 
        virtual void prepare();
 
+       void export_dup_nodes(synfig::Layer::Handle, synfig::Canvas::Handle, int &);
+
        ACTION_MODULE_EXT
 };