When a .sif file fails to load, display the error messages in the studio GUI, not...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sun, 26 Oct 2008 20:01:02 +0000 (20:01 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sun, 26 Oct 2008 20:01:02 +0000 (20:01 +0000)
git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2132 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
synfig-core/trunk/src/tool/main.cpp
synfig-studio/trunk/src/gtkmm/app.cpp
synfig-studio/trunk/src/synfigapp/canvasinterface.cpp

index 67f06b9..5592aa0 100644 (file)
@@ -47,7 +47,7 @@ using namespace synfig;
 using namespace etl;
 using namespace std;
 
-namespace synfig { extern Canvas::Handle open_canvas(const String &filename); };
+namespace synfig { extern Canvas::Handle open_canvas(const String &filename, String &errors); };
 
 /* === M A C R O S ========================================================= */
 
@@ -537,10 +537,11 @@ Canvas::surefind_canvas(const String &id)
                        external_canvas=externals_[file_name];
                else
                {
+                       String errors;
                        if(is_absolute_path(file_name))
-                               external_canvas=open_canvas(file_name);
+                               external_canvas=open_canvas(file_name, errors);
                        else
-                               external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name);
+                               external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name, errors);
 
                        if(!external_canvas)
                                throw Exception::FileNotFound(file_name);
@@ -622,10 +623,11 @@ Canvas::find_canvas(const String &id)const
                        external_canvas=externals_[file_name];
                else
                {
+                       String errors;
                        if(is_absolute_path(file_name))
-                               external_canvas=open_canvas(file_name);
+                               external_canvas=open_canvas(file_name, errors);
                        else
-                               external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name);
+                               external_canvas=open_canvas(get_file_path()+ETL_DIRECTORY_SEPARATOR+file_name, errors);
 
                        if(!external_canvas)
                                throw Exception::FileNotFound(file_name);
index e4b2e15..79a3ec1 100644 (file)
@@ -121,31 +121,25 @@ static void _canvas_file_name_changed(Canvas *x)
 }
 
 Canvas::Handle
-synfig::open_canvas(const String &filename)
+synfig::open_canvas(const String &filename,String &errors)
 {
-       CanvasParser parser;
-
-       parser.set_allow_errors(true);
-
-       Canvas::Handle canvas=parser.parse_from_file(filename);
-
-       if(parser.error_count())
-               return Canvas::Handle();
-
-       return canvas;
+       return open_canvas_as(filename, filename, errors);
 }
 
 Canvas::Handle
-synfig::open_canvas_as(const String &filename,const String &as)
+synfig::open_canvas_as(const String &filename,const String &as,String &errors)
 {
        CanvasParser parser;
 
        parser.set_allow_errors(true);
 
-       Canvas::Handle canvas=parser.parse_from_file_as(filename,as);
+       Canvas::Handle canvas=parser.parse_from_file_as(filename,as,errors);
 
        if(parser.error_count())
+       {
+               errors = parser.get_errors_text();
                return Canvas::Handle();
+       }
 
        return canvas;
 }
@@ -195,6 +189,7 @@ CanvasParser::error(xmlpp::Node *element, const String &text)
 {
        string str=strprintf("%s:<%s>:%d: error: ",filename.c_str(),element->get_name().c_str(),element->get_line())+text;
        total_errors_++;
+       errors_text += "  " + str + "\n";
        if(!allow_errors_)
                throw runtime_error(str);
        cerr<<str<<endl;
@@ -2100,13 +2095,7 @@ CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool in
 }
 
 Canvas::Handle
-CanvasParser::parse_from_file(const String &file)
-{
-       return parse_from_file_as(file,file);
-}
-
-Canvas::Handle
-CanvasParser::parse_from_file_as(const String &file_,const String &as_)
+CanvasParser::parse_from_file_as(const String &file_,const String &as_,String &errors)
 {
        try
        {
@@ -2154,12 +2143,14 @@ CanvasParser::parse_from_file_as(const String &file_,const String &as_)
        catch(const std::exception& ex)
        {
                synfig::error("Standard Exception: "+String(ex.what()));
+               errors = ex.what();
                return Canvas::Handle();
        }
        catch(const String& str)
        {
                cerr<<str<<endl;
                //      synfig::error(str);
+               errors = str;
                return Canvas::Handle();
        }
        return Canvas::Handle();
index 3c9ce10..be093fe 100644 (file)
@@ -73,6 +73,8 @@ private:
 
        String path;
 
+       String errors_text;
+
        GUID guid_;
 
        /*
@@ -113,10 +115,10 @@ public:
 
        const synfig::String& get_path()const { return path; }
 
-       //! \todo writeme
-       Canvas::Handle parse_from_file(const String &filename);
+       const synfig::String& get_errors_text()const { return errors_text; }
 
-       Canvas::Handle parse_from_file_as(const String &filename,const String &as);
+       //! \todo writeme
+       Canvas::Handle parse_from_file_as(const String &filename,const String &as,String &errors);
 
        //! \todo writeme
        Canvas::Handle parse_from_string(const String &data);
@@ -169,8 +171,8 @@ private:
 
 //!    Loads a canvas from \a filename
 /*!    \return The Canvas's handle on success, an empty handle on failure */
-extern Canvas::Handle open_canvas(const String &filename);
-extern Canvas::Handle open_canvas_as(const String &filename,const String &as);
+extern Canvas::Handle open_canvas(const String &filename,String &errors);
+extern Canvas::Handle open_canvas_as(const String &filename,const String &as,String &errors);
 
 //! Retrieves a Canvas from a string in XML format
 extern Canvas::Handle string_to_canvas(const String &data);
index 01f4b64..90d7cf8 100644 (file)
@@ -1174,7 +1174,8 @@ int main(int argc, char *argv[])
                          return ret;
 
                        // Open the composition
-                       job_list.front().root=open_canvas(job_list.front().filename);
+                       String errors;
+                       job_list.front().root=open_canvas(job_list.front().filename, errors);
 
                        if(!job_list.front().root)
                        {
@@ -1234,7 +1235,8 @@ int main(int argc, char *argv[])
                                extract_append(imageargs,composite_file);
                                if(!composite_file.empty())
                                {
-                                       Canvas::Handle composite(open_canvas(composite_file));
+                                       String errors;
+                                       Canvas::Handle composite(open_canvas(composite_file, errors));
                                        if(!composite)
                                                break;
                                        Canvas::reverse_iterator iter;
index 091d75a..a1cb858 100644 (file)
@@ -2339,8 +2339,9 @@ App::open_as(std::string filename,std::string as)
        try
        {
                OneMoment one_moment;
+               String errors;
 
-               etl::handle<synfig::Canvas> canvas(open_canvas_as(filename,as));
+               etl::handle<synfig::Canvas> canvas(open_canvas_as(filename,as,errors));
                if(canvas && get_instance(canvas))
                {
                        get_instance(canvas)->find_canvas_view(canvas)->present();
@@ -2350,7 +2351,7 @@ App::open_as(std::string filename,std::string as)
                else
                {
                        if(!canvas)
-                               throw (String)strprintf(_("Unable to open file \"%s\""),filename.c_str());
+                               throw (String)strprintf(_("Unable to open file \"%s\":\n\n"),filename.c_str()) + errors;
 
                        if (as.find(custom_filename_prefix.c_str()) != 0)
                                add_recent_file(as);
index 40d14df..c0423f0 100644 (file)
@@ -579,8 +579,8 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
        // If this is a SIF file, then we need to do things slightly differently
        if(ext=="sif" || ext=="sifz")try
        {
-
-               Canvas::Handle outside_canvas(synfig::open_canvas(filename));
+               String errors;
+               Canvas::Handle outside_canvas(synfig::open_canvas(filename, errors));
                if(!outside_canvas)
                        throw String(_("Unable to open this composition"));