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
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 "valuenodedynamiclistinsert.h"
33 #include <synfigapp/canvasinterface.h>
39 using namespace synfig;
40 using namespace synfigapp;
41 using namespace Action;
43 /* === M A C R O S ========================================================= */
45 ACTION_INIT(Action::ValueNodeDynamicListInsert);
46 ACTION_SET_NAME(Action::ValueNodeDynamicListInsert,"value_node_dynamic_list_insert");
47 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListInsert,"Insert Item");
48 ACTION_SET_TASK(Action::ValueNodeDynamicListInsert,"insert");
49 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListInsert,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE|Action::CATEGORY_HIDDEN);
50 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListInsert,-20);
51 ACTION_SET_VERSION(Action::ValueNodeDynamicListInsert,"0.0");
52 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListInsert,"$Id$");
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 Action::ValueNodeDynamicListInsert::ValueNodeDynamicListInsert()
69 Action::ValueNodeDynamicListInsert::get_param_vocab()
71 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
74 .set_local_name(_("ValueDesc"))
76 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
77 .set_local_name(_("Time"))
80 ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
81 .set_local_name(_("Origin"))
84 ret.push_back(ParamDesc("item",Param::TYPE_VALUENODE)
85 .set_local_name(_("ValueNode to insert"))
93 Action::ValueNodeDynamicListInsert::is_candidate(const ParamList &x)
95 if(candidate_check(get_param_vocab(),x))
97 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
98 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
107 Action::ValueNodeDynamicListInsert::set_param(const synfig::String& name, const Action::Param ¶m)
109 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
111 ValueDesc value_desc(param.get_value_desc());
113 if(!value_desc.parent_is_value_node())
116 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
121 index=value_desc.get_index();
123 value_node_bline=ValueNode_BLine::Handle::cast_dynamic(value_desc.get_parent_value_node());
125 list_entry=value_node->create_list_entry(index,time,origin);
127 list_entry.value_node=item;
129 assert(list_entry.value_node.rcount()==1);
133 if(name=="time" && param.get_type()==Param::TYPE_TIME)
135 time=param.get_time();
139 if(name=="item" && param.get_type()==Param::TYPE_VALUENODE)
141 item=param.get_value_node();
143 list_entry.value_node=item;
147 if(name=="origin" && param.get_type()==Param::TYPE_REAL)
149 origin=param.get_real();
154 return Action::CanvasSpecific::set_param(name,param);
158 Action::ValueNodeDynamicListInsert::is_ready()const
162 return Action::CanvasSpecific::is_ready();
166 Action::ValueNodeDynamicListInsert::perform()
168 if(index>value_node->link_count())
169 index=value_node->link_count();
171 value_node->add(list_entry,index);
172 assert(list_entry.value_node.rcount()>=2);
174 // Signal that a layer has been inserted
175 value_node->changed();
176 /*_if(get_canvas_interface())
178 get_canvas_interface()->signal_value_node_changed()(value_node);
180 else synfig::warning("CanvasInterface not set on action");*/
184 Action::ValueNodeDynamicListInsert::undo()
186 assert(list_entry.value_node.rcount()>=2);
187 value_node->erase((value_node->list.begin()+index)->value_node);
188 assert(list_entry.value_node.rcount()>=1);
190 // Signal that a layer has been inserted
191 value_node->changed();
192 /*_if(get_canvas_interface())
194 get_canvas_interface()->signal_value_node_changed()(value_node);
196 else synfig::warning("CanvasInterface not set on action");*/