1 /* === S Y N F I G ========================================================= */
2 /*! \file synfigapp/instance.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include "canvasinterface.h"
35 #include <synfig/loadcanvas.h>
36 #include <synfig/savecanvas.h>
37 #include <synfig/valuenode_composite.h>
38 #include <synfig/valuenode_radialcomposite.h>
39 #include <synfig/valuenode_reference.h>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace synfigapp;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 static std::map<loose_handle<Canvas>, loose_handle<Instance> > instance_map_;
57 /* === P R O C E D U R E S ================================================= */
60 synfigapp::is_editable(synfig::ValueNode::Handle value_node)
62 if(ValueNode_Const::Handle::cast_dynamic(value_node)
63 || ValueNode_Animated::Handle::cast_dynamic(value_node)
64 || ValueNode_Composite::Handle::cast_dynamic(value_node)
65 || ValueNode_RadialComposite::Handle::cast_dynamic(value_node)
66 || ValueNode_Reference::Handle::cast_dynamic(value_node)
73 synfigapp::find_instance(etl::handle<synfig::Canvas> canvas)
75 if(instance_map_.count(canvas)==0)
77 return instance_map_[canvas];
80 /* === M E T H O D S ======================================================= */
82 Instance::Instance(Canvas::Handle canvas):
83 CVSInfo(canvas->get_file_name()),
86 assert(canvas->is_root());
88 unset_selection_manager();
90 instance_map_[canvas]=this;
91 } // END of synfigapp::Instance::Instance()
94 Instance::create(Canvas::Handle canvas)
96 // Construct a new instance
97 handle<Instance> instance(new Instance(canvas));
100 } // END of synfigapp::Instance::create()
103 Instance::get_file_name()const
105 return get_canvas()->get_file_name();
109 Instance::set_file_name(const synfig::String &name)
111 get_canvas()->set_file_name(name);
112 CVSInfo::set_file_name(name);
115 Instance::~Instance()
117 instance_map_.erase(canvas_);
118 synfig::info("studio::Instance::~Instance(): Deleted");
119 } // END of studio::Instance::~Instance()
121 handle<CanvasInterface>
122 Instance::find_canvas_interface(handle<Canvas> canvas)
126 while(canvas->is_inline())
127 canvas=canvas->parent();
129 CanvasInterfaceList::iterator iter;
131 for(iter=canvas_interface_list().begin();iter!=canvas_interface_list().end();iter++)
132 if((*iter)->get_canvas()==canvas)
135 return CanvasInterface::create(this,canvas);
139 Instance::save()const
141 bool ret=save_canvas(get_file_name(),canvas_);
144 reset_action_count();
145 const_cast<sigc::signal<void>& >(signal_saved_)();
151 Instance::save_as(const std::string &file_name)
155 String old_file_name(get_file_name());
157 set_file_name(file_name);
159 ret=save_canvas(file_name,canvas_);
163 reset_action_count();
167 set_file_name(old_file_name);
169 signal_filename_changed_();