1 /* === S Y N F I G ========================================================= */
2 /*! \file layerremove.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 "layerremove.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(Action::LayerRemove);
48 ACTION_SET_NAME(Action::LayerRemove,"layer_remove");
49 ACTION_SET_LOCAL_NAME(Action::LayerRemove,N_("Remove Layer"));
50 ACTION_SET_TASK(Action::LayerRemove,"remove");
51 ACTION_SET_CATEGORY(Action::LayerRemove,Action::CATEGORY_LAYER);
52 ACTION_SET_PRIORITY(Action::LayerRemove,0);
53 ACTION_SET_VERSION(Action::LayerRemove,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerRemove,"$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::LayerRemove::LayerRemove()
67 Action::LayerRemove::get_param_vocab()
69 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
72 .set_local_name(_("Layer"))
73 .set_desc(_("Layer to be deleted"))
74 .set_supports_multiple()
81 Action::LayerRemove::is_candidate(const ParamList &x)
83 return candidate_check(get_param_vocab(),x);
87 Action::LayerRemove::set_param(const synfig::String& name, const Action::Param ¶m)
89 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
91 std::pair<synfig::Layer::Handle,int> layer_pair;
92 layer_pair.first=param.get_layer();
93 layer_list.push_back(layer_pair);
98 return Action::CanvasSpecific::set_param(name,param);
102 Action::LayerRemove::is_ready()const
104 if(layer_list.empty())
106 return Action::CanvasSpecific::is_ready();
110 Action::LayerRemove::perform()
112 std::list<std::pair<synfig::Layer::Handle,int> >::iterator iter;
113 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
115 Layer::Handle layer(iter->first);
116 // int& depth(iter->second);
117 Canvas::Handle subcanvas(layer->get_canvas());
119 // Find the iterator for the layer
120 Canvas::iterator iter2=find(subcanvas->begin(),subcanvas->end(),layer);
122 // If we couldn't find the layer in the canvas, then bail
125 /*! \todo We should really undo all prior removals
126 ** before we go throwing shit around */
127 throw Error(_("This layer doesn't exist anymore."));
130 // If the subcanvas isn't the same as the canvas,
131 // then it had better be an inline canvas. If not,
133 if(get_canvas()!=subcanvas && !subcanvas->is_inline())
135 /*! \todo We should really undo all prior removals
136 ** before we go throwing shit around */
137 throw Error(_("This layer doesn't belong to this canvas anymore"));
140 set_canvas(subcanvas);
142 // Calculate the depth that the layer was at (For the undo)
143 iter->second=layer->get_depth();
145 // Mark ourselves as dirty if necessary
146 set_dirty(layer->active());
148 // Remove the layer from the canvas
149 subcanvas->erase(iter2);
151 // Signal that a layer has been removed
152 if(get_canvas_interface())
153 get_canvas_interface()->signal_layer_removed()(layer);
158 Action::LayerRemove::undo()
160 std::list<std::pair<synfig::Layer::Handle,int> >::reverse_iterator iter;
161 for(iter=layer_list.rbegin();iter!=layer_list.rend();++iter)
163 Layer::Handle layer(iter->first);
164 int& depth(iter->second);
166 // Set the layer's canvas
167 layer->set_canvas(get_canvas());
169 // Make sure that the depth is valid
170 if(get_canvas()->size()<depth)
171 depth=get_canvas()->size();
173 // Mark ourselves as dirty if necessary
174 set_dirty(layer->active());
176 // Insert the layer into the canvas at the desired depth
177 get_canvas()->insert(get_canvas()->begin()+depth,layer);
179 // Signal that a layer has been inserted
180 if(get_canvas_interface())
181 get_canvas_interface()->signal_layer_inserted()(layer,depth);