From: dooglus Date: Tue, 18 Nov 2008 23:27:52 +0000 (+0000) Subject: When a new document is made and saved, register it in the canvas map as if it had... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fed432fb09efa7eaecf220c494feb4f3b59b922c;p=synfig.git When a new document is made and saved, register it in the canvas map as if it had been loaded. Previously only documents that were loaded from disk were entered into the map causing errors in some situations. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2214 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/canvas.cpp b/synfig-core/trunk/src/synfig/canvas.cpp index 5b27e59..303cdce 100644 --- a/synfig-core/trunk/src/synfig/canvas.cpp +++ b/synfig-core/trunk/src/synfig/canvas.cpp @@ -39,6 +39,7 @@ #include "time.h" #include "context.h" #include "layer_pastecanvas.h" +#include "loadcanvas.h" #include #endif @@ -956,8 +957,24 @@ Canvas::set_file_name(const String &file_name) parent()->set_file_name(file_name); else { + String old_name(file_name_); file_name_=file_name; - signal_file_name_changed_(); + + // when a canvas is made, its name is "" + // then, before it's saved or even edited, it gets a name like "Synfig Animation 23", in the local language + // we don't want to register the canvas' filename in the canvas map until it gets a real filename + if (old_name != "") + { + file_name_=file_name; + std::map >::iterator iter; + for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter) + if(iter->second==this) + break; + if (iter == get_open_canvas_map().end()) + CanvasParser::register_canvas_in_map(this, file_name); + else + signal_file_name_changed_(); + } } } diff --git a/synfig-core/trunk/src/synfig/loadcanvas.cpp b/synfig-core/trunk/src/synfig/loadcanvas.cpp index 5482fd9..28dff3e 100644 --- a/synfig-core/trunk/src/synfig/loadcanvas.cpp +++ b/synfig-core/trunk/src/synfig/loadcanvas.cpp @@ -2120,6 +2120,14 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in return canvas; } +void +CanvasParser::register_canvas_in_map(Canvas::Handle canvas, String as) +{ + get_open_canvas_map()[etl::absolute_path(as)]=canvas; + canvas->signal_deleted().connect(sigc::bind(sigc::ptr_fun(_remove_from_open_canvas_map),canvas.get())); + canvas->signal_file_name_changed().connect(sigc::bind(sigc::ptr_fun(_canvas_file_name_changed),canvas.get())); +} + Canvas::Handle CanvasParser::parse_from_file_as(const String &file_,const String &as_,String &errors) { @@ -2139,9 +2147,7 @@ CanvasParser::parse_from_file_as(const String &file_,const String &as_,String &e { Canvas::Handle canvas(parse_canvas(parser.get_document()->get_root_node(),0,false,as)); if (!canvas) return canvas; - get_open_canvas_map()[etl::absolute_path(as)]=canvas; - canvas->signal_deleted().connect(sigc::bind(sigc::ptr_fun(_remove_from_open_canvas_map),canvas.get())); - canvas->signal_file_name_changed().connect(sigc::bind(sigc::ptr_fun(_canvas_file_name_changed),canvas.get())); + register_canvas_in_map(canvas, as); const ValueNodeList& value_node_list(canvas->value_node_list()); diff --git a/synfig-core/trunk/src/synfig/loadcanvas.h b/synfig-core/trunk/src/synfig/loadcanvas.h index c527f03..bf5f053 100644 --- a/synfig-core/trunk/src/synfig/loadcanvas.h +++ b/synfig-core/trunk/src/synfig/loadcanvas.h @@ -119,6 +119,8 @@ public: const synfig::String& get_errors_text()const { return errors_text; } const synfig::String& get_warnings_text()const { return warnings_text; } + static void register_canvas_in_map(Canvas::Handle canvas, String as); + //! \todo writeme Canvas::Handle parse_from_file_as(const String &filename,const String &as,String &errors);