* Asks user for a file and opens it. * askUser Should the user be asked about CSV format? * reopen Should the file be opened in the same window? Caution: Changes are overwritten. */
| 473 | * reopen Should the file be opened in the same window? Caution: Changes are overwritten. |
| 474 | */ |
| 475 | void CsvApplication::openFile(bool askUser, bool reopen) { |
| 476 | int winIndex; |
| 477 | std::string fn; |
| 478 | Fl_Native_File_Chooser fnfc; |
| 479 | |
| 480 | fnfc.title("Pick a file"); |
| 481 | fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE); |
| 482 | fnfc.filter("CSV Files\t*.{txt,csv,tsv}"); |
| 483 | fnfc.directory(workDir.c_str()); |
| 484 | |
| 485 | if( reopen ) { |
| 486 | winIndex = app.getTopWindow(); |
| 487 | if( winIndex >= 0 ) { |
| 488 | fn = windows[winIndex].getPath(); |
| 489 | windows[winIndex].loadFile(fn, true, true); |
| 490 | } |
| 491 | } else { |
| 492 | nfcIsOpen = true; |
| 493 | switch ( fnfc.show() ) { |
| 494 | case -1: |
| 495 | #ifdef DEBUG |
| 496 | printf("ERROR: %s\n", fnfc.errmsg()); |
| 497 | #endif |
| 498 | break; // ERROR |
| 499 | case 1: |
| 500 | #ifdef DEBUG |
| 501 | printf("CANCEL\n"); |
| 502 | #endif |
| 503 | break; // CANCEL |
| 504 | default: |
| 505 | #ifdef DEBUG |
| 506 | printf("PICKED: %s\n", fnfc.filename()); |
| 507 | #endif |
| 508 | fn = fnfc.filename(); |
| 509 | openFile(fn, askUser); |
| 510 | } |
| 511 | nfcIsOpen = false; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | |
| 516 | void CsvApplication::openFile(std::string path, bool askUser) { |
no test coverage detected