Add an option "Browser Command" to allow the user to specify which web browser to...
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layerparamconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerparamconnect.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 "layerparamconnect.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::LayerParamConnect);
48 ACTION_SET_NAME(Action::LayerParamConnect,"layer_param_connect");
49 ACTION_SET_LOCAL_NAME(Action::LayerParamConnect,N_("Connect Layer Parameter"));
50 ACTION_SET_TASK(Action::LayerParamConnect,"connect");
51 ACTION_SET_CATEGORY(Action::LayerParamConnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
52 ACTION_SET_PRIORITY(Action::LayerParamConnect,0);
53 ACTION_SET_VERSION(Action::LayerParamConnect,"0.0");
54 ACTION_SET_CVS_ID(Action::LayerParamConnect,"$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::LayerParamConnect::LayerParamConnect()
63 {
64 }
65
66 Action::ParamVocab
67 Action::LayerParamConnect::get_param_vocab()
68 {
69         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70
71         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
72                 .set_local_name(_("Layer"))
73         );
74
75         ret.push_back(ParamDesc("param",Param::TYPE_STRING)
76                 .set_local_name(_("Param"))
77         );
78
79         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
80                 .set_local_name(_("ValueNode"))
81         );
82
83         return ret;
84 }
85
86 bool
87 Action::LayerParamConnect::is_candidate(const ParamList &x)
88 {
89         return candidate_check(get_param_vocab(),x);
90 }
91
92 bool
93 Action::LayerParamConnect::set_param(const synfig::String& name, const Action::Param &param)
94 {
95         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
96         {
97                 layer=param.get_layer();
98
99                 return true;
100         }
101
102         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
103         {
104                 value_node=param.get_value_node();
105
106                 return true;
107         }
108
109         if(name=="param" && param.get_type()==Param::TYPE_STRING)
110         {
111                 param_name=param.get_string();
112
113                 return true;
114         }
115
116         return Action::CanvasSpecific::set_param(name,param);
117 }
118
119 bool
120 Action::LayerParamConnect::is_ready()const
121 {
122         if(!layer)
123                 synfig::warning("Action::LayerParamConnect: Missing \"layer\"");
124         if(!value_node)
125                 synfig::warning("Action::LayerParamConnect: Missing \"value_node\"");
126         if(param_name.empty())
127                 synfig::warning("Action::LayerParamConnect: Missing \"param\"");
128
129         if(!layer || !value_node || param_name.empty())
130                 return false;
131         return Action::CanvasSpecific::is_ready();
132 }
133
134 void
135 Action::LayerParamConnect::perform()
136 {
137         // See if the parameter is dynamic
138         if(layer->dynamic_param_list().count(param_name))
139                 old_value_node=layer->dynamic_param_list().find(param_name)->second;
140         else
141         {
142                 old_value_node=0;
143         }
144
145         old_value=layer->get_param(param_name);
146         if(!old_value.is_valid())
147                 throw Error(_("Layer did not recognize parameter name"));
148
149         if(!layer->set_param(param_name,(*value_node)(0)))
150                 throw Error(_("Bad connection"));
151
152         layer->connect_dynamic_param(param_name,value_node);
153
154         layer->changed();
155         value_node->changed();
156 /*      if(get_canvas_interface())
157         {
158                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
159                 //get_canvas_interface()->signal_value_node_changed()(value_node);
160         }
161 */
162 }
163
164 void
165 Action::LayerParamConnect::undo()
166 {
167         if(old_value_node)
168                 layer->connect_dynamic_param(param_name,old_value_node);
169         else
170         {
171                 layer->disconnect_dynamic_param(param_name);
172                 layer->set_param(param_name,old_value);
173         }
174
175         layer->changed();
176         if(old_value_node)
177                 old_value_node->changed();
178         /*
179         if(layer->active())
180                 set_dirty(true);
181         else
182                 set_dirty(false);
183         */
184
185         if(get_canvas_interface())
186         {
187                 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
188                 //if(old_value_node)get_canvas_interface()->signal_value_node_changed()(old_value_node);
189         }
190 }