1 /* === S Y N F I G ========================================================= */
2 /*! \file action_layerremove.cpp
3 ** \brief Template File
5 ** $Id: layerremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "layerremove.h"
32 #include <synfigapp/canvasinterface.h>
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
44 ACTION_INIT(Action::LayerRemove);
45 ACTION_SET_NAME(Action::LayerRemove,"layer_remove");
46 ACTION_SET_LOCAL_NAME(Action::LayerRemove,"Remove Layer");
47 ACTION_SET_TASK(Action::LayerRemove,"remove");
48 ACTION_SET_CATEGORY(Action::LayerRemove,Action::CATEGORY_LAYER);
49 ACTION_SET_PRIORITY(Action::LayerRemove,0);
50 ACTION_SET_VERSION(Action::LayerRemove,"0.0");
51 ACTION_SET_CVS_ID(Action::LayerRemove,"$Id: layerremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 Action::LayerRemove::LayerRemove()
64 Action::LayerRemove::get_param_vocab()
66 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
69 .set_local_name(_("Layer"))
70 .set_desc(_("Layer to be deleted"))
71 .set_supports_multiple()
78 Action::LayerRemove::is_canidate(const ParamList &x)
80 return canidate_check(get_param_vocab(),x);
84 Action::LayerRemove::set_param(const synfig::String& name, const Action::Param ¶m)
86 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
88 std::pair<synfig::Layer::Handle,int> layer_pair;
89 layer_pair.first=param.get_layer();
90 layer_list.push_back(layer_pair);
95 return Action::CanvasSpecific::set_param(name,param);
99 Action::LayerRemove::is_ready()const
101 if(layer_list.empty())
103 return Action::CanvasSpecific::is_ready();
107 Action::LayerRemove::perform()
109 std::list<std::pair<synfig::Layer::Handle,int> >::iterator iter;
110 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
112 Layer::Handle layer(iter->first);
113 // int& depth(iter->second);
114 Canvas::Handle subcanvas(layer->get_canvas());
116 // Find the iterator for the layer
117 Canvas::iterator iter2=find(subcanvas->begin(),subcanvas->end(),layer);
119 // If we couldn't find the layer in the canvas, then bail
122 /*! \fixme We should really undo all prior removals
123 ** before we go throwing shit around */
124 throw Error(_("This layer doesn't exist anymore."));
127 // If the subcanvas isn't the same as the canvas,
128 // then it had better be an inline canvas. If not,
130 if(get_canvas()!=subcanvas && !subcanvas->is_inline())
132 /*! \fixme We should really undo all prior removals
133 ** before we go throwing shit around */
134 throw Error(_("This layer doesn't belong to this canvas anymore"));
137 set_canvas(subcanvas);
139 // Calculate the depth that the layer was at (For the undo)
140 iter->second=layer->get_depth();
142 // Mark ourselves as dirty if necessary
143 set_dirty(layer->active());
145 // Remove the layer from the canvas
146 subcanvas->erase(iter2);
148 // Signal that a layer has been removed
149 if(get_canvas_interface())
150 get_canvas_interface()->signal_layer_removed()(layer);
155 Action::LayerRemove::undo()
157 std::list<std::pair<synfig::Layer::Handle,int> >::reverse_iterator iter;
158 for(iter=layer_list.rbegin();iter!=layer_list.rend();++iter)
160 Layer::Handle layer(iter->first);
161 int& depth(iter->second);
163 // Set the layer's canvas
164 layer->set_canvas(get_canvas());
166 // Make sure that the depth is valid
167 if(get_canvas()->size()<depth)
168 depth=get_canvas()->size();
170 // Mark ourselves as dirty if necessary
171 set_dirty(layer->active());
173 // Insert the layer into the canvas at the desired depth
174 get_canvas()->insert(get_canvas()->begin()+depth,layer);
176 // Signal that a layer has been inserted
177 if(get_canvas_interface())
178 get_canvas_interface()->signal_layer_inserted()(layer,depth);