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>
35 #include <synfigapp/general.h>
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
45 /* === M A C R O S ========================================================= */
47 ACTION_INIT(Action::ValueNodeDynamicListInsert);
48 ACTION_SET_NAME(Action::ValueNodeDynamicListInsert,"value_node_dynamic_list_insert");
49 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListInsert,N_("Insert Item"));
50 ACTION_SET_TASK(Action::ValueNodeDynamicListInsert,"insert");
51 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListInsert,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE|Action::CATEGORY_HIDDEN);
52 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListInsert,-20);
53 ACTION_SET_VERSION(Action::ValueNodeDynamicListInsert,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListInsert,"$Id$");
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 Action::ValueNodeDynamicListInsert::ValueNodeDynamicListInsert()
71 Action::ValueNodeDynamicListInsert::get_param_vocab()
73 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
76 .set_local_name(_("ValueDesc"))
78 ret.push_back(ParamDesc("time",Param::TYPE_TIME)
79 .set_local_name(_("Time"))
82 ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
83 .set_local_name(_("Origin"))
86 ret.push_back(ParamDesc("item",Param::TYPE_VALUENODE)
87 .set_local_name(_("ValueNode to insert"))
95 Action::ValueNodeDynamicListInsert::is_candidate(const ParamList &x)
97 if(candidate_check(get_param_vocab(),x))
99 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
100 if(!value_desc.parent_is_value_node() || !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");*/