Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / src / synfigapp / actions / valuenodedynamiclistremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenodedynamiclistremove.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenodedynamiclistremove.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #include <synfigapp/general.h>
36
37 #endif
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace synfigapp;
43 using namespace Action;
44
45 /* === M A C R O S ========================================================= */
46
47 ACTION_INIT(Action::ValueNodeDynamicListRemove);
48 ACTION_SET_NAME(Action::ValueNodeDynamicListRemove,"value_node_dynamic_list_remove");
49 ACTION_SET_LOCAL_NAME(Action::ValueNodeDynamicListRemove,N_("Remove Item"));
50 ACTION_SET_TASK(Action::ValueNodeDynamicListRemove,"remove");
51 ACTION_SET_CATEGORY(Action::ValueNodeDynamicListRemove,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE|Action::CATEGORY_HIDDEN);
52 ACTION_SET_PRIORITY(Action::ValueNodeDynamicListRemove,-19);
53 ACTION_SET_VERSION(Action::ValueNodeDynamicListRemove,"0.0");
54 ACTION_SET_CVS_ID(Action::ValueNodeDynamicListRemove,"$Id$");
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 Action::ValueNodeDynamicListRemove::ValueNodeDynamicListRemove()
63 {
64         index=0;
65         set_dirty(true);
66 }
67
68 Action::ParamVocab
69 Action::ValueNodeDynamicListRemove::get_param_vocab()
70 {
71         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
72
73         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
74                 .set_local_name(_("ValueDesc"))
75         );
76
77         return ret;
78 }
79
80 bool
81 Action::ValueNodeDynamicListRemove::is_candidate(const ParamList &x)
82 {
83         if(candidate_check(get_param_vocab(),x))
84         {
85                 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
86                 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
87                         return false;
88
89                 return true;
90         }
91         return false;
92 }
93
94 bool
95 Action::ValueNodeDynamicListRemove::set_param(const synfig::String& name, const Action::Param &param)
96 {
97         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
98         {
99                 ValueDesc value_desc(param.get_value_desc());
100
101                 if(!value_desc.parent_is_value_node())
102                         return false;
103
104                 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
105
106                 if(!value_node)
107                         return false;
108
109                 index=value_desc.get_index();
110
111                 return true;
112         }
113
114         return Action::CanvasSpecific::set_param(name,param);
115 }
116
117 bool
118 Action::ValueNodeDynamicListRemove::is_ready()const
119 {
120         if(!value_node)
121                 return false;
122         return Action::CanvasSpecific::is_ready();
123 }
124
125 void
126 Action::ValueNodeDynamicListRemove::perform()
127 {
128         if(index>=value_node->link_count())
129                 index=value_node->link_count()-1;
130
131         list_entry=value_node->list[index];
132         value_node->erase((value_node->list.begin()+index)->value_node);
133
134         // Signal that a layer has been inserted
135         value_node->changed();
136 /*_if(get_canvas_interface())
137         {
138                 get_canvas_interface()->signal_value_node_changed()(value_node);
139         }
140         else synfig::warning("CanvasInterface not set on action");*/
141 }
142
143 void
144 Action::ValueNodeDynamicListRemove::undo()
145 {
146         value_node->add(list_entry,index);
147
148         // Signal that a layer has been inserted
149         value_node->changed();
150 /*_if(get_canvas_interface())
151         {
152                 get_canvas_interface()->signal_value_node_changed()(value_node);
153         }
154         else synfig::warning("CanvasInterface not set on action");*/
155 }