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>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::ValueNodeLinkConnect);
48 ACTION_SET_NAME(Action::ValueNodeLinkConnect,"ValueNodeLinkConnect");
49 ACTION_SET_LOCAL_NAME(Action::ValueNodeLinkConnect,N_("Connect ValueNode Link"));
50 ACTION_SET_TASK(Action::ValueNodeLinkConnect,"connect");
51 ACTION_SET_CATEGORY(Action::ValueNodeLinkConnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
52 ACTION_SET_PRIORITY(Action::ValueNodeLinkConnect,0);
53 ACTION_SET_VERSION(Action::ValueNodeLinkConnect,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueNodeLinkConnect,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::ValueNodeLinkConnect::ValueNodeLinkConnect():
63 index(-1) // Initially set it to negative one so that we know when it has changed
68 Action::ValueNodeLinkConnect::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE)
73 .set_local_name(_("Parent ValueNode"))
76 ret.push_back(ParamDesc("index",Param::TYPE_INTEGER)
77 .set_local_name(_("Index"))
80 ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
81 .set_local_name(_("ValueNode to be connected"))
88 Action::ValueNodeLinkConnect::is_candidate(const ParamList &x)
90 return candidate_check(get_param_vocab(),x);
94 Action::ValueNodeLinkConnect::set_param(const synfig::String& name, const Action::Param ¶m)
96 if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE)
98 parent_value_node=LinkableValueNode::Handle::cast_dynamic(param.get_value_node());
100 return static_cast<bool>(parent_value_node);
103 if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
105 new_value_node=param.get_value_node();
110 if(name=="index" && param.get_type()==Param::TYPE_INTEGER)
112 index=param.get_integer();
117 return Action::CanvasSpecific::set_param(name,param);
121 Action::ValueNodeLinkConnect::is_ready()const
123 if(!new_value_node || !parent_value_node || index==-1)
125 return Action::CanvasSpecific::is_ready();
129 Action::ValueNodeLinkConnect::perform()
131 if(parent_value_node->link_count()<=index)
132 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
134 old_value_node=parent_value_node->get_link(index);
136 if(!parent_value_node->set_link(index,new_value_node))
137 throw Error(_("Parent would not accept link"));
141 if(get_canvas_interface())
143 get_canvas_interface()->signal_value_node_changed()(parent_value_node);
148 Action::ValueNodeLinkConnect::undo()
150 if(parent_value_node->link_count()<=index)
151 throw Error(_("Bad index, too big. LinkCount=%d, Index=%d"),parent_value_node->link_count(),index);
153 if(!parent_value_node->set_link(index,old_value_node))
154 throw Error(_("Parent would not accept old link"));
158 if(get_canvas_interface())
160 get_canvas_interface()->signal_value_node_changed()(parent_value_node);