my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / groupremovelayers.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file action_layerremove.cpp
3 **      \brief Template File
4 **
5 **      $Id: groupremovelayers.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "groupremovelayers.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43
44 ACTION_INIT(Action::GroupRemoveLayers);
45 ACTION_SET_NAME(Action::GroupRemoveLayers,"group_remove_layers");
46 ACTION_SET_LOCAL_NAME(Action::GroupRemoveLayers,"Remove Layers from a Group");
47 ACTION_SET_TASK(Action::GroupRemoveLayers,"remove");
48 ACTION_SET_CATEGORY(Action::GroupRemoveLayers,Action::CATEGORY_LAYER|Action::CATEGORY_GROUP);
49 ACTION_SET_PRIORITY(Action::GroupRemoveLayers,0);
50 ACTION_SET_VERSION(Action::GroupRemoveLayers,"0.0");
51 ACTION_SET_CVS_ID(Action::GroupRemoveLayers,"$Id: groupremovelayers.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Action::GroupRemoveLayers::GroupRemoveLayers()
60 {
61 }
62
63 Action::ParamVocab
64 Action::GroupRemoveLayers::get_param_vocab()
65 {
66         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
67         
68         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
69                 .set_local_name(_("Layer"))
70                 .set_desc(_("Layer to be added to group"))
71                 .set_supports_multiple()
72         );
73
74         ret.push_back(ParamDesc("group",Param::TYPE_STRING)
75                 .set_local_name(_("Group"))
76                 .set_desc(_("Name of the Group to add the Layers to"))
77                 .set_user_supplied()
78         );
79         
80         return ret;
81 }
82
83 bool
84 Action::GroupRemoveLayers::is_canidate(const ParamList &x)
85 {
86         return canidate_check(get_param_vocab(),x);
87 }
88
89 bool
90 Action::GroupRemoveLayers::set_param(const synfig::String& name, const Action::Param &param)
91 {
92         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
93         {
94                 std::pair<synfig::Layer::Handle,String> layer_pair;
95                 layer_pair.first=param.get_layer();
96                 layer_list.push_back(layer_pair);
97                 
98                 return true;
99         }
100
101         if(name=="group" && param.get_type()==Param::TYPE_STRING)
102         {
103                 group=param.get_string();
104                 
105                 return true;
106         }
107
108         return Action::CanvasSpecific::set_param(name,param);
109 }
110
111 bool
112 Action::GroupRemoveLayers::is_ready()const
113 {
114         if(layer_list.empty() || group.empty())
115                 return false;
116         return Action::CanvasSpecific::is_ready();
117 }
118
119 void
120 Action::GroupRemoveLayers::perform()
121 {
122         std::list<std::pair<synfig::Layer::Handle,String> >::iterator iter;
123         for(iter=layer_list.begin();iter!=layer_list.end();++iter)
124         {
125                 Layer::Handle layer(iter->first);
126                 iter->second=layer->get_group();
127                 
128                 layer->remove_from_group(group);
129         }
130 }
131
132 void
133 Action::GroupRemoveLayers::undo()
134 {
135         std::list<std::pair<synfig::Layer::Handle,String> >::iterator iter;
136         for(iter=layer_list.begin();iter!=layer_list.end();++iter)
137         {
138                 Layer::Handle layer(iter->first);
139                 
140                 layer->add_to_group(iter->second);
141         }
142 }