Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc3 / src / synfigapp / actions / valuenodelinkdisconnect.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodelinkdisconnect.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 "valuenodelinkdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_const.h>
35
36 #endif
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
43
44 /* === M A C R O S ========================================================= */
45
46 ACTION_INIT(Action::ValueNodeLinkDisconnect);
47 ACTION_SET_NAME(Action::ValueNodeLinkDisconnect,"value_node_link_disconnect");
48 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkDisconnect,_("Disconnect ValueNode Link"));
49 ACTION_SET_TASK(Action::ValueNodeLinkDisconnect,"disconnect");
50 ACTION_SET_CATEGORY(Action::ValueNodeLinkDisconnect,Action::CATEGORY_VALUENODE);
51 ACTION_SET_PRIORITY(Action::ValueNodeLinkDisconnect,0);
52 ACTION_SET_VERSION(Action::ValueNodeLinkDisconnect,"0.0");
53 ACTION_SET_CVS_ID(Action::ValueNodeLinkDisconnect,"$Id$");
54
55 /* === G L O B A L S ======================================================= */
56
57 /* === P R O C E D U R E S ================================================= */
58
59 /* === M E T H O D S ======================================================= */
60
61 Action::ValueNodeLinkDisconnect::ValueNodeLinkDisconnect():
62         index(-1),      // Initially set it to negative one so that we know when it has changed
63         time(0)
64 {
65 }
66
67 Action::ParamVocab
68 Action::ValueNodeLinkDisconnect::get_param_vocab()
69 {
70         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71
72         ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
73                 .set_local_name(_("Parent ValueNode"))
74         );
75
76         ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
77                 .set_local_name(_("Index"))
78         );
79
80         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
81                 .set_local_name(_("Time"))
82                 .set_optional()
83         );
84
85         return ret;
86 }
87
88 bool
89 Action::ValueNodeLinkDisconnect::is_candidate(const ParamList &x)
90 {
91         return candidate_check(get_param_vocab(),x);
92 }
93
94 bool
95 Action::ValueNodeLinkDisconnect::set_param(const synfig::String& name, const Action::Param &param)
96 {
97         if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
98         {
99                 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
100
101                 return static_cast<bool>(parent_value_node);
102         }
103
104         if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
105         {
106                 index=param.get_integer();
107
108                 return true;
109         }
110
111         if(name=="time" && param.get_type()==Param::TYPE_TIME)
112         {
113                 time=param.get_time();
114
115                 return true;
116         }
117
118         return Action::CanvasSpecific::set_param(name,param);
119 }
120
121 bool
122 Action::ValueNodeLinkDisconnect::is_ready()const
123 {
124         if(!parent_value_node || index==-1)
125                 return false;
126         return Action::CanvasSpecific::is_ready();
127 }
128
129 void
130 Action::ValueNodeLinkDisconnect::perform()
131 {
132         if(parent_value_node->link_count()<=index)
133                 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
134
135         old_value_node=parent_value_node->get_link(index);
136
137         if(!parent_value_node->set_link(index,ValueNode_Const::create((*old_value_node)(time))))
138                 throw Error(_("Parent would not accept link"));
139
140         /*
141         if(get_canvas()->get_time()!=time)
142                 set_dirty(true);
143         else
144                 set_dirty(false);
145
146         if(get_canvas_interface())
147         {
148                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
149         }
150         */
151 }
152
153 void
154 Action::ValueNodeLinkDisconnect::undo()
155 {
156         if(parent_value_node->link_count()<=index)
157                 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
158
159         if(!parent_value_node->set_link(index,old_value_node))
160                 throw Error(_("Parent would not accept old link"));
161
162         /*if(get_canvas()->get_time()!=time)
163                 set_dirty(true);
164         else
165                 set_dirty(false);
166
167         if(get_canvas_interface())
168         {
169                 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
170         }*/
171 }