Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / synfigapp / actions / groupremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file groupremove.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 "groupremove.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::GroupRemove);
48 ACTION_SET_NAME(Action::GroupRemove,"group_remove");
49 ACTION_SET_LOCAL_NAME(Action::GroupRemove,N_("Remove Group"));
50 ACTION_SET_TASK(Action::GroupRemove,"remove");
51 ACTION_SET_CATEGORY(Action::GroupRemove,Action::CATEGORY_GROUP);
52 ACTION_SET_PRIORITY(Action::GroupRemove,0);
53 ACTION_SET_VERSION(Action::GroupRemove,"0.0");
54 ACTION_SET_CVS_ID(Action::GroupRemove,"$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::GroupRemove::GroupRemove()
63 {
64 }
65
66 Action::ParamVocab
67 Action::GroupRemove::get_param_vocab()
68 {
69         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
70
71         ret.push_back(ParamDesc("group",Param::TYPE_STRING)
72                 .set_local_name(_("Group"))
73                 .set_desc(_("Name of the Group to remove"))
74         );
75
76         return ret;
77 }
78
79 bool
80 Action::GroupRemove::is_candidate(const ParamList &x)
81 {
82         bool ret(candidate_check(get_param_vocab(),x));
83         if(!ret)
84         {
85                 synfig::info("Action::GroupRemove::is_candidate(): failed candidate check");
86                 ParamList::const_iterator iter;
87                 for(iter=x.begin();iter!=x.end();++iter)
88                 {
89                         synfig::info("PARAM: %s",iter->first.c_str());
90                 }
91         }
92         return ret;
93 }
94
95 bool
96 Action::GroupRemove::set_param(const synfig::String& name, const Action::Param &param)
97 {
98         if(name=="group" && param.get_type()==Param::TYPE_STRING)
99         {
100                 group=param.get_string();
101
102                 return true;
103         }
104
105         return Action::CanvasSpecific::set_param(name,param);
106 }
107
108 bool
109 Action::GroupRemove::is_ready()const
110 {
111         if(group.empty())
112                 return false;
113         return Action::CanvasSpecific::is_ready();
114 }
115
116 void
117 Action::GroupRemove::perform()
118 {
119         layer_list=get_canvas()->get_layers_in_group(group);
120
121         std::set<synfig::Layer::Handle>::iterator iter;
122         for(iter=layer_list.begin();iter!=layer_list.end();++iter)
123         {
124                 (*iter)->remove_from_group(group);
125         }
126 }
127
128 void
129 Action::GroupRemove::undo()
130 {
131         std::set<synfig::Layer::Handle>::iterator iter;
132         for(iter=layer_list.begin();iter!=layer_list.end();++iter)
133         {
134                 (*iter)->add_to_group(group);
135         }
136 }