1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodelinkconnect.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 "valuenodelinkconnect.h"
33 #include <synfigapp/canvasinterface.h>
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
43 /* === M A C R O S ========================================================= */
45 ACTION_INIT(Action::ValueNodeLinkConnect);
46 ACTION_SET_NAME(Action::ValueNodeLinkConnect,"value_node_link_connect");
47 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkConnect,_("Connect ValueNode Link"));
48 ACTION_SET_TASK(Action::ValueNodeLinkConnect,"connect");
49 ACTION_SET_CATEGORY(Action::ValueNodeLinkConnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
50 ACTION_SET_PRIORITY(Action::ValueNodeLinkConnect,0);
51 ACTION_SET_VERSION(Action::ValueNodeLinkConnect,"0.0");
52 ACTION_SET_CVS_ID(Action::ValueNodeLinkConnect,"$Id$");
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 Action::ValueNodeLinkConnect::ValueNodeLinkConnect():
61 index(-1) // Initially set it to negative one so that we know when it has changed
66 Action::ValueNodeLinkConnect::get_param_vocab()
68 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70 ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
71 .set_local_name(_("Parent ValueNode"))
74 ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
75 .set_local_name(_("Index"))
78 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
79 .set_local_name(_("ValueNode to be connected"))
86 Action::ValueNodeLinkConnect::is_candidate(const ParamList &x)
88 return candidate_check(get_param_vocab(),x);
92 Action::ValueNodeLinkConnect::set_param(const synfig::String& name, const Action::Param ¶m)
94 if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
96 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
98 return static_cast<bool>(parent_value_node);
101 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
103 new_value_node=param.get_value_node();
108 if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
110 index=param.get_integer();
115 return Action::CanvasSpecific::set_param(name,param);
119 Action::ValueNodeLinkConnect::is_ready()const
121 if(!new_value_node || !parent_value_node || index==-1)
123 return Action::CanvasSpecific::is_ready();
127 Action::ValueNodeLinkConnect::perform()
129 if(parent_value_node->link_count()<=index)
130 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
132 old_value_node=parent_value_node->get_link(index);
134 if(!parent_value_node->set_link(index,new_value_node))
135 throw Error(_("Parent would not accept link"));
139 if(get_canvas_interface())
141 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
146 Action::ValueNodeLinkConnect::undo()
148 if(parent_value_node->link_count()<=index)
149 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
151 if(!parent_value_node->set_link(index,old_value_node))
152 throw Error(_("Parent would not accept old link"));
156 if(get_canvas_interface())
158 get_canvas_interface()->signal_value_node_changed()(parent_value_node);