1 /* === S Y N F I G ========================================================= */
2 /*! \file layeractivate.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 "layeractivate.h"
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 ========================================================= */
46 #define ACTION_INIT2(class) \
47 Action::Base* class::create() { return new class(); } \
48 synfig::String class::get_name()const { return name__; }
50 ACTION_INIT2(Action::LayerActivate);
51 ACTION_SET_NAME(Action::LayerActivate,"layer_activate");
52 ACTION_SET_LOCAL_NAME(Action::LayerActivate,N_("Activate Layer"));
53 ACTION_SET_TASK(Action::LayerActivate,"activate");
54 ACTION_SET_CATEGORY(Action::LayerActivate,Action::CATEGORY_LAYER);
55 ACTION_SET_PRIORITY(Action::LayerActivate,0);
56 ACTION_SET_VERSION(Action::LayerActivate,"0.0");
57 ACTION_SET_CVS_ID(Action::LayerActivate,"$Id$");
59 /* === G L O B A L S ======================================================= */
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 Action::LayerActivate::LayerActivate()
70 Action::LayerActivate::get_local_name()const
73 return _("Activate Layer");
75 if(layer->get_description().empty())
76 name=layer->get_local_name();
78 name=layer->get_description();
80 return (new_status?_("Activate "):_("Deactivate "))+name;
84 Action::LayerActivate::get_param_vocab()
86 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
88 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
89 .set_local_name(_("Layer"))
92 ret.push_back(ParamDesc("new_status",Param::TYPE_BOOL)
93 .set_local_name(_("New Status"))
94 .set_desc(_("The new status of the layer"))
101 Action::LayerActivate::is_candidate(const ParamList &x)
103 return candidate_check(get_param_vocab(),x);
107 Action::LayerActivate::set_param(const synfig::String& name, const Action::Param ¶m)
109 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
111 layer=param.get_layer();
116 if(name=="new_status" && param.get_type()==Param::TYPE_BOOL)
118 new_status=param.get_bool();
123 return Action::CanvasSpecific::set_param(name,param);
127 Action::LayerActivate::is_ready()const
131 return Action::CanvasSpecific::is_ready();
135 Action::LayerActivate::perform()
137 Canvas::Handle subcanvas(layer->get_canvas());
139 // Find the iterator for the layer
140 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->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 // If the subcanvas isn't the same as the canvas,
147 // then it had better be an inline canvas. If not,
149 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
150 //if(get_canvas()->get_root()!=subcanvas->get_root())
151 // throw Error(_("This layer doesn't belong to this composition"));
153 old_status=layer->active();
155 // If we are changing the status to what it already is,
156 // the go ahead and return
157 if(new_status==old_status)
170 if(get_canvas_interface())
172 get_canvas_interface()->signal_layer_status_changed()(layer,new_status);
174 else synfig::warning("CanvasInterface not set on action");
178 Action::LayerActivate::undo()
180 // If we are changing the status to what it already is,
181 // the go ahead and return
182 if(new_status==old_status)
190 // restore the old status
196 if(get_canvas_interface())
198 get_canvas_interface()->signal_layer_status_changed()(layer,old_status);
200 else synfig::warning("CanvasInterface not set on action");