Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / synfigapp / actions / valuenodeconstset.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodeconstset.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 "valuenodeconstset.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
45 ACTION_INIT(Action::ValueNodeConstSet);
46 ACTION_SET_NAME(Action::ValueNodeConstSet,"value_node_const_set");
47 ACTION_SET_LOCAL_NAME(Action::ValueNodeConstSet,_("Set ValueNode_Const"));
48 ACTION_SET_TASK(Action::ValueNodeConstSet,"set");
49 ACTION_SET_CATEGORY(Action::ValueNodeConstSet,Action::CATEGORY_VALUENODE);
50 ACTION_SET_PRIORITY(Action::ValueNodeConstSet,0);
51 ACTION_SET_VERSION(Action::ValueNodeConstSet,"0.0");
52 ACTION_SET_CVS_ID(Action::ValueNodeConstSet,"$Id$");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::ValueNodeConstSet::ValueNodeConstSet()
61 {
62         set_dirty(true);
63 }
64
65 Action::ParamVocab
66 Action::ValueNodeConstSet::get_param_vocab()
67 {
68         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69
70         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
71                 .set_local_name(_("ValueNode_Const"))
72         );
73
74         ret.push_back(ParamDesc("new_value",Param::TYPE_VALUE)
75                 .set_local_name(_("ValueBase"))
76         );
77
78         return ret;
79 }
80
81 bool
82 Action::ValueNodeConstSet::is_candidate(const ParamList &x)
83 {
84         if(candidate_check(get_param_vocab(),x))
85         {
86                 if(ValueNode_Const::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()))
87                         return true;
88         }
89         return false;
90 }
91
92 bool
93 Action::ValueNodeConstSet::set_param(const synfig::String& name, const Action::Param &param)
94 {
95         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
96         {
97                 value_node=ValueNode_Const::Handle::cast_dynamic(param.get_value_node());
98
99                 return (bool)value_node;
100         }
101
102         if(name=="new_value" && param.get_type()==Param::TYPE_VALUE)
103         {
104                 new_value=param.get_value();
105
106                 return true;
107         }
108
109         return Action::CanvasSpecific::set_param(name,param);
110 }
111
112 bool
113 Action::ValueNodeConstSet::is_ready()const
114 {
115         if(!value_node || !new_value.is_valid())
116                 return false;
117         return Action::CanvasSpecific::is_ready();
118 }
119
120 void
121 Action::ValueNodeConstSet::perform()
122 {
123         //set_dirty(true);
124
125         old_value=value_node->get_value();
126
127         value_node->set_value(new_value);
128
129         // Signal that a layer has been inserted
130         /*if(get_canvas_interface())
131         {
132                 get_canvas_interface()->signal_value_node_changed()(value_node);
133         }*/
134 }
135
136 void
137 Action::ValueNodeConstSet::undo()
138 {
139         //set_dirty(true);
140
141         value_node->set_value(old_value);
142
143         // Signal that a layer has been inserted
144         /*if(get_canvas_interface())
145         {
146                 get_canvas_interface()->signal_value_node_changed()(value_node);
147         }*/
148 }