1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodelinkdisconnect.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "valuenodelinkdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_const.h>
36 #include <synfigapp/general.h>
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::ValueNodeLinkDisconnect);
49 ACTION_SET_NAME(Action::ValueNodeLinkDisconnect,"value_node_link_disconnect");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkDisconnect,N_("Disconnect ValueNode Link"));
51 ACTION_SET_TASK(Action::ValueNodeLinkDisconnect,"disconnect");
52 ACTION_SET_CATEGORY(Action::ValueNodeLinkDisconnect,Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::ValueNodeLinkDisconnect,0);
54 ACTION_SET_VERSION(Action::ValueNodeLinkDisconnect,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeLinkDisconnect,"$Id$");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::ValueNodeLinkDisconnect::ValueNodeLinkDisconnect():
64 index(-1), // Initially set it to negative one so that we know when it has changed
70 Action::ValueNodeLinkDisconnect::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
75 .set_local_name(_("Parent ValueNode"))
78 ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
79 .set_local_name(_("Index"))
82 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
83 .set_local_name(_("Time"))
91 Action::ValueNodeLinkDisconnect::is_candidate(const ParamList &x)
93 return candidate_check(get_param_vocab(),x);
97 Action::ValueNodeLinkDisconnect::set_param(const synfig::String& name, const Action::Param ¶m)
99 if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
101 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
103 return static_cast<bool>(parent_value_node);
106 if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
108 index=param.get_integer();
113 if(name=="time" && param.get_type()==Param::TYPE_TIME)
115 time=param.get_time();
120 return Action::CanvasSpecific::set_param(name,param);
124 Action::ValueNodeLinkDisconnect::is_ready()const
126 if(!parent_value_node || index==-1)
128 return Action::CanvasSpecific::is_ready();
132 Action::ValueNodeLinkDisconnect::perform()
134 if(parent_value_node->link_count()<=index)
135 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
137 old_value_node=parent_value_node->get_link(index);
139 if(!parent_value_node->set_link(index,ValueNode_Const::create((*old_value_node)(time))))
140 throw Error(_("Parent would not accept link"));
143 if(get_canvas()->get_time()!=time)
148 if(get_canvas_interface())
150 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
156 Action::ValueNodeLinkDisconnect::undo()
158 if(parent_value_node->link_count()<=index)
159 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
161 if(!parent_value_node->set_link(index,old_value_node))
162 throw Error(_("Parent would not accept old link"));
164 /*if(get_canvas()->get_time()!=time)
169 if(get_canvas_interface())
171 get_canvas_interface()->signal_value_node_changed()(parent_value_node);