From: dooglus Date: Sun, 26 Oct 2008 20:01:02 +0000 (+0000) Subject: When a .sif file fails to load, display the error messages in the studio GUI, not... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6c6dde907eadafe73e401781fd2ffb6c6223ec85;p=synfig.git When a .sif file fails to load, display the error messages in the studio GUI, not just in the terminal. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2132 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/canvas.cpp b/synfig-core/trunk/src/synfig/canvas.cpp index 67f06b9..5592aa0 100644 --- a/synfig-core/trunk/src/synfig/canvas.cpp +++ b/synfig-core/trunk/src/synfig/canvas.cpp @@ -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); diff --git a/synfig-core/trunk/src/synfig/loadcanvas.cpp b/synfig-core/trunk/src/synfig/loadcanvas.cpp index e4b2e15..79a3ec1 100644 --- a/synfig-core/trunk/src/synfig/loadcanvas.cpp +++ b/synfig-core/trunk/src/synfig/loadcanvas.cpp @@ -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< canvas(open_canvas_as(filename,as)); + etl::handle 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); diff --git a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp index 40d14df..c0423f0 100644 --- a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp +++ b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp @@ -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"));