Suit better local name for set/unset static actions
[synfig.git] / synfig-studio / src / synfigapp / actions / valuenodeconstunsetstatic.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodeconstunsetstatic.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2010 Carlos López
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenodeconstunsetstatic.h"
34 #include <synfigapp/canvasinterface.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::ValueNodeConstUnSetStatic);
49 ACTION_SET_NAME(Action::ValueNodeConstUnSetStatic,"ValueNodeConstUnSetStatic");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeConstUnSetStatic,N_("Allow Animation"));
51 ACTION_SET_TASK(Action::ValueNodeConstUnSetStatic,"unsetstatic");
52 ACTION_SET_CATEGORY(Action::ValueNodeConstUnSetStatic,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::ValueNodeConstUnSetStatic,0);
54 ACTION_SET_VERSION(Action::ValueNodeConstUnSetStatic,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeConstUnSetStatic,"$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::ValueNodeConstUnSetStatic::ValueNodeConstUnSetStatic()
64 {
65 }
66
67 Action::ParamVocab
68 Action::ValueNodeConstUnSetStatic::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"))
74         );
75
76         return ret;
77 }
78
79 bool
80 Action::ValueNodeConstUnSetStatic::is_candidate(const ParamList &x)
81 {
82         if (!candidate_check(get_param_vocab(),x))
83                 return false;
84
85         ValueNode::Handle value_node;
86         ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
87
88         if(value_desc.parent_is_value_node_const() || value_desc.parent_is_linkable_value_node())
89                 value_node = value_desc.get_value_node();
90         else
91                 value_node = x.find("value_node")->second.get_value_node();
92
93         // We need a constant value node or a constant layer param.
94         return (
95                         (ValueNode_Const::Handle::cast_dynamic(value_node) &&
96                         // We need the constant value node to be static.
97                         ValueNode_Const::Handle::cast_dynamic(value_node)->get_static())
98                         );
99 }
100
101 bool
102 Action::ValueNodeConstUnSetStatic::set_param(const synfig::String& name, const Action::Param &param)
103 {
104         if(!value_node && name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
105         {
106                 ValueDesc value_desc(param.get_value_desc());
107                 if(!value_desc.parent_is_value_node())
108                         return false;
109
110                 value_node=ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node());
111
112                 if(!value_node)
113                         return false;
114
115                 return true;
116         }
117
118         if(!value_node && name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
119         {
120                 value_node=ValueNode_Const::Handle::cast_dynamic(param.get_value_node());
121
122                 if(!value_node)
123                         return false;
124
125                 return true;
126         }
127
128         return Action::CanvasSpecific::set_param(name,param);
129 }
130
131 bool
132 Action::ValueNodeConstUnSetStatic::is_ready()const
133 {
134         if(!value_node)
135                 return false;
136         return Action::CanvasSpecific::is_ready();
137 }
138
139 void
140 Action::ValueNodeConstUnSetStatic::perform()
141 {
142         old_static_value=value_node->get_static();
143
144         if(old_static_value==false)
145         {
146                 set_dirty(false);
147                 return;
148         }
149         set_dirty(true);
150         value_node->set_static(false);
151
152         value_node->changed();
153 }
154
155 void
156 Action::ValueNodeConstUnSetStatic::undo()
157 {
158         if(old_static_value==value_node->get_static())
159         {
160                 set_dirty(false);
161                 return;
162         }
163
164         set_dirty(true);
165         value_node->set_static(old_static_value);
166
167         value_node->changed();
168
169 }