When a new document is made and saved, register it in the canvas map as if it had...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 18 Nov 2008 23:27:52 +0000 (23:27 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 18 Nov 2008 23:27:52 +0000 (23:27 +0000)
git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2214 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/canvas.cpp
synfig-core/trunk/src/synfig/loadcanvas.cpp
synfig-core/trunk/src/synfig/loadcanvas.h

index 5b27e59..303cdce 100644 (file)
@@ -39,6 +39,7 @@
 #include "time.h"
 #include "context.h"
 #include "layer_pastecanvas.h"
+#include "loadcanvas.h"
 #include <sigc++/bind.h>
 
 #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<synfig::String, etl::loose_handle<Canvas> >::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_();
+               }
        }
 }
 
index 5482fd9..28dff3e 100644 (file)
@@ -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());
 
index c527f03..bf5f053 100644 (file)
@@ -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);