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