Tue, 02 Jul 2013 23:40:27 +0300
rework aborting.. I'm still not sure I'm doing it right, though.
src/file.cpp | file | annotate | diff | comparison | revisions |
--- a/src/file.cpp Tue Jul 02 23:29:57 2013 +0300 +++ b/src/file.cpp Tue Jul 02 23:40:27 2013 +0300 @@ -38,6 +38,7 @@ static bool g_loadingMainFile = false; static const int g_MaxRecentFiles = 5; +static bool g_aborted = false; // ============================================================================= namespace LDPaths @@ -207,7 +208,8 @@ // ============================================================================= void FileLoader::work() { - m_progress = 0; + setDone( false ); + setProgress( 0 ); abortflag = false; for( str line : *PROP_NAME( file )) { @@ -257,6 +259,7 @@ vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { vector<str> lines; vector<LDObject*> objs; + g_aborted = false; if( numWarnings ) *numWarnings = 0; @@ -296,7 +299,10 @@ // Show the prompt. If the user hits cancel, tell the loader to abort. if( !dlg->exec() ) + { loader->abortflag = true; + g_aborted = true; + } } else loader->work(); @@ -347,16 +353,22 @@ ulong numWarnings; bool ok; - vector<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); + vector<LDObject*> objs = loadFileContents( f, &numWarnings, &ok ); + print( "ok: %1\n", ok ); if( !ok ) { - g_curfile = oldLoad; + if( g_loadingMainFile ) + { + g_curfile = oldLoad; + g_win->R()->setFile( oldLoad ); + } + return null; } - for (LDObject* obj : objs) - load->addObject (obj); + for( LDObject* obj : objs ) + load->addObject( obj ); delete f; g_loadedFiles << load; @@ -513,9 +525,12 @@ // closed everything prior. newFile (); - // Tell the user loading failed. - setlocale( LC_ALL, "C" ); - critical( fmt( "Failed to open %1: %2", path, strerror( errno ))); + if( !g_aborted ) + { + // Tell the user loading failed. + setlocale( LC_ALL, "C" ); + critical( fmt( "Failed to open %1: %2", path, strerror( errno ))); + } g_loadingMainFile = false; return;