// Backend for OnMRUFile and OnMRUProject bool AudacityApp::MRUOpen(wxString fileName) { // Most of the checks below are copied from AudacityProject::ShowFileDialog // - some rationalisation might be possible. AudacityProject *proj = GetActiveProject(); if(!fileName.IsEmpty()) { // verify that the file exists if(wxFile::Exists(fileName)) { wxFileName newFileName(fileName); gPrefs->Write(wxT("/DefaultOpenPath"), wxPathOnly(fileName)); // Make sure it isn't already open size_t numProjects = gAudacityProjects.Count(); for (size_t i = 0; i < numProjects; i++) { if (newFileName.SameAs(gAudacityProjects[i]->GetFileName())) { wxMessageBox(wxString::Format(_("%s is already open in another window."), newFileName.GetName().c_str()), _("Error opening project"), wxOK | wxCENTRE); continue; } } // DMM: If the project is dirty, that means it's been touched at // all, and it's not safe to open a new project directly in its // place. Only if the project is brand-new clean and the user // hasn't done any action at all is it safe for Open to take place // inside the current project. // // If you try to Open a new project inside the current window when // there are no tracks, but there's an Undo history, etc, then // bad things can happen, including data files moving to the new // project directory, etc. if (!proj || proj->GetDirty() || !proj->GetIsEmpty()) { proj = CreateNewAudacityProject(gParentWindow); } // This project is clean; it's never been touched. Therefore // all relevant member variables are in their initial state, // and it's okay to open a new project inside this window. proj->OpenFile(fileName); // Add file to "recent files" list. proj->GetRecentFiles()->AddFileToHistory(fileName); gPrefs->SetPath(wxT("/RecentFiles")); proj->GetRecentFiles()->Save(*gPrefs); gPrefs->SetPath(wxT("..")); } else { // File doesn't exist - remove file from history wxMessageBox(wxString::Format(_("%s does not exist and could not be opened.\n\nIt has been removed from the history list."), fileName.c_str())); return(false); } } return(true); }
void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) { long item = mChains->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == -1) { wxMessageBox(_("No chain selected")); return; } wxString name = mChains->GetItemText(item); gPrefs->Write(wxT("/Batch/ActiveChain"), name); gPrefs->Flush(); AudacityProject *project = GetActiveProject(); if (!project->GetIsEmpty()) { wxMessageBox(_("Please save and close the current project first.")); return; } wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd()); wxString prompt = _("Select file(s) for batch processing..."); FormatList l; wxString filter; wxString all; Importer::Get().GetSupportedImportFormats(&l); for (const auto &format : l) { const Format *f = &format; wxString newfilter = f->formatName + wxT("|"); for (size_t i = 0; i < f->formatExtensions.size(); i++) { if (!newfilter.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";"))) newfilter += wxT("*.") + f->formatExtensions[i] + wxT(";"); if (!all.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";"))) all += wxT("*.") + f->formatExtensions[i] + wxT(";"); } newfilter.RemoveLast(1); filter += newfilter; filter += wxT("|"); } all.RemoveLast(1); filter.RemoveLast(1); wxString mask = _("All files|*|All supported files|") + all + wxT("|") + filter; wxString type = gPrefs->Read(wxT("/DefaultOpenType"),mask.BeforeFirst(wxT('|'))); // Convert the type to the filter index int index = mask.First(type + wxT("|")); if (index == wxNOT_FOUND) { index = 0; } else { index = mask.Left(index).Freq(wxT('|')) / 2; if (index < 0) { index = 0; } } FileDialog dlog(this, prompt, path, wxT(""), mask, wxFD_OPEN | wxFD_MULTIPLE | wxRESIZE_BORDER); dlog.SetFilterIndex(index); if (dlog.ShowModal() != wxID_OK) { return; } wxArrayString files; dlog.GetPaths(files); files.Sort(); wxDialog * pD = safenew wxDialog(this, wxID_ANY, GetTitle()); pD->SetName(pD->GetTitle()); ShuttleGui S(pD, eIsCreating); S.StartVerticalLay(false); { S.StartStatic(_("Applying..."), 1); { wxImageList *imageList = new wxImageList(9, 16); imageList->Add(wxIcon(empty9x16_xpm)); imageList->Add(wxIcon(arrow_xpm)); S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_SINGLE_SEL); mList = S.Id(CommandsListID).AddListControlReportMode(); mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL); mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT); } S.EndStatic(); S.StartHorizontalLay(wxCENTER, false); { S.Id(wxID_CANCEL).AddButton(_("&Cancel")); } S.EndHorizontalLay(); } S.EndVerticalLay(); int i; for (i = 0; i < (int)files.GetCount(); i++ ) { mList->InsertItem(i, files[i], i == 0); } // Set the column size for the files list. mList->SetColumnWidth(0, wxLIST_AUTOSIZE); int width = mList->GetColumnWidth(0); wxSize sz = mList->GetClientSize(); if (width > sz.GetWidth() && width < 500) { sz.SetWidth(width); mList->SetInitialSize(sz); } pD->Layout(); pD->Fit(); pD->SetSizeHints(pD->GetSize()); pD->CenterOnScreen(); pD->Move(-1, 0); pD->Show(); Hide(); mBatchCommands.ReadChain(name); for (i = 0; i < (int)files.GetCount(); i++) { wxWindowDisabler wd(pD); if (i > 0) { //Clear the arrow in previous item. mList->SetItemImage(i - 1, 0, 0); } mList->SetItemImage(i, 1, 1); mList->EnsureVisible(i); project->Import(files[i]); project->OnSelectAll(); if (!mBatchCommands.ApplyChain()) { break; } if (!pD->IsShown() || mAbort) { break; } UndoManager *um = project->GetUndoManager(); um->ClearStates(); project->OnSelectAll(); project->OnRemoveTracks(); } project->OnRemoveTracks(); // Under Linux an EndModal() here crashes (Bug #1221). // But sending a close message instead is OK. #if !defined(__WXMAC__) wxCloseEvent Evt; Evt.SetId( wxID_OK ); Evt.SetEventObject( this); ProcessWindowEvent( Evt ); #else EndModal(wxID_OK); #endif // Raise myself again, and the parent window with me Show(); }
void BatchProcessDialog::OnApplyToFiles(wxCommandEvent &event) { long item = mChains->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == -1) { wxMessageBox(_("No chain selected")); return; } wxString name = mChains->GetItemText(item); gPrefs->Write(wxT("/Batch/ActiveChain"), name); AudacityProject *project = GetActiveProject(); if (!project->GetIsEmpty()) { wxMessageBox(_("Please save and close the current project first.")); return; } wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd()); wxString prompt = project->GetCleanSpeechMode() ? _("Select vocal file(s) for batch CleanSpeech Chain...") : _("Select file(s) for batch processing..."); wxString fileSelector = project->GetCleanSpeechMode() ? _("Vocal files (*.wav;*.mp3)|*.wav;*.mp3|WAV files (*.wav)|*.wav|MP3 files (*.mp3)|*.mp3") : _("All files (*.*)|*.*|WAV files (*.wav)|*.wav|AIFF files (*.aif)|*.aif|AU files (*.au)|*.au|MP3 files (*.mp3)|*.mp3|Ogg Vorbis files (*.ogg)|*.ogg|FLAC files (*.flac)|*.flac" ); FileDialog dlog(this, prompt, path, wxT(""), fileSelector, wxFD_OPEN | wxFD_MULTIPLE | wxRESIZE_BORDER); if (dlog.ShowModal() != wxID_OK) { return; } wxArrayString files; dlog.GetPaths(files); files.Sort(); wxDialog d(this, wxID_ANY, GetTitle()); ShuttleGui S(&d, eIsCreating); S.StartVerticalLay(false); { S.StartStatic(_("Applying..."), 1); { wxImageList *imageList = new wxImageList(9, 16); imageList->Add(wxIcon(empty_9x16_xpm)); imageList->Add(wxIcon(arrow_xpm)); S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_SINGLE_SEL); mList = S.AddListControlReportMode(); mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL); mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT); } S.EndStatic(); S.StartHorizontalLay(wxCENTER, false); { S.Id(wxID_CANCEL).AddButton(_("&Cancel")); } S.EndHorizontalLay(); } S.EndVerticalLay(); int i; for (i = 0; i < (int)files.GetCount(); i++ ) { mList->InsertItem(i, files[i], i == 0); } // Set the column size for the files list. mList->SetColumnWidth(0, wxLIST_AUTOSIZE); int width = mList->GetColumnWidth(0); wxSize sz = mList->GetClientSize(); if (width > sz.GetWidth() && width < 500) { sz.SetWidth(width); mList->SetInitialSize(sz); } d.Layout(); d.Fit(); d.SetSizeHints(d.GetSize()); d.CenterOnScreen(); d.Move(-1, 0); d.Show(); Hide(); mBatchCommands.ReadChain(name); for (i = 0; i < (int)files.GetCount(); i++) { wxWindowDisabler wd(&d); if (i > 0) { //Clear the arrow in previous item. mList->SetItemImage(i - 1, 0, 0); } mList->SetItemImage(i, 1, 1); mList->EnsureVisible(i); project->OnRemoveTracks(); project->Import(files[i]); project->OnSelectAll(); if (!mBatchCommands.ApplyChain()) { break; } if (!d.IsShown() || mAbort) { break; } UndoManager *um = project->GetUndoManager(); um->ClearStates(); } project->OnRemoveTracks(); }