| 667 | } |
| 668 | |
| 669 | void LabelDialog::OnExport(wxCommandEvent & WXUNUSED(event)) |
| 670 | { |
| 671 | int cnt = mData.size(); |
| 672 | |
| 673 | // Silly user (could just disable the button, but that's a hassle ;-)) |
| 674 | if (cnt == 0) { |
| 675 | AudacityMessageBox( XO("No labels to export.") ); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | // Extract the actual name. |
| 680 | wxString fName = mTrackNames[mTrackNames.size() - 1].AfterFirst(wxT('-')).Mid(1); |
| 681 | |
| 682 | fName = SelectFile(FileNames::Operation::Export, |
| 683 | XO("Export Labels As:"), |
| 684 | wxEmptyString, |
| 685 | fName, |
| 686 | wxT("txt"), |
| 687 | { FileNames::TextFiles, LabelTrack::SubripFiles, LabelTrack::WebVTTFiles }, |
| 688 | wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER, |
| 689 | this); |
| 690 | |
| 691 | if (fName.empty()) |
| 692 | return; |
| 693 | |
| 694 | LabelFormat format = LabelTrack::FormatForFileName(fName); |
| 695 | |
| 696 | // Move existing files out of the way. Otherwise wxTextFile will |
| 697 | // append to (rather than replace) the current file. |
| 698 | |
| 699 | if (wxFileExists(fName)) { |
| 700 | #ifdef __WXGTK__ |
| 701 | wxString safetyFileName = fName + wxT("~"); |
| 702 | #else |
| 703 | wxString safetyFileName = fName + wxT(".bak"); |
| 704 | #endif |
| 705 | |
| 706 | if (wxFileExists(safetyFileName)) |
| 707 | wxRemoveFile(safetyFileName); |
| 708 | |
| 709 | wxRename(fName, safetyFileName); |
| 710 | } |
| 711 | |
| 712 | wxTextFile f(fName); |
| 713 | #ifdef __WXMAC__ |
| 714 | wxFile{}.Create(fName); |
| 715 | #else |
| 716 | f.Create(); |
| 717 | #endif |
| 718 | f.Open(); |
| 719 | if (!f.IsOpened()) { |
| 720 | AudacityMessageBox( |
| 721 | XO("Couldn't write to file: %s").Format( fName ) ); |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | // Transfer our collection to a temporary label track |
| 726 | auto lt = std::make_shared<LabelTrack>(); |
nothing calls this directly
no test coverage detected