When we try to open a file that doesn't exist, display an error in studio.
[synfig.git] / synfig-studio / trunk / src / gtkmm / app.cpp
index 75af506..18cab60 100644 (file)
@@ -8,6 +8,7 @@
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **     Copyright (c) 2007, 2008 Chris Moore
 **     Copyright (c) 2008 Gerald Young
+**  Copyright (c) 2008 Carlos López
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -274,6 +275,7 @@ bool studio::App::use_colorspace_gamma=true;
 bool studio::App::single_threaded=false;
 #endif
 bool studio::App::restrict_radius_ducks=false;
+bool studio::App::resize_imported_images=false;
 String studio::App::custom_filename_prefix(DEFAULT_FILENAME_PREFIX);
 int studio::App::preferred_x_size=480;
 int studio::App::preferred_y_size=270;
@@ -510,6 +512,11 @@ public:
                        value=strprintf("%i",(int)App::restrict_radius_ducks);
                        return true;
                }
+               if(key=="resize_imported_images")
+               {
+                       value=strprintf("%i",(int)App::resize_imported_images);
+                       return true;
+               }
                if(key=="browser_command")
                {
                        value=App::browser_command;
@@ -599,6 +606,12 @@ public:
                        App::restrict_radius_ducks=i;
                        return true;
                }
+               if(key=="resize_imported_images")
+               {
+                       int i(atoi(value.c_str()));
+                       App::resize_imported_images=i;
+                       return true;
+               }
                if(key=="browser_command")
                {
                        App::browser_command=value;
@@ -642,6 +655,7 @@ public:
 #endif
                ret.push_back("auto_recover_backup_interval");
                ret.push_back("restrict_radius_ducks");
+               ret.push_back("resize_imported_images");
                ret.push_back("browser_command");
                ret.push_back("custom_filename_prefix");
                ret.push_back("preferred_x_size");
@@ -1142,6 +1156,11 @@ App::App(int *argc, char ***argv):
 
        // Initialize the Synfig library
        try { synfigapp_main=etl::smart_ptr<synfigapp::Main>(new synfigapp::Main(etl::dirname((*argv)[0]),&synfig_init_cb)); }
+       catch(std::runtime_error x)
+       {
+               get_ui_interface()->error(strprintf("%s\n\n%s", _("Failed to initialize synfig!"), x.what()));
+               throw;
+       }
        catch(...)
        {
                get_ui_interface()->error(_("Failed to initialize synfig!"));
@@ -1431,7 +1450,8 @@ App::set_recent_file_window_size(etl::handle<Instance> instance)
                // find the canvas
                synfig::Canvas::Handle canvas;
                try {
-                       canvas = instance->get_canvas()->find_canvas(String(canvas_window_size, current, separator-current));
+                       String warnings;
+                       canvas = instance->get_canvas()->find_canvas(String(canvas_window_size, current, separator-current), warnings);
                }
                catch(Exception::IDNotFound) {
                        // can't find the canvas; skip to the next canvas or return
@@ -1726,6 +1746,7 @@ App::reset_initial_window_configuration()
        synfigapp::Main::settings().set_value("pref.single_threaded","0");
 #endif
        synfigapp::Main::settings().set_value("pref.restrict_radius_ducks","0");
+       synfigapp::Main::settings().set_value("pref.resize_imported_images","0");
        synfigapp::Main::settings().set_value("pref.custom_filename_prefix",DEFAULT_FILENAME_PREFIX);
        synfigapp::Main::settings().set_value("pref.preferred_x_size","480");
        synfigapp::Main::settings().set_value("pref.preferred_y_size","270");
@@ -2338,8 +2359,9 @@ App::open_as(std::string filename,std::string as)
        try
        {
                OneMoment one_moment;
+               String errors, warnings;
 
-               etl::handle<synfig::Canvas> canvas(open_canvas_as(filename,as));
+               etl::handle<synfig::Canvas> canvas(open_canvas_as(filename,as,errors,warnings));
                if(canvas && get_instance(canvas))
                {
                        get_instance(canvas)->find_canvas_view(canvas)->present();
@@ -2349,8 +2371,11 @@ 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 load \"%s\":\n\n"),filename.c_str()) + errors;
 
+                       if (warnings != "")
+                               dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
+                       
                        if (as.find(custom_filename_prefix.c_str()) != 0)
                                add_recent_file(as);
 
@@ -2372,6 +2397,11 @@ App::open_as(std::string filename,std::string as)
                dialog_error_blocking(_("Error"), x);
                return false;
        }
+       catch(runtime_error x)
+       {
+               dialog_error_blocking(_("Error"), x.what());
+               return false;
+       }
        catch(...)
        {
                dialog_error_blocking(_("Error"), _("Uncaught error on file open (BUG)"));