1 /* === S Y N F I G ========================================================= */
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 ======================================================= */
33 #include <synfigapp/canvasinterface.h>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerAdd);
48 ACTION_SET_NAME(Action::LayerAdd,"layer_add");
49 ACTION_SET_LOCAL_NAME(Action::LayerAdd,N_("Add Layer"));
50 ACTION_SET_TASK(Action::LayerAdd,"add");
51 ACTION_SET_CATEGORY(Action::LayerAdd,Action::CATEGORY_LAYER);
52 ACTION_SET_PRIORITY(Action::LayerAdd,0);
53 ACTION_SET_VERSION(Action::LayerAdd,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerAdd,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::LayerAdd::LayerAdd()
67 Action::LayerAdd::get_local_name()const
70 return strprintf("%s '%s'", _("Add Layer"), layer->get_local_name().c_str());
72 return _("Add Layer");
76 Action::LayerAdd::get_param_vocab()
78 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80 ret.push_back(ParamDesc("new",Param::TYPE_LAYER)
81 .set_local_name(_("New Layer"))
82 .set_desc(_("Layer to be added"))
89 Action::LayerAdd::is_candidate(const ParamList &x)
91 return candidate_check(get_param_vocab(),x);
95 Action::LayerAdd::set_param(const synfig::String& name, const Action::Param ¶m)
97 if(name=="new" && param.get_type()==Param::TYPE_LAYER)
99 layer=param.get_layer();
104 return Action::CanvasSpecific::set_param(name,param);
108 Action::LayerAdd::is_ready()const
112 return Action::CanvasSpecific::is_ready();
116 Action::LayerAdd::perform()
118 // Set the layer's canvas
119 layer->set_canvas(get_canvas());
121 // Push the layer onto the front of the canvas
122 get_canvas()->push_front(layer);
124 // Mark ourselves as dirty if necessary
125 //set_dirty(layer->active());
127 // Signal that a layer has been inserted
128 if(get_canvas_interface())
130 get_canvas_interface()->signal_layer_inserted()(layer,0);
132 else synfig::warning("CanvasInterface not set on action");
136 Action::LayerAdd::undo()
138 // Find the iterator for the layer
139 Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),layer);
141 // If we couldn't find the layer in the canvas, then bail
143 throw Error(_("This layer doesn't exist anymore."));
145 // Remove the layer from the canvas
146 get_canvas()->erase(iter);
148 // Mark ourselves as dirty if necessary
149 //set_dirty(layer->active());
151 // Signal that a layer has been inserted
152 if(get_canvas_interface())
154 get_canvas_interface()->signal_layer_removed()(layer);
156 else synfig::warning("CanvasInterface not set on action");