1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include <synfigapp/canvasinterface.h>
36 #include <synfigapp/general.h>
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerAdd);
49 ACTION_SET_NAME(Action::LayerAdd,"layer_add");
50 ACTION_SET_LOCAL_NAME(Action::LayerAdd,N_("Add Layer"));
51 ACTION_SET_TASK(Action::LayerAdd,"add");
52 ACTION_SET_CATEGORY(Action::LayerAdd,Action::CATEGORY_LAYER);
53 ACTION_SET_PRIORITY(Action::LayerAdd,0);
54 ACTION_SET_VERSION(Action::LayerAdd,"0.0");
55 ACTION_SET_CVS_ID(Action::LayerAdd,"$Id$");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::LayerAdd::LayerAdd()
68 Action::LayerAdd::get_local_name()const
71 return strprintf("%s '%s'", _("Add Layer"), layer->get_local_name().c_str());
73 return _("Add Layer");
77 Action::LayerAdd::get_param_vocab()
79 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
81 ret.push_back(ParamDesc("new",Param::TYPE_LAYER)
82 .set_local_name(_("New Layer"))
83 .set_desc(_("Layer to be added"))
90 Action::LayerAdd::is_candidate(const ParamList &x)
92 return candidate_check(get_param_vocab(),x);
96 Action::LayerAdd::set_param(const synfig::String& name, const Action::Param ¶m)
98 if(name=="new" && param.get_type()==Param::TYPE_LAYER)
100 layer=param.get_layer();
105 return Action::CanvasSpecific::set_param(name,param);
109 Action::LayerAdd::is_ready()const
113 return Action::CanvasSpecific::is_ready();
117 Action::LayerAdd::perform()
119 // Set the layer's canvas
120 layer->set_canvas(get_canvas());
122 // Push the layer onto the front of the canvas
123 get_canvas()->push_front(layer);
125 // Mark ourselves as dirty if necessary
126 //set_dirty(layer->active());
128 // Signal that a layer has been inserted
129 if(get_canvas_interface())
131 get_canvas_interface()->signal_layer_inserted()(layer,0);
133 else synfig::warning("CanvasInterface not set on action");
137 Action::LayerAdd::undo()
139 // Find the iterator for the layer
140 Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),layer);
142 // If we couldn't find the layer in the canvas, then bail
144 throw Error(_("This layer doesn't exist anymore."));
146 // Remove the layer from the canvas
147 get_canvas()->erase(iter);
149 // Mark ourselves as dirty if necessary
150 //set_dirty(layer->active());
152 // Signal that a layer has been inserted
153 if(get_canvas_interface())
155 get_canvas_interface()->signal_layer_removed()(layer);
157 else synfig::warning("CanvasInterface not set on action");