my log
[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: layeractivate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "layeractivate.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43 #define ACTION_INIT2(class) \
44         Action::Base* class::create() { return new class(); }   \
45         synfig::String class::get_name()const { return name__; }        
46
47 ACTION_INIT2(Action::LayerActivate);
48 ACTION_SET_NAME(Action::LayerActivate,"layer_activate");
49 ACTION_SET_LOCAL_NAME(Action::LayerActivate,_("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: layeractivate.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
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 (new_status?_("Activate "):_("Deactivate "))+name;
78 }
79
80 Action::ParamVocab
81 Action::LayerActivate::get_param_vocab()
82 {
83         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
84         
85         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
86                 .set_local_name(_("Layer"))
87         );
88
89         ret.push_back(ParamDesc("new_status",Param::TYPE_BOOL)
90                 .set_local_name(_("New Status"))
91                 .set_desc(_("The new status of the layer"))
92         );
93         
94         return ret;
95 }
96
97 bool
98 Action::LayerActivate::is_canidate(const ParamList &x)
99 {
100         return canidate_check(get_param_vocab(),x);
101 }
102
103 bool
104 Action::LayerActivate::set_param(const synfig::String& name, const Action::Param &param)
105 {
106         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
107         {
108                 layer=param.get_layer();
109                 
110                 return true;
111         }
112
113         if(name=="new_status" && param.get_type()==Param::TYPE_BOOL)
114         {
115                 new_status=param.get_bool();
116                 
117                 return true;
118         }
119
120         return Action::CanvasSpecific::set_param(name,param);
121 }
122
123 bool
124 Action::LayerActivate::is_ready()const
125 {
126         if(!layer)
127                 return false;
128         return Action::CanvasSpecific::is_ready();
129 }
130
131 void
132 Action::LayerActivate::perform()
133 {
134         Canvas::Handle subcanvas(layer->get_canvas());
135         
136         // Find the iterator for the layer
137         Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
138         
139         // If we couldn't find the layer in the canvas, then bail
140         if(*iter!=layer)
141                 throw Error(_("This layer doesn't exist anymore."));
142
143         // If the subcanvas isn't the same as the canvas,
144         // then it had better be an inline canvas. If not,
145         // bail
146         //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
147         //if(get_canvas()->get_root()!=subcanvas->get_root())
148         //      throw Error(_("This layer doesn't belong to this composition"));
149         
150         old_status=layer->active();
151         
152         // If we are changing the status to what it already is,
153         // the go ahead and return
154         if(new_status==old_status)
155         {
156                 set_dirty(false);
157                 return;
158         }
159         else
160                 set_dirty();
161         
162         if(new_status)
163                 layer->enable();
164         else
165                 layer->disable();
166
167         if(get_canvas_interface())
168         {
169                 get_canvas_interface()->signal_layer_status_changed()(layer,new_status);
170         }
171         else synfig::warning("CanvasInterface not set on action");
172 }
173
174 void
175 Action::LayerActivate::undo()
176 {
177         // If we are changing the status to what it already is,
178         // the go ahead and return
179         if(new_status==old_status)
180         {
181                 set_dirty(false);
182                 return;
183         }
184         else
185                 set_dirty();
186
187         // restore the old status
188         if(old_status)
189                 layer->enable();
190         else
191                 layer->disable();
192         
193         if(get_canvas_interface())
194         {
195                 get_canvas_interface()->signal_layer_status_changed()(layer,old_status);
196         }
197         else synfig::warning("CanvasInterface not set on action");
198 }