1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodedynamiclistinsert.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenodedynamiclistinsert.h"
34 #include <synfigapp/canvasinterface.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::ValueNodeDynamicListInsert);
49 ACTION_SET_NAME(Action::ValueNodeDynamicListInsert,"value_node_dynamic_list_insert");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListInsert,N_("Insert Item"));
51 ACTION_SET_TASK(Action::ValueNodeDynamicListInsert,"insert");
52 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListInsert,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE|Action::CATEGORY_HIDDEN);
53 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListInsert,-20);
54 ACTION_SET_VERSION(Action::ValueNodeDynamicListInsert,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListInsert,"$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::ValueNodeDynamicListInsert::ValueNodeDynamicListInsert()
72 Action::ValueNodeDynamicListInsert::get_param_vocab()
74 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
76 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
77 .set_local_name(_("ValueDesc"))
79 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
80 .set_local_name(_("Time"))
83 ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
84 .set_local_name(_("Origin"))
87 ret.push_back(ParamDesc("item",Param::TYPE_VALUENODE)
88 .set_local_name(_("ValueNode to insert"))
96 Action::ValueNodeDynamicListInsert::is_candidate(const ParamList &x)
98 if (!candidate_check(get_param_vocab(),x))
101 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
103 return (value_desc.parent_is_value_node() &&
104 // We need a dynamic list.
105 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
109 Action::ValueNodeDynamicListInsert::set_param(const synfig::String& name, const Action::Param ¶m)
111 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
113 ValueDesc value_desc(param.get_value_desc());
115 if(!value_desc.parent_is_value_node())
118 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
123 index=value_desc.get_index();
125 value_node_bline=ValueNode_BLine::Handle::cast_dynamic(value_desc.get_parent_value_node());
127 list_entry=value_node->create_list_entry(index,time,origin);
129 list_entry.value_node=item;
131 assert(list_entry.value_node.rcount()==1);
135 if(name=="time" && param.get_type()==Param::TYPE_TIME)
137 time=param.get_time();
141 if(name=="item" && param.get_type()==Param::TYPE_VALUENODE)
143 item=param.get_value_node();
145 list_entry.value_node=item;
149 if(name=="origin" && param.get_type()==Param::TYPE_REAL)
151 origin=param.get_real();
156 return Action::CanvasSpecific::set_param(name,param);
160 Action::ValueNodeDynamicListInsert::is_ready()const
164 return Action::CanvasSpecific::is_ready();
168 Action::ValueNodeDynamicListInsert::perform()
170 if(index>value_node->link_count())
171 index=value_node->link_count();
173 value_node->add(list_entry,index);
174 assert(list_entry.value_node.rcount()>=2);
176 // Signal that a layer has been inserted
177 value_node->changed();
178 /*_if(get_canvas_interface())
180 get_canvas_interface()->signal_value_node_changed()(value_node);
182 else synfig::warning("CanvasInterface not set on action");*/
186 Action::ValueNodeDynamicListInsert::undo()
188 assert(list_entry.value_node.rcount()>=2);
189 value_node->erase((value_node->list.begin()+index)->value_node);
190 assert(list_entry.value_node.rcount()>=1);
192 // Signal that a layer has been inserted
193 value_node->changed();
194 /*_if(get_canvas_interface())
196 get_canvas_interface()->signal_value_node_changed()(value_node);
198 else synfig::warning("CanvasInterface not set on action");*/