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 ========================================================= */
47 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerActivate);
48 ACTION_SET_NAME(Action::LayerActivate,"layer_activate");
49 ACTION_SET_LOCAL_NAME(Action::LayerActivate,N_("Activate Layer"));
50 ACTION_SET_TASK(Action::LayerActivate,"activate");
51 ACTION_SET_CATEGORY(Action::LayerActivate,Action::CATEGORY_LAYER);
52 ACTION_SET_PRIORITY(Action::LayerActivate,0);
53 ACTION_SET_VERSION(Action::LayerActivate,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerActivate,"$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::LayerActivate::LayerActivate()
67 Action::LayerActivate::get_local_name()const
70 return _("Activate Layer");
72 if(layer->get_description().empty())
73 name=layer->get_local_name();
75 name=layer->get_description();
77 return (new_status?_("Activate "):_("Deactivate "))+name;
81 Action::LayerActivate::get_param_vocab()
83 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
85 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
86 .set_local_name(_("Layer"))
89 ret.push_back(ParamDesc("new_status",Param::TYPE_BOOL)
90 .set_local_name(_("New Status"))
91 .set_desc(_("The new status of the layer"))
98 Action::LayerActivate::is_candidate(const ParamList &x)
100 return candidate_check(get_param_vocab(),x);
104 Action::LayerActivate::set_param(const synfig::String& name, const Action::Param ¶m)
106 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
108 layer=param.get_layer();
113 if(name=="new_status" && param.get_type()==Param::TYPE_BOOL)
115 new_status=param.get_bool();
120 return Action::CanvasSpecific::set_param(name,param);
124 Action::LayerActivate::is_ready()const
128 return Action::CanvasSpecific::is_ready();
132 Action::LayerActivate::perform()
134 Canvas::Handle subcanvas(layer->get_canvas());
136 // Find the iterator for the layer
137 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
139 // If we couldn't find the layer in the canvas, then bail
141 throw Error(_("This layer doesn't exist anymore."));
143 // If the subcanvas isn't the same as the canvas,
144 // then it had better be an inline canvas. If not,
146 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
147 //if(get_canvas()->get_root()!=subcanvas->get_root())
148 // throw Error(_("This layer doesn't belong to this composition"));
150 old_status=layer->active();
152 // If we are changing the status to what it already is,
153 // the go ahead and return
154 if(new_status==old_status)
167 if(get_canvas_interface())
169 get_canvas_interface()->signal_layer_status_changed()(layer,new_status);
171 else synfig::warning("CanvasInterface not set on action");
175 Action::LayerActivate::undo()
177 // If we are changing the status to what it already is,
178 // the go ahead and return
179 if(new_status==old_status)
187 // restore the old status
193 if(get_canvas_interface())
195 get_canvas_interface()->signal_layer_status_changed()(layer,old_status);
197 else synfig::warning("CanvasInterface not set on action");