Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layeractivate.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layeractivate.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 "layeractivate.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #include <synfigapp/general.h>
36
37 #endif
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
44
45 /* === M A C R O S ========================================================= */
46 #define ACTION_INIT2(class) \
47         Action::Base* class::create() { return new class(); }   \
48         synfig::String class::get_name()const { return name__; }
49
50 ACTION_INIT2(Action::LayerActivate);
51 ACTION_SET_NAME(Action::LayerActivate,"layer_activate");
52 ACTION_SET_LOCAL_NAME(Action::LayerActivate,N_("Activate Layer"));
53 ACTION_SET_TASK(Action::LayerActivate,"activate");
54 ACTION_SET_CATEGORY(Action::LayerActivate,Action::CATEGORY_LAYER);
55 ACTION_SET_PRIORITY(Action::LayerActivate,0);
56 ACTION_SET_VERSION(Action::LayerActivate,"0.0");
57 ACTION_SET_CVS_ID(Action::LayerActivate,"$Id$");
58
59 /* === G L O B A L S ======================================================= */
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 Action::LayerActivate::LayerActivate()
66 {
67 }
68
69 synfig::String
70 Action::LayerActivate::get_local_name()const
71 {
72         if(!layer)
73                 return _("Activate Layer");
74         String name;
75         if(layer->get_description().empty())
76                 name=layer->get_local_name();
77         else
78                 name=layer->get_description();
79
80         return (new_status?_("Activate "):_("Deactivate "))+name;
81 }
82
83 Action::ParamVocab
84 Action::LayerActivate::get_param_vocab()
85 {
86         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
87
88         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
89                 .set_local_name(_("Layer"))
90         );
91
92         ret.push_back(ParamDesc("new_status",Param::TYPE_BOOL)
93                 .set_local_name(_("New Status"))
94                 .set_desc(_("The new status of the layer"))
95         );
96
97         return ret;
98 }
99
100 bool
101 Action::LayerActivate::is_candidate(const ParamList &x)
102 {
103         return candidate_check(get_param_vocab(),x);
104 }
105
106 bool
107 Action::LayerActivate::set_param(const synfig::String& name, const Action::Param &param)
108 {
109         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
110         {
111                 layer=param.get_layer();
112
113                 return true;
114         }
115
116         if(name=="new_status" && param.get_type()==Param::TYPE_BOOL)
117         {
118                 new_status=param.get_bool();
119
120                 return true;
121         }
122
123         return Action::CanvasSpecific::set_param(name,param);
124 }
125
126 bool
127 Action::LayerActivate::is_ready()const
128 {
129         if(!layer)
130                 return false;
131         return Action::CanvasSpecific::is_ready();
132 }
133
134 void
135 Action::LayerActivate::perform()
136 {
137         Canvas::Handle subcanvas(layer->get_canvas());
138
139         // Find the iterator for the layer
140         Canvas::iterator iter=find(subcanvas->begin(),subcanvas->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         // If the subcanvas isn't the same as the canvas,
147         // then it had better be an inline canvas. If not,
148         // bail
149         //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
150         //if(get_canvas()->get_root()!=subcanvas->get_root())
151         //      throw Error(_("This layer doesn't belong to this composition"));
152
153         old_status=layer->active();
154
155         // If we are changing the status to what it already is,
156         // the go ahead and return
157         if(new_status==old_status)
158         {
159                 set_dirty(false);
160                 return;
161         }
162         else
163                 set_dirty();
164
165         if(new_status)
166                 layer->enable();
167         else
168                 layer->disable();
169
170         if(get_canvas_interface())
171         {
172                 get_canvas_interface()->signal_layer_status_changed()(layer,new_status);
173         }
174         else synfig::warning("CanvasInterface not set on action");
175 }
176
177 void
178 Action::LayerActivate::undo()
179 {
180         // If we are changing the status to what it already is,
181         // the go ahead and return
182         if(new_status==old_status)
183         {
184                 set_dirty(false);
185                 return;
186         }
187         else
188                 set_dirty();
189
190         // restore the old status
191         if(old_status)
192                 layer->enable();
193         else
194                 layer->disable();
195
196         if(get_canvas_interface())
197         {
198                 get_canvas_interface()->signal_layer_status_changed()(layer,old_status);
199         }
200         else synfig::warning("CanvasInterface not set on action");
201 }