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>
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::ValueNodeAdd);
48 ACTION_SET_NAME(Action::ValueNodeAdd,"value_node_add");
49 ACTION_SET_LOCAL_NAME(Action::ValueNodeAdd,N_("Add ValueNode"));
50 ACTION_SET_TASK(Action::ValueNodeAdd,"add");
51 ACTION_SET_CATEGORY(Action::ValueNodeAdd,Action::CATEGORY_VALUENODE);
52 ACTION_SET_PRIORITY(Action::ValueNodeAdd,0);
53 ACTION_SET_VERSION(Action::ValueNodeAdd,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueNodeAdd,"$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::ValueNodeAdd::ValueNodeAdd()
67 Action::ValueNodeAdd::get_param_vocab()
69 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71 ret.push_back(ParamDesc("new",Param::TYPE_VALUENODE)
72 .set_local_name(_("New ValueNode"))
73 .set_desc(_("ValueNode to be added"))
76 ret.push_back(ParamDesc("name",Param::TYPE_STRING)
77 .set_local_name(_("Name"))
84 Action::ValueNodeAdd::is_candidate(const ParamList &x)
86 return candidate_check(get_param_vocab(),x);
90 Action::ValueNodeAdd::set_param(const synfig::String& param_name, const Action::Param ¶m)
92 if(param_name=="new" && param.get_type()==Param::TYPE_VALUENODE)
94 value_node=param.get_value_node();
99 if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
101 name=param.get_string();
106 return Action::CanvasSpecific::set_param(param_name,param);
110 Action::ValueNodeAdd::is_ready()const
112 if(!value_node || name.empty())
114 return Action::CanvasSpecific::is_ready();
118 Action::ValueNodeAdd::perform()
120 if(value_node->is_exported())
122 throw Error(_("Parameter appears to already be exported"));
127 get_canvas()->add_value_node(value_node,name);
129 catch(Exception::IDAlreadyExists)
131 throw Error(_("Another exported ValueBase with this name already exists"));
135 throw Error(_("Exception caught on Add ValueNode."));
140 // Signal that a layer has been inserted
141 if(get_canvas_interface())
143 get_canvas_interface()->signal_value_node_added()(value_node);
145 else synfig::warning("CanvasInterface not set on action");
149 Action::ValueNodeAdd::undo()
151 try { get_canvas()->remove_value_node(value_node); }
154 throw Error(_("Exception caught on Remove ValueNode."));
159 // Signal that a layer has been inserted
160 if(get_canvas_interface())
162 get_canvas_interface()->signal_value_node_deleted()(value_node);
164 else synfig::warning("CanvasInterface not set on action");