my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / canvasremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasremove.cpp
3 **      \brief Template File
4 **
5 **      $Id: canvasremove.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 "canvasremove.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::CanvasRemove);
45 ACTION_SET_NAME(Action::CanvasRemove,"canvas_remove");
46 ACTION_SET_LOCAL_NAME(Action::CanvasRemove,"Remove Canvas");
47 ACTION_SET_TASK(Action::CanvasRemove,"remove");
48 ACTION_SET_CATEGORY(Action::CanvasRemove,Action::CATEGORY_CANVAS);
49 ACTION_SET_PRIORITY(Action::CanvasRemove,0);
50 ACTION_SET_VERSION(Action::CanvasRemove,"0.0");
51 ACTION_SET_CVS_ID(Action::CanvasRemove,"$Id: canvasremove.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::CanvasRemove::CanvasRemove()
60 {
61 }
62
63 Action::ParamVocab
64 Action::CanvasRemove::get_param_vocab()
65 {
66         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
67         
68         return ret;
69 }
70
71 bool
72 Action::CanvasRemove::is_canidate(const ParamList &x)
73 {
74         if(canidate_check(get_param_vocab(),x))
75         {
76                 Canvas::Handle canvas=x.find("canvas")->second.get_canvas();
77                 assert(canvas);
78                 // We cannot remove the root canvas.
79                 if(canvas->is_root())
80                         return false;
81                 
82                 return true;
83         }
84         return false;
85 }
86
87 bool
88 Action::CanvasRemove::set_param(const synfig::String& name, const Action::Param &param)
89 {
90         return Action::CanvasSpecific::set_param(name,param);
91 }
92
93 bool
94 Action::CanvasRemove::is_ready()const
95 {
96         return Action::CanvasSpecific::is_ready();
97 }
98
99 void
100 Action::CanvasRemove::perform()
101 {
102         // We cannot remove the root canvas.
103         if(get_canvas()->is_root())
104                 throw Error(_("You cannot remove the root canvas!"));
105
106         if(get_canvas()->is_inline())
107                 throw Error(_("You cannot remove an inline canvas!"));
108         
109         parent_canvas=get_canvas()->parent();
110         canvas_id=get_canvas()->get_id();
111         
112         assert(parent_canvas);
113         
114         parent_canvas->remove_child_canvas(get_canvas());
115         
116         if(get_canvas_interface())
117         {
118                 get_canvas_interface()->signal_canvas_removed()(get_canvas());
119         }
120         else synfig::warning("CanvasInterface not set on action");
121 }
122
123 void
124 Action::CanvasRemove::undo()
125 {
126         parent_canvas->add_child_canvas(get_canvas(), canvas_id);
127
128         if(get_canvas_interface())
129         {
130                 get_canvas_interface()->signal_canvas_added()(get_canvas());
131         }
132         else synfig::warning("CanvasInterface not set on action");
133 }