1 /* === S Y N F I G ========================================================= */
2 /*! \file layerduplicate.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "layerduplicate.h"
34 #include <synfigapp/canvasinterface.h>
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
44 /* === M A C R O S ========================================================= */
46 ACTION_INIT(Action::LayerDuplicate);
47 ACTION_SET_NAME(Action::LayerDuplicate,"layer_duplicate");
48 ACTION_SET_LOCAL_NAME(Action::LayerDuplicate,"Duplicate Layer");
49 ACTION_SET_TASK(Action::LayerDuplicate,"duplicate");
50 ACTION_SET_CATEGORY(Action::LayerDuplicate,Action::CATEGORY_LAYER);
51 ACTION_SET_PRIORITY(Action::LayerDuplicate,0);
52 ACTION_SET_VERSION(Action::LayerDuplicate,"0.0");
53 ACTION_SET_CVS_ID(Action::LayerDuplicate,"$Id$");
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Action::LayerDuplicate::LayerDuplicate()
66 Action::LayerDuplicate::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
71 .set_local_name(_("Layer"))
72 .set_desc(_("Layer to be duplicated"))
73 .set_supports_multiple()
80 Action::LayerDuplicate::is_candidate(const ParamList &x)
82 return candidate_check(get_param_vocab(),x);
86 Action::LayerDuplicate::set_param(const synfig::String& name, const Action::Param ¶m)
88 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
90 layers.push_back(param.get_layer());
95 return Action::CanvasSpecific::set_param(name,param);
99 Action::LayerDuplicate::is_ready()const
103 return Action::CanvasSpecific::is_ready();
107 Action::LayerDuplicate::prepare()
112 std::list<synfig::Layer::Handle>::const_iterator iter;
114 for(iter=layers.begin();iter!=layers.end();++iter)
116 Layer::Handle layer(*iter);
118 Canvas::Handle subcanvas(layer->get_canvas());
120 // Find the iterator for the layer
121 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
123 // If we couldn't find the layer in the canvas, then bail
125 throw Error(_("This layer doesn't exist anymore."));
127 // If the subcanvas isn't the same as the canvas,
128 // then it had better be an inline canvas. If not,
130 if(get_canvas()!=subcanvas && !subcanvas->is_inline())
131 throw Error(_("This layer doesn't belong to this canvas anymore"));
133 Layer::Handle new_layer(layer->clone(guid));
136 Action::Handle action(Action::create("layer_move"));
138 action->set_param("canvas",subcanvas);
139 action->set_param("canvas_interface",get_canvas_interface());
140 action->set_param("layer",new_layer);
141 action->set_param("new_index",layers.front()->get_depth());
143 add_action_front(action);
146 Action::Handle action(Action::create("layer_add"));
148 action->set_param("canvas",subcanvas);
149 action->set_param("canvas_interface",get_canvas_interface());
150 action->set_param("new",new_layer);
152 add_action_front(action);