Get the waypoints in the Children panel's timetrack to respond to mouse events.
[synfig.git] / synfig-studio / trunk / src / gtkmm / layeractionmanager.cpp
index 59ea0dd..34d7f20 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
 
 #include "layeractionmanager.h"
 #include "layertree.h"
+#include <synfig/context.h>
 #include <synfigapp/action_param.h>
 #include "instance.h"
 #include <synfigapp/selectionmanager.h>
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -228,7 +232,7 @@ LayerActionManager::refresh()
        }
 
 
-       String ui_info;
+       String ui_info, ui_toolbar_info;
 
        action_paste_->set_sensitive(!clipboard_.empty());
        action_group_->add(action_paste_);
@@ -284,30 +288,38 @@ LayerActionManager::refresh()
                        {
                                action_group_->add(Gtk::Action::create(
                                        "select-all-child-layers",
-                                       _("Select All Child Layers")
-                               ),
-                                       sigc::bind(
-                                               sigc::mem_fun(
-                                                       *layer_tree_,
-                                                       &studio::LayerTree::select_all_children_layers
-                                               ),
-                                               Layer::LooseHandle(layer)
-                                       )
-                               );
+                                       Gtk::StockID("synfig-select_all_child_layers"),
+                                       _("Select All Child Layers"),
+                                       _("Select All Child Layers")),
+                                       sigc::bind(sigc::mem_fun(*layer_tree_,
+                                                                                        &studio::LayerTree::select_all_children_layers),
+                                                          Layer::LooseHandle(layer)));
                                ui_info+="<menuitem action='select-all-child-layers'/>";
+                               ui_toolbar_info+="<toolbar action='toolbar-layer'><toolitem action='select-all-child-layers'/></toolbar>";
                        }
                        handle<studio::Instance>::cast_static(get_canvas_interface()->get_instance())->
                                add_actions_to_group(action_group_, ui_info,   param_list, synfigapp::Action::CATEGORY_LAYER);
                }
        }
 
-       ui_info="<ui><popup action='menu-main'><menu action='menu-layer'>"+ui_info+"<separator/><menuitem action='cut' /><menuitem action='copy' /><menuitem action='paste' /><separator/></menu></popup></ui>";
+       ui_info=("<ui>"
+                          "<popup action='menu-main'>"
+                            "<menu action='menu-layer'>" +
+                                  ui_info +
+                                  "<separator/>"
+                              "<menuitem action='cut' />"
+                                  "<menuitem action='copy' />"
+                                  "<menuitem action='paste' />"
+                                  "<separator/>"
+                            "</menu>"
+                          "</popup>" +
+                        ui_toolbar_info +
+                        "</ui>");
        popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
 #ifdef ONE_ACTION_GROUP
 #else
        get_ui_manager()->insert_action_group(action_group_);
 #endif
-       DEBUGPOINT();
 }
 
 void
@@ -381,7 +393,8 @@ LayerActionManager::paste()
                        return;
                }
 
-               synfig::info("DEPTH=%d",depth);
+               // synfig::info("DEPTH=%d",depth);
+
                // Action to move the layer (if necessary)
                if(depth>0)
                {
@@ -411,12 +424,61 @@ LayerActionManager::paste()
                        }
                }
                depth++;
+
+               // automatically export the Index parameter of Duplicate layers when pasting
+               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);