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>
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
44 /* === M A C R O S ========================================================= */
46 ACTION_INIT(Action::LayerParamDisconnect);
47 ACTION_SET_NAME(Action::LayerParamDisconnect,"layer_param_disconnect");
48 ACTION_SET_LOCAL_NAME(Action::LayerParamDisconnect,_("Disconnect Layer Parameter"));
49 ACTION_SET_TASK(Action::LayerParamDisconnect,"disconnect");
50 ACTION_SET_CATEGORY(Action::LayerParamDisconnect,Action::CATEGORY_LAYER|Action::CATEGORY_VALUENODE);
51 ACTION_SET_PRIORITY(Action::LayerParamDisconnect,0);
52 ACTION_SET_VERSION(Action::LayerParamDisconnect,"0.0");
53 ACTION_SET_CVS_ID(Action::LayerParamDisconnect,"$Id$");
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Action::LayerParamDisconnect::LayerParamDisconnect():
68 Action::LayerParamDisconnect::get_param_vocab()
70 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
73 .set_local_name(_("Layer"))
76 ret.push_back(ParamDesc("param",Param::TYPE_STRING)
77 .set_local_name(_("Param"))
80 ret.push_back(ParamDesc("time",Param::TYPE_STRING)
81 .set_local_name(_("Time"))
89 Action::LayerParamDisconnect::is_candidate(const ParamList &x)
91 return candidate_check(get_param_vocab(),x);
95 Action::LayerParamDisconnect::set_param(const synfig::String& name, const Action::Param ¶m)
97 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
99 layer=param.get_layer();
104 if(name=="param" && param.get_type()==Param::TYPE_STRING)
106 param_name=param.get_string();
111 if(name=="time" && param.get_type()==Param::TYPE_TIME)
113 time=param.get_time();
118 return Action::CanvasSpecific::set_param(name,param);
122 Action::LayerParamDisconnect::is_ready()const
124 if(!layer || param_name.empty())
126 return Action::CanvasSpecific::is_ready();
130 Action::LayerParamDisconnect::perform()
132 if(!layer->dynamic_param_list().count(param_name))
133 throw Error(_("Layer Parameter is not connected to anything"));
135 old_value_node=layer->dynamic_param_list().find(param_name)->second;
136 layer->disconnect_dynamic_param(param_name);
138 if(new_value_node || ValueNode_DynamicList::Handle::cast_dynamic(old_value_node))
141 new_value_node=old_value_node.clone();
142 layer->connect_dynamic_param(param_name,new_value_node);
145 layer->set_param(param_name,(*old_value_node)(time));
148 old_value_node->changed();
152 if(get_canvas_interface())
154 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);
159 Action::LayerParamDisconnect::undo()
161 layer->connect_dynamic_param(param_name,old_value_node);
163 /* if(layer->active() && get_canvas()->get_time()!=time)
169 old_value_node->changed();
173 if(get_canvas_interface())
175 get_canvas_interface()->signal_layer_param_changed()(layer,param_name);