src/file.cpp

changeset 273
0a9141118630
parent 272
2074672a6554
child 274
d232fe4d88a6
equal deleted inserted replaced
272:2074672a6554 273:0a9141118630
29 #include "bbox.h" 29 #include "bbox.h"
30 #include "gui.h" 30 #include "gui.h"
31 #include "history.h" 31 #include "history.h"
32 #include "dialogs.h" 32 #include "dialogs.h"
33 #include "gldraw.h" 33 #include "gldraw.h"
34 #include "string.h"
34 35
35 cfg (str, io_ldpath, ""); 36 cfg (str, io_ldpath, "");
36 cfg (str, io_recentfiles, ""); 37 cfg (str, io_recentfiles, "");
37 38
38 static bool g_loadingMainFile = false; 39 static bool g_loadingMainFile = false;
435 436
436 // ============================================================================= 437 // =============================================================================
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 438 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
438 // ============================================================================= 439 // =============================================================================
439 void addRecentFile (str path) { 440 void addRecentFile (str path) {
440 long pos = io_recentfiles.value.first (path); 441 vector<str> rfiles = io_recentfiles.value.split ('@');
442
443 ulong idx = rfiles.find (path);
441 444
442 // If this file already is in the list, pop it out. 445 // If this file already is in the list, pop it out.
443 if (pos != -1) { 446 if (idx != -1u) {
444 if (~io_recentfiles.value == ~path) 447 if (rfiles.size () == 1)
445 return; // only recent file - do nothing 448 return; // only recent file - do nothing
446 449
447 // Pop it out. 450 // Pop it out.
448 str front = io_recentfiles.value.substr (0, pos); 451 rfiles.erase (idx);
449 str back;
450
451 if (pos + ~path + 1 < io_recentfiles.value.len ())
452 back = io_recentfiles.value.substr (pos + ~path + 1, -1);
453 else
454 back = "";
455
456 io_recentfiles.value = front + back;
457 } 452 }
458 453
459 // If there's too many recent files, drop one out. 454 // If there's too many recent files, drop one out.
460 while (io_recentfiles.value.count ('@') > 3) 455 while (rfiles.size () > (5 - 1))
461 io_recentfiles.value = io_recentfiles.value.substr (io_recentfiles.value.first ("@") + 1, -1); 456 rfiles.erase (0);
462 457
463 // Add the file 458 // Add the file
464 if (~io_recentfiles.value > 0) 459 rfiles.push_back (path);
465 io_recentfiles.value += "@"; 460
466 461 // Rebuild the config string
467 io_recentfiles += path; 462 io_recentfiles = str::join (rfiles, "@");
468 463
469 config::save (); 464 config::save ();
470 g_win->updateRecentFilesMenu (); 465 g_win->updateRecentFilesMenu ();
471 } 466 }
472 467

mercurial