my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuenoderemove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenoderemove.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenoderemove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "valuenoderemove.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43
44 ACTION_INIT(Action::ValueNodeRemove);
45 ACTION_SET_NAME(Action::ValueNodeRemove,"value_node_remove");
46 ACTION_SET_LOCAL_NAME(Action::ValueNodeRemove,_("Unexport"));
47 ACTION_SET_TASK(Action::ValueNodeRemove,"remove");
48 ACTION_SET_CATEGORY(Action::ValueNodeRemove,Action::CATEGORY_VALUENODE);
49 ACTION_SET_PRIORITY(Action::ValueNodeRemove,0);
50 ACTION_SET_VERSION(Action::ValueNodeRemove,"0.0");
51 ACTION_SET_CVS_ID(Action::ValueNodeRemove,"$Id: valuenoderemove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Action::ValueNodeRemove::ValueNodeRemove()
60 {
61 }
62
63 Action::ParamVocab
64 Action::ValueNodeRemove::get_param_vocab()
65 {
66         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
67         
68         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
69                 .set_local_name(_("ValueNode"))
70         );
71         
72         return ret;
73 }
74
75 bool
76 Action::ValueNodeRemove::is_canidate(const ParamList &x)
77 {
78         if(canidate_check(get_param_vocab(),x))
79         {
80                 ValueNode::Handle value_node=x.find("value_node")->second.get_value_node();
81                 if(!value_node->is_exported())
82                         return false;
83 //              if(value_node->rcount()!=1)
84 //                      return false;
85                 return true;
86         }
87         return false;
88 }
89
90 bool
91 Action::ValueNodeRemove::set_param(const synfig::String& name, const Action::Param &param)
92 {
93         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
94         {
95                 value_node=param.get_value_node();
96                 
97                 if(value_node && !value_node->is_exported())
98                 {
99                         synfig::error("Action::ValueNodeRemove::set_param(): ValueBase node not exported!");
100                         value_node=0;
101                 }
102                 
103                 return (bool)value_node;
104         }
105
106         return Action::CanvasSpecific::set_param(name,param);
107 }
108
109 bool
110 Action::ValueNodeRemove::is_ready()const
111 {
112         if(!value_node)
113                 synfig::error("Action::ValueNodeRemove::is_ready(): ValueNode not set!");
114
115         if(!value_node)
116                 return false;
117         return Action::CanvasSpecific::is_ready();
118 }
119
120 void
121 Action::ValueNodeRemove::perform()
122 {       
123 //      if(value_node->rcount()!=1)
124 //              throw Error(_("ValueNode is still being used by something"));
125
126         old_name=value_node->get_id();
127         parent_canvas=value_node->get_parent_canvas();
128         parent_canvas->remove_value_node(value_node);
129
130         if(get_canvas_interface())
131         {
132                 get_canvas_interface()->signal_value_node_deleted()(value_node);
133         }
134         
135         //throw Error(_("Not yet implemented"));
136 /*
137         assert(value_node->is_exported());
138
139         if(get_canvas()->value_node_list().count(new_name))
140                 throw Error(_("A ValueNode with this ID already exists in this canvas"));
141         
142         old_name=value_node->get_id();
143
144         value_node->set_id(new_name);   
145         
146         if(get_canvas_interface())
147         {
148                 get_canvas_interface()->signal_value_node_changed()(value_node);
149         }
150 */
151 }
152
153 void
154 Action::ValueNodeRemove::undo()
155 {
156         parent_canvas->add_value_node(value_node,old_name);
157         if(get_canvas_interface())
158         {
159                 get_canvas_interface()->signal_value_node_added()(value_node);
160         }
161         
162         //throw Error(_("Not yet implemented"));
163 /*
164         assert(value_node->is_exported());
165
166         if(get_canvas()->value_node_list().count(old_name))
167                 throw Error(_("A ValueNode with the old ID already exists in this canvas (BUG)"));
168         
169         value_node->set_id(old_name);   
170         
171         if(get_canvas_interface())
172         {
173                 get_canvas_interface()->signal_value_node_changed()(value_node);
174         }
175 */
176 }