Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc3 / src / synfigapp / actions / layeradd.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layeradd.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "layeradd.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
45 ACTION_INIT(Action::LayerAdd);
46 ACTION_SET_NAME(Action::LayerAdd,"layer_add");
47 ACTION_SET_LOCAL_NAME(Action::LayerAdd,"Add Layer");
48 ACTION_SET_TASK(Action::LayerAdd,"add");
49 ACTION_SET_CATEGORY(Action::LayerAdd,Action::CATEGORY_LAYER);
50 ACTION_SET_PRIORITY(Action::LayerAdd,0);
51 ACTION_SET_VERSION(Action::LayerAdd,"0.0");
52 ACTION_SET_CVS_ID(Action::LayerAdd,"$Id$");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::LayerAdd::LayerAdd()
61 {
62 }
63
64 Action::ParamVocab
65 Action::LayerAdd::get_param_vocab()
66 {
67         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68
69         ret.push_back(ParamDesc("new",Param::TYPE_LAYER)
70                 .set_local_name(_("New Layer"))
71                 .set_desc(_("Layer to be added"))
72         );
73
74         return ret;
75 }
76
77 bool
78 Action::LayerAdd::is_candidate(const ParamList &x)
79 {
80         return candidate_check(get_param_vocab(),x);
81 }
82
83 bool
84 Action::LayerAdd::set_param(const synfig::String& name, const Action::Param &param)
85 {
86         if(name=="new" && param.get_type()==Param::TYPE_LAYER)
87         {
88                 layer=param.get_layer();
89
90                 return true;
91         }
92
93         return Action::CanvasSpecific::set_param(name,param);
94 }
95
96 bool
97 Action::LayerAdd::is_ready()const
98 {
99         if(!layer)
100                 return false;
101         return Action::CanvasSpecific::is_ready();
102 }
103
104 void
105 Action::LayerAdd::perform()
106 {
107         // Set the layer's canvas
108         layer->set_canvas(get_canvas());
109
110         // Push the layer onto the front of the canvas
111         get_canvas()->push_front(layer);
112
113         // Mark ourselves as dirty if necessary
114         //set_dirty(layer->active());
115
116         // Signal that a layer has been inserted
117         if(get_canvas_interface())
118         {
119                 get_canvas_interface()->signal_layer_inserted()(layer,0);
120         }
121         else synfig::warning("CanvasInterface not set on action");
122 }
123
124 void
125 Action::LayerAdd::undo()
126 {
127         // Find the iterator for the layer
128         Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),layer);
129
130         // If we couldn't find the layer in the canvas, then bail
131         if(*iter!=layer)
132                 throw Error(_("This layer doesn't exist anymore."));
133
134         // Remove the layer from the canvas
135         get_canvas()->erase(iter);
136
137         // Mark ourselves as dirty if necessary
138         //set_dirty(layer->active());
139
140         // Signal that a layer has been inserted
141         if(get_canvas_interface())
142         {
143                 get_canvas_interface()->signal_layer_removed()(layer);
144         }
145         else synfig::warning("CanvasInterface not set on action");
146 }