my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / layeradd.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layeradd.cpp
3 **      \brief Template File
4 **
5 **      $Id: layeradd.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 "layeradd.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::LayerAdd);
45 ACTION_SET_NAME(Action::LayerAdd,"layer_add");
46 ACTION_SET_LOCAL_NAME(Action::LayerAdd,"Add Layer");
47 ACTION_SET_TASK(Action::LayerAdd,"add");
48 ACTION_SET_CATEGORY(Action::LayerAdd,Action::CATEGORY_LAYER);
49 ACTION_SET_PRIORITY(Action::LayerAdd,0);
50 ACTION_SET_VERSION(Action::LayerAdd,"0.0");
51 ACTION_SET_CVS_ID(Action::LayerAdd,"$Id: layeradd.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::LayerAdd::LayerAdd()
60 {
61 }
62
63 Action::ParamVocab
64 Action::LayerAdd::get_param_vocab()
65 {
66         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
67         
68         ret.push_back(ParamDesc("new",Param::TYPE_LAYER)
69                 .set_local_name(_("New Layer"))
70                 .set_desc(_("Layer to be added"))
71         );
72         
73         return ret;
74 }
75
76 bool
77 Action::LayerAdd::is_canidate(const ParamList &x)
78 {
79         return canidate_check(get_param_vocab(),x);
80 }
81
82 bool
83 Action::LayerAdd::set_param(const synfig::String& name, const Action::Param &param)
84 {
85         if(name=="new" && param.get_type()==Param::TYPE_LAYER)
86         {
87                 layer=param.get_layer();
88                 
89                 return true;
90         }
91
92         return Action::CanvasSpecific::set_param(name,param);
93 }
94
95 bool
96 Action::LayerAdd::is_ready()const
97 {
98         if(!layer)
99                 return false;
100         return Action::CanvasSpecific::is_ready();
101 }
102
103 void
104 Action::LayerAdd::perform()
105 {
106         // Set the layer's canvas
107         layer->set_canvas(get_canvas());
108                 
109         // Push the layer onto the front of the canvas
110         get_canvas()->push_front(layer);        
111
112         // Mark ourselves as dirty if necessary
113         //set_dirty(layer->active());
114         
115         // Signal that a layer has been inserted
116         if(get_canvas_interface())
117         {
118                 get_canvas_interface()->signal_layer_inserted()(layer,0);
119         }
120         else synfig::warning("CanvasInterface not set on action");
121 }
122
123 void
124 Action::LayerAdd::undo()
125 {
126         // Find the iterator for the layer
127         Canvas::iterator iter=find(get_canvas()->begin(),get_canvas()->end(),layer);
128                 
129         // If we couldn't find the layer in the canvas, then bail
130         if(*iter!=layer)
131                 throw Error(_("This layer doesn't exist anymore."));
132         
133         // Remove the layer from the canvas
134         get_canvas()->erase(iter);
135
136         // Mark ourselves as dirty if necessary
137         //set_dirty(layer->active());
138         
139         // Signal that a layer has been inserted
140         if(get_canvas_interface())
141         {
142                 get_canvas_interface()->signal_layer_removed()(layer);
143         }
144         else synfig::warning("CanvasInterface not set on action");
145 }