Show the 'active' and 'deactivate' messages with the layer name in quotes in the...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layerparamdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerparamdisconnect.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 "layerparamdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_dynamiclist.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(Action::LayerParamDisconnect);
49 ACTION_SET_NAME(Action::LayerParamDisconnect,"layer_param_disconnect");
50 ACTION_SET_LOCAL_NAME(Action::LayerParamDisconnect,N_("Disconnect Layer Parameter"));
51 ACTION_SET_TASK(Action::LayerParamDisconnect,"disconnect");
52 ACTION_SET_CATEGORY(Action::LayerParamDisconnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::LayerParamDisconnect,0);
54 ACTION_SET_VERSION(Action::LayerParamDisconnect,"0.0");
55 ACTION_SET_CVS_ID(Action::LayerParamDisconnect,"$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::LayerParamDisconnect::LayerParamDisconnect():
64         time(0)
65 {
66
67 }
68
69 Action::ParamVocab
70 Action::LayerParamDisconnect::get_param_vocab()
71 {
72         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73
74         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
75                 .set_local_name(_("Layer"))
76         );
77
78         ret.push_back(ParamDesc("param",Param::TYPE_STRING)
79                 .set_local_name(_("Param"))
80         );
81
82         ret.push_back(ParamDesc("time",Param::TYPE_STRING)
83                 .set_local_name(_("Time"))
84                 .set_optional()
85         );
86
87         return ret;
88 }
89
90 bool
91 Action::LayerParamDisconnect::is_candidate(const ParamList &x)
92 {
93         return candidate_check(get_param_vocab(),x);
94 }
95
96 bool
97 Action::LayerParamDisconnect::set_param(const synfig::String& name, const Action::Param &param)
98 {
99         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
100         {
101                 layer=param.get_layer();
102
103                 return true;
104         }
105
106         if(name=="param" && param.get_type()==Param::TYPE_STRING)
107         {
108                 param_name=param.get_string();
109
110                 return true;
111         }
112
113         if(name=="time" && param.get_type()==Param::TYPE_TIME)
114         {
115                 time=param.get_time();
116
117                 return true;
118         }
119
120         return Action::CanvasSpecific::set_param(name,param);
121 }
122
123 bool
124 Action::LayerParamDisconnect::is_ready()const
125 {
126         if(!layer || param_name.empty())
127                 return false;
128         return Action::CanvasSpecific::is_ready();
129 }
130
131 void
132 Action::LayerParamDisconnect::perform()
133 {
134         if(!layer->dynamic_param_list().count(param_name))
135                 throw Error(_("Layer Parameter is not connected to anything"));
136
137         old_value_node=layer->dynamic_param_list().find(param_name)->second;
138         layer->disconnect_dynamic_param(param_name);
139
140         if(new_value_node || ValueNode_DynamicList::Handle::cast_dynamic(old_value_node))
141         {
142                 if(!new_value_node)
143                         new_value_node=old_value_node.clone();
144                 layer->connect_dynamic_param(param_name,new_value_node);
145         }
146         else
147                 layer->set_param(param_name,(*old_value_node)(time));
148
149         layer->changed();
150         old_value_node->changed();
151
152         set_dirty(false);
153
154         if(get_canvas_interface())
155         {
156                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
157         }
158 }
159
160 void
161 Action::LayerParamDisconnect::undo()
162 {
163         layer->connect_dynamic_param(param_name,old_value_node);
164
165 /*      if(layer->active() && get_canvas()->get_time()!=time)
166                 set_dirty(true);
167         else
168                 set_dirty(false);
169 */
170         layer->changed();
171         old_value_node->changed();
172
173         set_dirty(false);
174
175         if(get_canvas_interface())
176         {
177                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
178         }
179 }