1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenodedynamiclistrotateorder.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 "valuenodedynamiclistrotateorder.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::ValueNodeDynamicListRotateOrder);
49 ACTION_SET_NAME(Action::ValueNodeDynamicListRotateOrder,"value_node_dynamic_list_rotate_order");
50 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListRotateOrder,N_("Rotate Order"));
51 ACTION_SET_TASK(Action::ValueNodeDynamicListRotateOrder,"rotate");
52 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListRotateOrder,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
53 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListRotateOrder,0);
54 ACTION_SET_VERSION(Action::ValueNodeDynamicListRotateOrder,"0.0");
55 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListRotateOrder,"$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::ValueNodeDynamicListRotateOrder::ValueNodeDynamicListRotateOrder()
70 Action::ValueNodeDynamicListRotateOrder::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
75 .set_local_name(_("ValueDesc"))
82 Action::ValueNodeDynamicListRotateOrder::is_candidate(const ParamList &x)
84 if (!candidate_check(get_param_vocab(),x))
87 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
89 return (value_desc.parent_is_value_node() &&
90 // We need a dynamic list.
91 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
95 Action::ValueNodeDynamicListRotateOrder::set_param(const synfig::String& name, const Action::Param ¶m)
97 if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
99 ValueDesc value_desc(param.get_value_desc());
101 if(!value_desc.parent_is_value_node())
104 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
109 index=value_desc.get_index();
114 return Action::CanvasSpecific::set_param(name,param);
118 Action::ValueNodeDynamicListRotateOrder::is_ready()const
122 return Action::CanvasSpecific::is_ready();
126 Action::ValueNodeDynamicListRotateOrder::prepare()
130 for(int i(0);i<(value_node->link_count()-index)%value_node->link_count();++i)
132 ValueDesc value_desc(value_node,value_node->link_count()-1-i);
133 ValueNode::Handle child(value_desc.get_value_node());
136 Action::Handle action(Action::create("value_node_dynamic_list_remove"));
138 action->set_param("canvas",get_canvas());
139 action->set_param("canvas_interface",get_canvas_interface());
140 action->set_param("value_desc",ValueDesc(value_node,value_node->link_count()-1));
142 assert(action->is_ready());
143 if(!action->is_ready())
144 throw Error(Error::TYPE_NOTREADY);
149 action=Action::create("value_node_dynamic_list_insert");
151 action->set_param("canvas",get_canvas());
152 action->set_param("canvas_interface",get_canvas_interface());
153 action->set_param("value_desc",ValueDesc(value_node,0));
154 action->set_param("item",child);
156 assert(action->is_ready());
157 if(!action->is_ready())
158 throw Error(Error::TYPE_NOTREADY);