1 /* === S Y N F I G ========================================================= */
2 /*! \file synfigapp/instance.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include "canvasinterface.h"
36 #include <synfig/loadcanvas.h>
37 #include <synfig/savecanvas.h>
38 #include <synfig/valuenode_composite.h>
39 #include <synfig/valuenode_radialcomposite.h>
40 #include <synfig/valuenode_reference.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace synfigapp;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 static std::map<loose_handle<Canvas>, loose_handle<Instance> > instance_map_;
58 /* === P R O C E D U R E S ================================================= */
61 synfigapp::is_editable(synfig::ValueNode::Handle value_node)
63 if(ValueNode_Const::Handle::cast_dynamic(value_node)
64 || ValueNode_Animated::Handle::cast_dynamic(value_node)
65 || ValueNode_Composite::Handle::cast_dynamic(value_node)
66 || ValueNode_RadialComposite::Handle::cast_dynamic(value_node)
67 || ValueNode_Reference::Handle::cast_dynamic(value_node)
74 synfigapp::find_instance(etl::handle<synfig::Canvas> canvas)
76 if(instance_map_.count(canvas)==0)
78 return instance_map_[canvas];
81 /* === M E T H O D S ======================================================= */
83 Instance::Instance(Canvas::Handle canvas):
84 CVSInfo(canvas->get_file_name()),
87 assert(canvas->is_root());
89 unset_selection_manager();
91 instance_map_[canvas]=this;
92 } // END of synfigapp::Instance::Instance()
95 Instance::create(Canvas::Handle canvas)
97 // Construct a new instance
98 handle<Instance> instance(new Instance(canvas));
101 } // END of synfigapp::Instance::create()
104 Instance::get_file_name()const
106 return get_canvas()->get_file_name();
110 Instance::set_file_name(const synfig::String &name)
112 get_canvas()->set_file_name(name);
113 CVSInfo::set_file_name(name);
116 Instance::~Instance()
118 instance_map_.erase(canvas_);
119 synfig::info("studio::Instance::~Instance(): Deleted");
120 } // END of studio::Instance::~Instance()
122 handle<CanvasInterface>
123 Instance::find_canvas_interface(handle<Canvas> canvas)
127 while(canvas->is_inline())
128 canvas=canvas->parent();
130 CanvasInterfaceList::iterator iter;
132 for(iter=canvas_interface_list().begin();iter!=canvas_interface_list().end();iter++)
133 if((*iter)->get_canvas()==canvas)
136 return CanvasInterface::create(this,canvas);
140 Instance::save()const
142 bool ret=save_canvas(get_file_name(),canvas_);
145 reset_action_count();
146 const_cast<sigc::signal<void>& >(signal_saved_)();
152 Instance::save_as(const std::string &file_name)
156 String old_file_name(get_file_name());
158 set_file_name(file_name);
160 ret=save_canvas(file_name,canvas_);
164 reset_action_count();
168 set_file_name(old_file_name);
170 signal_filename_changed_();