36 cfg( str, io_ldpath, "" ); |
36 cfg( str, io_ldpath, "" ); |
37 cfg( str, io_recentfiles, "" ); |
37 cfg( str, io_recentfiles, "" ); |
38 |
38 |
39 static bool g_loadingMainFile = false; |
39 static bool g_loadingMainFile = false; |
40 static const int g_MaxRecentFiles = 5; |
40 static const int g_MaxRecentFiles = 5; |
|
41 static bool g_aborted = false; |
41 |
42 |
42 // ============================================================================= |
43 // ============================================================================= |
43 namespace LDPaths |
44 namespace LDPaths |
44 { |
45 { |
45 static str pathError; |
46 static str pathError; |
205 // ============================================================================= |
206 // ============================================================================= |
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
207 // ============================================================================= |
208 // ============================================================================= |
208 void FileLoader::work() |
209 void FileLoader::work() |
209 { |
210 { |
210 m_progress = 0; |
211 setDone( false ); |
|
212 setProgress( 0 ); |
211 abortflag = false; |
213 abortflag = false; |
212 |
214 |
213 for( str line : *PROP_NAME( file )) { |
215 for( str line : *PROP_NAME( file )) { |
214 // Trim the trailing newline |
216 // Trim the trailing newline |
215 qchar c; |
217 qchar c; |
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
256 // ============================================================================= |
258 // ============================================================================= |
257 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { |
259 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { |
258 vector<str> lines; |
260 vector<str> lines; |
259 vector<LDObject*> objs; |
261 vector<LDObject*> objs; |
|
262 g_aborted = false; |
260 |
263 |
261 if( numWarnings ) |
264 if( numWarnings ) |
262 *numWarnings = 0; |
265 *numWarnings = 0; |
263 |
266 |
264 FileLoader* loader = new FileLoader; |
267 FileLoader* loader = new FileLoader; |
294 QObject::connect( loader, SIGNAL( progressUpdate( int )), dlg, SLOT( updateProgress( int ))); |
297 QObject::connect( loader, SIGNAL( progressUpdate( int )), dlg, SLOT( updateProgress( int ))); |
295 QObject::connect( loader, SIGNAL( workDone() ), dlg, SLOT( accept() )); |
298 QObject::connect( loader, SIGNAL( workDone() ), dlg, SLOT( accept() )); |
296 |
299 |
297 // Show the prompt. If the user hits cancel, tell the loader to abort. |
300 // Show the prompt. If the user hits cancel, tell the loader to abort. |
298 if( !dlg->exec() ) |
301 if( !dlg->exec() ) |
|
302 { |
299 loader->abortflag = true; |
303 loader->abortflag = true; |
|
304 g_aborted = true; |
|
305 } |
300 } else |
306 } else |
301 loader->work(); |
307 loader->work(); |
302 |
308 |
303 // If we wanted the success value, supply that now |
309 // If we wanted the success value, supply that now |
304 if( ok ) |
310 if( ok ) |
345 g_win->R()->setFile( load ); |
351 g_win->R()->setFile( load ); |
346 } |
352 } |
347 |
353 |
348 ulong numWarnings; |
354 ulong numWarnings; |
349 bool ok; |
355 bool ok; |
350 vector<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); |
356 vector<LDObject*> objs = loadFileContents( f, &numWarnings, &ok ); |
|
357 print( "ok: %1\n", ok ); |
351 |
358 |
352 if( !ok ) |
359 if( !ok ) |
353 { |
360 { |
354 g_curfile = oldLoad; |
361 if( g_loadingMainFile ) |
|
362 { |
|
363 g_curfile = oldLoad; |
|
364 g_win->R()->setFile( oldLoad ); |
|
365 } |
|
366 |
355 return null; |
367 return null; |
356 } |
368 } |
357 |
369 |
358 for (LDObject* obj : objs) |
370 for( LDObject* obj : objs ) |
359 load->addObject (obj); |
371 load->addObject( obj ); |
360 |
372 |
361 delete f; |
373 delete f; |
362 g_loadedFiles << load; |
374 g_loadedFiles << load; |
363 |
375 |
364 /* |
376 /* |
511 { |
523 { |
512 // Loading failed, thus drop down to a new file since we |
524 // Loading failed, thus drop down to a new file since we |
513 // closed everything prior. |
525 // closed everything prior. |
514 newFile (); |
526 newFile (); |
515 |
527 |
516 // Tell the user loading failed. |
528 if( !g_aborted ) |
517 setlocale( LC_ALL, "C" ); |
529 { |
518 critical( fmt( "Failed to open %1: %2", path, strerror( errno ))); |
530 // Tell the user loading failed. |
|
531 setlocale( LC_ALL, "C" ); |
|
532 critical( fmt( "Failed to open %1: %2", path, strerror( errno ))); |
|
533 } |
519 |
534 |
520 g_loadingMainFile = false; |
535 g_loadingMainFile = false; |
521 return; |
536 return; |
522 } |
537 } |
523 |
538 |