Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuenoderename.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenoderename.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenoderename.h"
34 #include <synfigapp/canvasinterface.h>
35
36 #include <synfigapp/general.h>
37
38 #endif
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
45
46 /* === M A C R O S ========================================================= */
47
48 ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueNodeRename);
49 ACTION_SET_NAME(Action::ValueNodeRename,"value_node_rename");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeRename,N_("Rename ValueNode"));
51 ACTION_SET_TASK(Action::ValueNodeRename,"rename");
52 ACTION_SET_CATEGORY(Action::ValueNodeRename,Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::ValueNodeRename,0);
54 ACTION_SET_VERSION(Action::ValueNodeRename,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeRename,"$Id$");
56
57 /* === G L O B A L S ======================================================= */
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 Action::ValueNodeRename::ValueNodeRename()
64 {
65 }
66
67 synfig::String
68 Action::ValueNodeRename::get_local_name()const
69 {
70         // TRANSLATORS: This is used in the 'history' dialog when a ValueNode is renamed.
71         return strprintf(_("Rename ValueNode from '%s' to '%s'"),
72                                          old_name.c_str(),
73                                          new_name.c_str());
74 }
75
76 Action::ParamVocab
77 Action::ValueNodeRename::get_param_vocab()
78 {
79         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80
81         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
82                 .set_local_name(_("ValueNode_Const"))
83         );
84
85         ret.push_back(ParamDesc("name",Param::TYPE_STRING)
86                 .set_local_name(_("Name"))
87                 .set_desc(_("The new name of the ValueNode"))
88                 .set_user_supplied()
89         );
90
91         return ret;
92 }
93
94 bool
95 Action::ValueNodeRename::is_candidate(const ParamList &x)
96 {
97         if(candidate_check(get_param_vocab(),x))
98         {
99                 if(x.find("value_node")->second.get_value_node()->is_exported())
100                         return true;
101         }
102         return false;
103 }
104
105 bool
106 Action::ValueNodeRename::set_param(const synfig::String& name, const Action::Param &param)
107 {
108         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
109         {
110                 value_node=param.get_value_node();
111
112                 if(value_node && !value_node->is_exported())
113                 {
114                         synfig::error("Action::ValueNodeRename::set_param(): ValueBase node not exported!");
115                         value_node=0;
116                 }
117
118                 return (bool)value_node;
119         }
120
121         if(name=="name" && param.get_type()==Param::TYPE_STRING)
122         {
123                 new_name=param.get_string();
124
125                 return true;
126         }
127
128         return Action::CanvasSpecific::set_param(name,param);
129 }
130
131 bool
132 Action::ValueNodeRename::is_ready()const
133 {
134         if(!value_node)
135                 synfig::error("Action::ValueNodeRename::is_ready(): ValueNode not set!");
136
137         if(new_name.empty())
138                 synfig::error("Action::ValueNodeRename::is_ready(): ValueNode not set!");
139
140         if(!value_node || new_name.empty())
141                 return false;
142         return Action::CanvasSpecific::is_ready();
143 }
144
145 void
146 Action::ValueNodeRename::perform()
147 {
148         assert(value_node->is_exported());
149
150         if(get_canvas()->value_node_list().count(new_name))
151                 throw Error(_("A ValueNode with this ID already exists in this canvas"));
152
153         old_name=value_node->get_id();
154
155         value_node->set_id(new_name);
156
157         if(get_canvas_interface())
158         {
159                 get_canvas_interface()->signal_value_node_renamed()(value_node);
160         }
161 }
162
163 void
164 Action::ValueNodeRename::undo()
165 {
166         assert(value_node->is_exported());
167
168         if(get_canvas()->value_node_list().count(old_name))
169                 throw Error(_("A ValueNode with the old ID already exists in this canvas (BUG)"));
170
171         value_node->set_id(old_name);
172
173         if(get_canvas_interface())
174         {
175                 get_canvas_interface()->signal_value_node_renamed()(value_node);
176         }
177 }