1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodeadd.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 "valuenodeadd.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::ValueNodeAdd);
46 ACTION_SET_NAME(Action::ValueNodeAdd,"value_node_add");
47 ACTION_SET_LOCAL_NAME(Action::ValueNodeAdd,"Add ValueNode");
48 ACTION_SET_TASK(Action::ValueNodeAdd,"add");
49 ACTION_SET_CATEGORY(Action::ValueNodeAdd,Action::CATEGORY_VALUENODE);
50 ACTION_SET_PRIORITY(Action::ValueNodeAdd,0);
51 ACTION_SET_VERSION(Action::ValueNodeAdd,"0.0");
52 ACTION_SET_CVS_ID(Action::ValueNodeAdd,"$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::ValueNodeAdd::ValueNodeAdd()
65 Action::ValueNodeAdd::get_param_vocab()
67 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69 ret.push_back(ParamDesc("new",Param::TYPE_VALUENODE)
70 .set_local_name(_("New ValueNode"))
71 .set_desc(_("ValueNode to be added"))
74 ret.push_back(ParamDesc("name",Param::TYPE_STRING)
75 .set_local_name(_("Name"))
82 Action::ValueNodeAdd::is_candidate(const ParamList &x)
84 return candidate_check(get_param_vocab(),x);
88 Action::ValueNodeAdd::set_param(const synfig::String& param_name, const Action::Param ¶m)
90 if(param_name=="new" && param.get_type()==Param::TYPE_VALUENODE)
92 value_node=param.get_value_node();
97 if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
99 name=param.get_string();
104 return Action::CanvasSpecific::set_param(param_name,param);
108 Action::ValueNodeAdd::is_ready()const
110 if(!value_node || name.empty())
112 return Action::CanvasSpecific::is_ready();
116 Action::ValueNodeAdd::perform()
118 if(value_node->is_exported())
120 throw Error(_("Parameter appears to already be exported"));
125 get_canvas()->add_value_node(value_node,name);
127 catch(Exception::IDAlreadyExists)
129 throw Error(_("Another exported ValueBase with this name already exists"));
133 throw Error(_("Exception caught on Add ValueNode."));
138 // Signal that a layer has been inserted
139 if(get_canvas_interface())
141 get_canvas_interface()->signal_value_node_added()(value_node);
143 else synfig::warning("CanvasInterface not set on action");
147 Action::ValueNodeAdd::undo()
149 try { get_canvas()->remove_value_node(value_node); }
152 throw Error(_("Exception caught on Remove ValueNode."));
157 // Signal that a layer has been inserted
158 if(get_canvas_interface())
160 get_canvas_interface()->signal_value_node_deleted()(value_node);
162 else synfig::warning("CanvasInterface not set on action");