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