Saves top-most window saveAs User clicked "Save As", default: false type What format to save data to, default: CsvApplication::SaveType CSV flaggedOnly Only export flagged rows */
| 632 | flaggedOnly Only export flagged rows |
| 633 | */ |
| 634 | bool CsvApplication::saveFile(bool saveAs, CsvApplication::SaveType type, bool flaggedOnly) { |
| 635 | Fl_Native_File_Chooser fnfc; |
| 636 | int winIndex = getTopWindow(); |
| 637 | std::string path; // path as stored in CsvWindow |
| 638 | std::string fn = ""; // path as chosen by user |
| 639 | bool repeatLoop = false; |
| 640 | std::ifstream fileExistsTest; |
| 641 | int choice; |
| 642 | std::string baseFilename, pathFilename; |
| 643 | bool ret = false; |
| 644 | std::string fileFilter = "CSV Files\t*.{txt,csv,tsv}"; |
| 645 | std::string defaultExtension = ".csv"; |
| 646 | |
| 647 | if( type == CsvApplication::SaveType::JSON ) { |
| 648 | fileFilter = "JSON Files\t*.{json}"; |
| 649 | defaultExtension = ".json"; |
| 650 | } |
| 651 | |
| 652 | path = windows[winIndex].getPath(); |
| 653 | |
| 654 | // Check if there are flagged rows when exporting flagged rows |
| 655 | if( flaggedOnly && windows[winIndex].table->countFlaggedRows() == 0 ) { |
| 656 | CsvApplication::myFlChoice("", "There are no flagged rows!", {"Okay"}); |
| 657 | return false; |
| 658 | } |
| 659 | |
| 660 | // Ask for path where file should be stored |
| 661 | if( path == "" || saveAs ) { |
| 662 | do { |
| 663 | repeatLoop = false; |
| 664 | fn = ""; |
| 665 | fnfc.title("Pick a file"); |
| 666 | fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE); |
| 667 | #ifdef DEBUG |
| 668 | std::cerr << " fnfc.filter" << std::endl; |
| 669 | #endif |
| 670 | fnfc.filter(fileFilter.c_str()); |
| 671 | fnfc.directory(workDir.c_str()); |
| 672 | |
| 673 | switch ( fnfc.show() ) { |
| 674 | case -1: |
| 675 | #ifdef DEBUG |
| 676 | printf("ERROR: %s\n", fnfc.errmsg()); |
| 677 | #endif |
| 678 | break; // ERROR |
| 679 | case 1: |
| 680 | #ifdef DEBUG |
| 681 | printf("CANCEL\n"); |
| 682 | #endif |
| 683 | break; // CANCEL |
| 684 | default: |
| 685 | #ifdef DEBUG |
| 686 | printf("PICKED: %s\n", fnfc.filename()); |
| 687 | #endif |
| 688 | fn = fnfc.filename(); |
| 689 | // calculate path and add extension if necessary |
| 690 | pathFilename = fn.substr(0, fn.find_last_of("/\\")+1); |
| 691 | baseFilename = fn.substr(fn.find_last_of("/\\") + 1); |
no test coverage detected