Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / 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 **      Copyright (c) 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "layeradd.h"
34 #include <synfigapp/canvasinterface.h>
35
36 #include <synfigapp/general.h>
37
38 #endif
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
45
46 /* === M A C R O S ========================================================= */
47
48 ACTION_INIT_NO_GET_LOCAL_NAME(Action::LayerAdd);
49 ACTION_SET_NAME(Action::LayerAdd,"layer_add");
50 ACTION_SET_LOCAL_NAME(Action::LayerAdd,N_("Add Layer"));
51 ACTION_SET_TASK(Action::LayerAdd,"add");
52 ACTION_SET_CATEGORY(Action::LayerAdd,Action::CATEGORY_LAYER);
53 ACTION_SET_PRIORITY(Action::LayerAdd,0);
54 ACTION_SET_VERSION(Action::LayerAdd,"0.0");
55 ACTION_SET_CVS_ID(Action::LayerAdd,"$Id$");
56
57 /* === G L O B A L S ======================================================= */
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 Action::LayerAdd::LayerAdd()
64 {
65 }
66
67 synfig::String
68 Action::LayerAdd::get_local_name()const
69 {
70         if (layer)
71                 return strprintf("%s '%s'", _("Add Layer"), layer->get_local_name().c_str());
72         else
73                 return _("Add Layer");
74 }
75
76 Action::ParamVocab
77 Action::LayerAdd::get_param_vocab()
78 {
79         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80
81         ret.push_back(ParamDesc("new",Param::TYPE_LAYER)
82                 .set_local_name(_("New Layer"))
83                 .set_desc(_("Layer to be added"))
84         );
85
86         return ret;
87 }
88
89 bool
90 Action::LayerAdd::is_candidate(const ParamList &x)
91 {
92         return candidate_check(get_param_vocab(),x);
93 }
94
95 bool
96 Action::LayerAdd::set_param(const synfig::String& name, const Action::Param &param)
97 {
98         if(name=="new" && param.get_type()==Param::TYPE_LAYER)
99         {
100                 layer=param.get_layer();
101
102                 return true;
103         }
104
105         return Action::CanvasSpecific::set_param(name,param);
106 }
107
108 bool
109 Action::LayerAdd::is_ready()const
110 {
111         if(!layer)
112                 return false;
113         return Action::CanvasSpecific::is_ready();
114 }
115
116 void
117 Action::LayerAdd::perform()
118 {
119         // Set the layer's canvas
120         layer->set_canvas(get_canvas());
121
122         // Push the layer onto the front of the canvas
123         get_canvas()->push_front(layer);
124
125         // Mark ourselves as dirty if necessary
126         //set_dirty(layer->active());
127
128         // Signal that a layer has been inserted
129         if(get_canvas_interface())
130         {
131                 get_canvas_interface()->signal_layer_inserted()(layer,0);
132         }
133         else synfig::warning("CanvasInterface not set on action");
134 }
135
136 void
137 Action::LayerAdd::undo()
138 {
139         // Find the iterator for the layer
140         Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),layer);
141
142         // If we couldn't find the layer in the canvas, then bail
143         if(*iter!=layer)
144                 throw Error(_("This layer doesn't exist anymore."));
145
146         // Remove the layer from the canvas
147         get_canvas()->erase(iter);
148
149         // Mark ourselves as dirty if necessary
150         //set_dirty(layer->active());
151
152         // Signal that a layer has been inserted
153         if(get_canvas_interface())
154         {
155                 get_canvas_interface()->signal_layer_removed()(layer);
156         }
157         else synfig::warning("CanvasInterface not set on action");
158 }