Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / synfigapp / actions / valuenodeadd.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodeadd.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenodeadd.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #endif
36
37 using namespace std;
38 using namespace etl;
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
42
43 /* === M A C R O S ========================================================= */
44
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$");
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 Action::ValueNodeAdd::ValueNodeAdd()
61 {
62 }
63
64 Action::ParamVocab
65 Action::ValueNodeAdd::get_param_vocab()
66 {
67         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
68
69         ret.push_back(ParamDesc("new",Param::TYPE_VALUENODE)
70                 .set_local_name(_("New ValueNode"))
71                 .set_desc(_("ValueNode to be added"))
72         );
73
74         ret.push_back(ParamDesc("name",Param::TYPE_STRING)
75                 .set_local_name(_("Name"))
76         );
77
78         return ret;
79 }
80
81 bool
82 Action::ValueNodeAdd::is_candidate(const ParamList &x)
83 {
84         return candidate_check(get_param_vocab(),x);
85 }
86
87 bool
88 Action::ValueNodeAdd::set_param(const synfig::String& param_name, const Action::Param &param)
89 {
90         if(param_name=="new" && param.get_type()==Param::TYPE_VALUENODE)
91         {
92                 value_node=param.get_value_node();
93
94                 return true;
95         }
96
97         if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
98         {
99                 name=param.get_string();
100
101                 return true;
102         }
103
104         return Action::CanvasSpecific::set_param(param_name,param);
105 }
106
107 bool
108 Action::ValueNodeAdd::is_ready()const
109 {
110         if(!value_node || name.empty())
111                 return false;
112         return Action::CanvasSpecific::is_ready();
113 }
114
115 void
116 Action::ValueNodeAdd::perform()
117 {
118         if(value_node->is_exported())
119         {
120                 throw Error(_("Parameter appears to already be exported"));
121         }
122
123         try
124         {
125                 get_canvas()->add_value_node(value_node,name);
126         }
127         catch(Exception::IDAlreadyExists)
128         {
129                 throw Error(_("Another exported ValueBase with this name already exists"));
130         }
131         catch(...)
132         {
133                 throw Error(_("Exception caught on Add ValueNode."));
134         }
135
136         set_dirty(false);
137
138         // Signal that a layer has been inserted
139         if(get_canvas_interface())
140         {
141                 get_canvas_interface()->signal_value_node_added()(value_node);
142         }
143         else synfig::warning("CanvasInterface not set on action");
144 }
145
146 void
147 Action::ValueNodeAdd::undo()
148 {
149         try { get_canvas()->remove_value_node(value_node); }
150         catch(...)
151         {
152                 throw Error(_("Exception caught on Remove ValueNode."));
153         }
154
155         set_dirty(false);
156
157         // Signal that a layer has been inserted
158         if(get_canvas_interface())
159         {
160                 get_canvas_interface()->signal_value_node_deleted()(value_node);
161         }
162         else synfig::warning("CanvasInterface not set on action");
163 }