Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / 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 #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::ValueNodeConstSet);
48 ACTION_SET_NAME(Action::ValueNodeConstSet,"value_node_const_set");
49 ACTION_SET_LOCAL_NAME(Action::ValueNodeConstSet,N_("Set ValueNode_Const"));
50 ACTION_SET_TASK(Action::ValueNodeConstSet,"set");
51 ACTION_SET_CATEGORY(Action::ValueNodeConstSet,Action::CATEGORY_VALUENODE);
52 ACTION_SET_PRIORITY(Action::ValueNodeConstSet,0);
53 ACTION_SET_VERSION(Action::ValueNodeConstSet,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueNodeConstSet,"$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::ValueNodeConstSet::ValueNodeConstSet()
63 {
64         set_dirty(true);
65 }
66
67 Action::ParamVocab
68 Action::ValueNodeConstSet::get_param_vocab()
69 {
70         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71
72         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
73                 .set_local_name(_("ValueNode_Const"))
74         );
75
76         ret.push_back(ParamDesc("new_value",Param::TYPE_VALUE)
77                 .set_local_name(_("ValueBase"))
78         );
79
80         return ret;
81 }
82
83 bool
84 Action::ValueNodeConstSet::is_candidate(const ParamList &x)
85 {
86         if(candidate_check(get_param_vocab(),x))
87         {
88                 if(ValueNode_Const::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()))
89                         return true;
90         }
91         return false;
92 }
93
94 bool
95 Action::ValueNodeConstSet::set_param(const synfig::String& name, const Action::Param &param)
96 {
97         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
98         {
99                 value_node=ValueNode_Const::Handle::cast_dynamic(param.get_value_node());
100
101                 return (bool)value_node;
102         }
103
104         if(name=="new_value" && param.get_type()==Param::TYPE_VALUE)
105         {
106                 new_value=param.get_value();
107
108                 return true;
109         }
110
111         return Action::CanvasSpecific::set_param(name,param);
112 }
113
114 bool
115 Action::ValueNodeConstSet::is_ready()const
116 {
117         if(!value_node || !new_value.is_valid())
118                 return false;
119         return Action::CanvasSpecific::is_ready();
120 }
121
122 void
123 Action::ValueNodeConstSet::perform()
124 {
125         //set_dirty(true);
126
127         old_value=value_node->get_value();
128
129         value_node->set_value(new_value);
130
131         // Signal that a layer has been inserted
132         /*if(get_canvas_interface())
133         {
134                 get_canvas_interface()->signal_value_node_changed()(value_node);
135         }*/
136 }
137
138 void
139 Action::ValueNodeConstSet::undo()
140 {
141         //set_dirty(true);
142
143         value_node->set_value(old_value);
144
145         // Signal that a layer has been inserted
146         /*if(get_canvas_interface())
147         {
148                 get_canvas_interface()->signal_value_node_changed()(value_node);
149         }*/
150 }