1 /* === S Y N F I G ========================================================= */
2 /*! \file layerparamdisconnect.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 "layerparamdisconnect.h"
33 #include <synfigapp/canvasinterface.h>
34 #include <synfig/valuenode_dynamiclist.h>
36 #include <synfigapp/general.h>
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
46 /* === M A C R O S ========================================================= */
48 ACTION_INIT(Action::LayerParamDisconnect);
49 ACTION_SET_NAME(Action::LayerParamDisconnect,"layer_param_disconnect");
50 ACTION_SET_LOCAL_NAME(Action::LayerParamDisconnect,N_("Disconnect Layer Parameter"));
51 ACTION_SET_TASK(Action::LayerParamDisconnect,"disconnect");
52 ACTION_SET_CATEGORY(Action::LayerParamDisconnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::LayerParamDisconnect,0);
54 ACTION_SET_VERSION(Action::LayerParamDisconnect,"0.0");
55 ACTION_SET_CVS_ID(Action::LayerParamDisconnect,"$Id$");
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Action::LayerParamDisconnect::LayerParamDisconnect():
70 Action::LayerParamDisconnect::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
75 .set_local_name(_("Layer"))
78 ret.push_back(ParamDesc("param",Param::TYPE_STRING)
79 .set_local_name(_("Param"))
82 ret.push_back(ParamDesc("time",Param::TYPE_STRING)
83 .set_local_name(_("Time"))
91 Action::LayerParamDisconnect::is_candidate(const ParamList &x)
93 return candidate_check(get_param_vocab(),x);
97 Action::LayerParamDisconnect::set_param(const synfig::String& name, const Action::Param ¶m)
99 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
101 layer=param.get_layer();
106 if(name=="param" && param.get_type()==Param::TYPE_STRING)
108 param_name=param.get_string();
113 if(name=="time" && param.get_type()==Param::TYPE_TIME)
115 time=param.get_time();
120 return Action::CanvasSpecific::set_param(name,param);
124 Action::LayerParamDisconnect::is_ready()const
126 if(!layer || param_name.empty())
128 return Action::CanvasSpecific::is_ready();
132 Action::LayerParamDisconnect::perform()
134 if(!layer->dynamic_param_list().count(param_name))
135 throw Error(_("Layer Parameter is not connected to anything"));
137 old_value_node=layer->dynamic_param_list().find(param_name)->second;
138 layer->disconnect_dynamic_param(param_name);
140 if(new_value_node || ValueNode_DynamicList::Handle::cast_dynamic(old_value_node))
143 new_value_node=old_value_node.clone();
144 layer->connect_dynamic_param(param_name,new_value_node);
147 layer->set_param(param_name,(*old_value_node)(time));
150 old_value_node->changed();
154 if(get_canvas_interface())
156 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
161 Action::LayerParamDisconnect::undo()
163 layer->connect_dynamic_param(param_name,old_value_node);
165 /* if(layer->active() && get_canvas()->get_time()!=time)
171 old_value_node->changed();
175 if(get_canvas_interface())
177 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);