3bd636c1da87c9318e1cf29ac4542bd1f87e1b54
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layersetdesc.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layersetdesc.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 "layersetdesc.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(Action::LayerSetDesc);
48 ACTION_SET_NAME(Action::LayerSetDesc,"layer_set_desc");
49 ACTION_SET_LOCAL_NAME(Action::LayerSetDesc,N_("Set Layer Description"));
50 ACTION_SET_TASK(Action::LayerSetDesc,"set_desc");
51 ACTION_SET_CATEGORY(Action::LayerSetDesc,Action::CATEGORY_LAYER);
52 ACTION_SET_PRIORITY(Action::LayerSetDesc,0);
53 ACTION_SET_VERSION(Action::LayerSetDesc,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerSetDesc,"$Id$");
55
56 /* === G L O B A L S ======================================================= */
57
58 static const int nindex=-1;
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 Action::LayerSetDesc::LayerSetDesc()
65 {
66 }
67
68 Action::ParamVocab
69 Action::LayerSetDesc::get_param_vocab()
70 {
71         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72
73         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
74                 .set_local_name(_("Layer"))
75                 .set_desc(_("Layer to be moved"))
76         );
77
78         ret.push_back(ParamDesc("new_description",Param::TYPE_STRING)
79                 .set_local_name(_("New Description"))
80                 .set_local_name(_("Enter a new description for this layer"))
81                 .set_user_supplied()
82         );
83
84         return ret;
85 }
86
87 bool
88 Action::LayerSetDesc::is_candidate(const ParamList &x)
89 {
90         return candidate_check(get_param_vocab(),x);
91 }
92
93 bool
94 Action::LayerSetDesc::set_param(const synfig::String& name, const Action::Param &param)
95 {
96         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
97         {
98                 layer=param.get_layer();
99
100                 return true;
101         }
102
103         if(name=="new_description" && param.get_type()==Param::TYPE_STRING)
104         {
105                 new_description=param.get_string();
106
107                 return true;
108         }
109
110         return Action::CanvasSpecific::set_param(name,param);
111 }
112
113 bool
114 Action::LayerSetDesc::is_ready()const
115 {
116         if(!layer)
117                 return false;
118         return Action::CanvasSpecific::is_ready();
119 }
120
121 void
122 Action::LayerSetDesc::perform()
123 {
124         old_description=layer->get_description();
125         layer->set_description(new_description);
126         set_dirty(false);
127         if(get_canvas_interface())
128         {
129                 get_canvas_interface()->signal_layer_new_description()(layer,new_description);
130         }
131         else synfig::warning("CanvasInterface not set on action");
132 }
133
134 void
135 Action::LayerSetDesc::undo()
136 {
137         layer->set_description(old_description);
138         set_dirty(false);
139         if(get_canvas_interface())
140         {
141                 get_canvas_interface()->signal_layer_new_description()(layer,old_description);
142         }
143         else synfig::warning("CanvasInterface not set on action");
144 }