diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 802537476..bbffdb312 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -774,9 +774,7 @@ bool AudacityApp::MRUOpen(const wxString &fullPathStr) { // verify that the file exists if (wxFile::Exists(fullPathStr)) { - if (!gPrefs->Write(wxT("/DefaultOpenPath"), wxPathOnly(fullPathStr)) || - !gPrefs->Flush()) - return false; + FileNames::UpdateDefaultPath(FileNames::Operation::Open, fullPathStr); // Make sure it isn't already open. // Test here even though AudacityProject::OpenFile() also now checks, because diff --git a/src/AudacityLogger.cpp b/src/AudacityLogger.cpp index 6d41a108d..97cb1882f 100644 --- a/src/AudacityLogger.cpp +++ b/src/AudacityLogger.cpp @@ -16,9 +16,10 @@ Provides thread-safe logging based on the wxWidgets log facility. #include "Audacity.h" // This should always be included first #include "AudacityLogger.h" -#include "FileDialog.h" +#include "FileNames.h" #include "ShuttleGui.h" +#include #include #include #include @@ -292,7 +293,8 @@ void AudacityLogger::OnSave(wxCommandEvent & WXUNUSED(e)) { wxString fName = _("log.txt"); - fName = FileSelector(_("Save log to:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Save log to:"), wxEmptyString, fName, wxT("txt"), diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 25325e933..b509e014c 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -434,7 +434,7 @@ wxString BatchCommands::BuildCleanFileName(const wxString &fileName, const wxStr // double endTime = project->mTracks->GetEndTime(); // double startTime = 0.0; //OnSelectAll(); - pathName = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd()); + pathName = FileNames::FindDefaultPath(FileNames::Operation::Export); ::wxMessageBox(wxString::Format(_("Export recording to %s\n/%s/%s%s"), pathName.c_str(), cleanedString.c_str(), justName.c_str(), extension.c_str()), _("Export recording"), diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index b5138fa97..6bd87eacf 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -50,6 +50,7 @@ #include "AllThemeResources.h" #include "FileDialog.h" +#include "FileNames.h" #include "import/Import.h" #define ChainsListID 7001 @@ -237,7 +238,6 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) return; } - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd()); wxString prompt = _("Select file(s) for batch processing..."); FormatList l; @@ -279,6 +279,7 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) } } + auto path = FileNames::FindDefaultPath(FileNames::Operation::Open); FileDialog dlog(this, prompt, path, @@ -290,7 +291,7 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) if (dlog.ShowModal() != wxID_OK) { return; } - + wxArrayString files; dlog.GetPaths(files); diff --git a/src/Benchmark.cpp b/src/Benchmark.cpp index 33d3174d9..ade11ec8e 100644 --- a/src/Benchmark.cpp +++ b/src/Benchmark.cpp @@ -41,7 +41,7 @@ of the BlockFile system. #include "Sequence.h" #include "Prefs.h" -#include "FileDialog.h" +#include "FileNames.h" class BenchmarkDialog final : public wxDialogWrapper { @@ -248,7 +248,8 @@ void BenchmarkDialog::OnSave( wxCommandEvent & WXUNUSED(event)) { wxString fName = wxT("benchmark.txt"); - fName = FileSelector(wxT("Export Benchmark Data As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + wxT("Export Benchmark Data As:"), wxEmptyString, fName, wxT("txt"), diff --git a/src/FFmpeg.cpp b/src/FFmpeg.cpp index 48a9bc0bd..8fa2a8cb6 100644 --- a/src/FFmpeg.cpp +++ b/src/FFmpeg.cpp @@ -24,6 +24,7 @@ License: GPL v2. See License.txt. #include "widgets/HelpSystem.h" #include +#include #include "Experimental.h" @@ -518,7 +519,8 @@ public: "Where would I find the file '%s'?" instead if you want. */ question.Printf(_("Where is '%s'?"), mName.c_str()); - wxString path = FileSelector(question, + wxString path = FileNames::SelectFile(FileNames::Operation::None, + question, mLibPath.GetPath(), mLibPath.GetName(), wxT(""), diff --git a/src/FFmpeg.h b/src/FFmpeg.h index f65bf311b..678e94956 100644 --- a/src/FFmpeg.h +++ b/src/FFmpeg.h @@ -140,7 +140,6 @@ extern "C" { #include // for wxMessageBox #include #include "widgets/LinkingHtmlWindow.h" -#include "FileDialog.h" #include "ShuttleGui.h" #include "Prefs.h" #include diff --git a/src/FileNames.cpp b/src/FileNames.cpp index 60dfb9cc7..e8642845a 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -30,6 +30,8 @@ used throughout Audacity into this one place. #include "FileNames.h" #include "Internat.h" #include "PlatformCompatibility.h" +#include "wxFileNameWrapper.h" +#include "../lib-src/FileDialog/FileDialog.h" #if defined(__WXMAC__) || defined(__WXGTK__) #include @@ -315,3 +317,77 @@ wxString FileNames::PathFromAddr(void *addr) return name.GetFullPath(); } + +wxFileNameWrapper FileNames::DefaultToDocumentsFolder +(const wxString &preference) +{ + wxFileNameWrapper result; + result.AssignHomeDir(); + +#ifdef __WIN32__ + result.SetPath(gPrefs->Read( + preference, result.GetPath(wxPATH_GET_VOLUME) + "\\Documents\\Audacity")); + // The path might not exist. + // There is no error if the path could not be created. That's OK. + // The dialog that Audacity offers will allow the user to select a valid directory. + result.Mkdir(0755, wxPATH_MKDIR_FULL); +#else + result.SetPath(gPrefs->Read( preference, result.GetPath() + "/Documents")); +#endif + + return result; +} + +namespace { + wxString PreferenceKey(FileNames::Operation op) + { + wxString key; + switch (op) { + case FileNames::Operation::Open: + key = wxT("/DefaultOpenPath"); break; + case FileNames::Operation::Export: + key = wxT("/DefaultExportPath"); break; + case FileNames::Operation::None: + default: + break; + } + return key; + } +} + +wxString FileNames::FindDefaultPath(Operation op) +{ + auto key = PreferenceKey(op); + if (key.empty()) + return wxString{}; + else + return DefaultToDocumentsFolder(key).GetPath(); +} + +void FileNames::UpdateDefaultPath(Operation op, const wxString &path) +{ + if (path.empty()) + return; + auto key = PreferenceKey(op); + if (!key.empty()) { + gPrefs->Write(key, ::wxPathOnly(path)); + gPrefs->Flush(); + } +} + +wxString +FileNames::SelectFile(Operation op, + const wxString& message, + const wxString& default_path, + const wxString& default_filename, + const wxString& default_extension, + const wxString& wildcard, + int flags, + wxWindow *parent) +{ + return WithDefaultPath(op, default_path, [&](const wxString &path) { + return FileSelector( + message, path, default_filename, default_extension, + wildcard, flags, parent, wxDefaultCoord, wxDefaultCoord); + }); +} diff --git a/src/FileNames.h b/src/FileNames.h index bff19e1e8..d54409afc 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -15,6 +15,7 @@ #include "Audacity.h" class wxFileName; +class wxFileNameWrapper; class wxArrayString; // Uh, this is really a namespace rather than a class, @@ -65,6 +66,43 @@ public: // Obtain name of loaded module that contains address static wxString PathFromAddr(void *addr); + static wxFileNameWrapper DefaultToDocumentsFolder + (const wxString &preference); + + // If not None, determines a preference key (for the default path string) to + // be read and updated + enum class Operation { + None, + Open, + Export + }; + + static wxString FindDefaultPath(Operation op); + static void UpdateDefaultPath(Operation op, const wxString &path); + + // F is a function taking a wxString, returning wxString + template + static wxString WithDefaultPath + (Operation op, const wxString &defaultPath, F function) + { + auto path = defaultPath; + if (path.empty()) + path = FileNames::FindDefaultPath(op); + auto result = function(path); + FileNames::UpdateDefaultPath(op, result); + return result; + } + + static wxString + SelectFile(Operation op, // op matters only when default_path is empty + const wxString& message, + const wxString& default_path, + const wxString& default_filename, + const wxString& default_extension, + const wxString& wildcard, + int flags, + wxWindow *parent); + private: // Private constructors: No one is ever going to instantiate it. // diff --git a/src/FreqWindow.cpp b/src/FreqWindow.cpp index 9110edac1..081d0807f 100644 --- a/src/FreqWindow.cpp +++ b/src/FreqWindow.cpp @@ -76,7 +76,7 @@ and in the spectrogram spectral selection. #include "Theme.h" #include "AllThemeResources.h" -#include "FileDialog.h" +#include "FileNames.h" #include "WaveTrack.h" @@ -1027,7 +1027,8 @@ void FreqWindow::OnExport(wxCommandEvent & WXUNUSED(event)) { wxString fName = _("spectrum.txt"); - fName = FileSelector(_("Export Spectral Data As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Spectral Data As:"), wxEmptyString, fName, wxT("txt"), wxT("*.txt"), wxFD_SAVE | wxRESIZE_BORDER, this); if (fName == wxT("")) diff --git a/src/Internat.cpp b/src/Internat.cpp index 880382e22..51b7166bd 100644 --- a/src/Internat.cpp +++ b/src/Internat.cpp @@ -29,7 +29,6 @@ and on Mac OS X for the filesystem. #include // for pow() #include "Internat.h" -#include "FileDialog.h" #include "Experimental.h" // in order for the static member variables to exist, they must appear here @@ -246,7 +245,8 @@ char *Internat::VerifyFilename(const wxString &s, bool input) wxMessageBox(_("The specified filename could not be converted due to Unicode character use.")); ext = ff.GetExt(); - name = FileSelector(_("Specify New Filename:"), + name = FileNames::SelectFile(FileNames::Operation::None, + _("Specify New Filename:"), wxEmptyString, name, ext, diff --git a/src/LabelDialog.cpp b/src/LabelDialog.cpp index 1c5852e1f..137f74d99 100644 --- a/src/LabelDialog.cpp +++ b/src/LabelDialog.cpp @@ -38,7 +38,7 @@ #include "ViewInfo.h" #include "widgets/NumericTextCtrl.h" -#include "FileDialog.h" +#include "FileNames.h" #include enum Column @@ -585,12 +585,11 @@ void LabelDialog::OnRemove(wxCommandEvent & WXUNUSED(event)) void LabelDialog::OnImport(wxCommandEvent & WXUNUSED(event)) { - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd()); - // Ask user for a filename wxString fileName = - FileSelector(_("Select a text file containing labels"), - path, // Path + FileNames::SelectFile(FileNames::Operation::Open, + _("Select a text file containing labels"), + wxEmptyString, // Path wxT(""), // Name wxT(".txt"), // Extension _("Text files (*.txt)|*.txt|All files|*"), @@ -599,10 +598,6 @@ void LabelDialog::OnImport(wxCommandEvent & WXUNUSED(event)) // They gave us one... if (fileName != wxT("")) { - path =::wxPathOnly(fileName); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - wxTextFile f; // Get at the data @@ -640,7 +635,8 @@ void LabelDialog::OnExport(wxCommandEvent & WXUNUSED(event)) // Extract the actual name. wxString fName = mTrackNames[mTrackNames.GetCount() - 1].AfterFirst(wxT('-')).Mid(1); - fName = FileSelector(_("Export Labels As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Labels As:"), wxEmptyString, fName.c_str(), wxT("txt"), diff --git a/src/Menus.cpp b/src/Menus.cpp index f92d6bc68..a1fa03c84 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -117,7 +117,6 @@ simplifies construction of menu items. #include "SoundActivatedRecord.h" #include "LabelDialog.h" -#include "FileDialog.h" #include "SplashDialog.h" #include "widgets/HelpSystem.h" #include "DeviceManager.h" @@ -4424,7 +4423,8 @@ void AudacityProject::OnExportLabels() return; } - fName = FileSelector(_("Export Labels As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Labels As:"), wxEmptyString, fName, wxT("txt"), @@ -4505,7 +4505,8 @@ void AudacityProject::OnExportMIDI(){ wxString fName = wxT(""); - fName = FileSelector(_("Export MIDI As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Export MIDI As:"), wxEmptyString, fName, wxT(".mid|.gro"), @@ -6730,8 +6731,7 @@ void AudacityProject::OnImport() for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) { wxString fileName = selectedFiles[ff]; - wxString path = ::wxPathOnly(fileName); - gPrefs->Write(wxT("/DefaultOpenPath"), path); + FileNames::UpdateDefaultPath(FileNames::Operation::Open, fileName); Import(fileName); } @@ -6741,11 +6741,10 @@ void AudacityProject::OnImport() void AudacityProject::OnImportLabels() { - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd()); - wxString fileName = - FileSelector(_("Select a text file containing labels"), - path, // Path + FileNames::SelectFile(FileNames::Operation::Open, + _("Select a text file containing labels"), + wxEmptyString, // Path wxT(""), // Name wxT(".txt"), // Extension _("Text files (*.txt)|*.txt|All files|*"), @@ -6753,10 +6752,6 @@ void AudacityProject::OnImportLabels() this); // Parent if (fileName != wxT("")) { - path =::wxPathOnly(fileName); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - wxTextFile f; f.Open(fileName); @@ -6787,23 +6782,17 @@ void AudacityProject::OnImportLabels() #ifdef USE_MIDI void AudacityProject::OnImportMIDI() { - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd()); - - wxString fileName = FileSelector(_("Select a MIDI file"), - path, // Path + wxString fileName = FileNames::SelectFile(FileNames::Operation::Open, + _("Select a MIDI file"), + wxEmptyString, // Path wxT(""), // Name wxT(""), // Extension _("MIDI and Allegro files (*.mid;*.midi;*.gro)|*.mid;*.midi;*.gro|MIDI files (*.mid;*.midi)|*.mid;*.midi|Allegro files (*.gro)|*.gro|All files|*"), wxRESIZE_BORDER, // Flags this); // Parent - if (fileName != wxT("")) { - path =::wxPathOnly(fileName); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - + if (fileName != wxT("")) AudacityProject::DoImportMIDI(this, fileName); - } } AudacityProject *AudacityProject::DoImportMIDI( @@ -6839,11 +6828,10 @@ AudacityProject *AudacityProject::DoImportMIDI( void AudacityProject::OnImportRaw() { - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd()); - wxString fileName = - FileSelector(_("Select any uncompressed audio file"), - path, // Path + FileNames::SelectFile(FileNames::Operation::Open, + _("Select any uncompressed audio file"), + wxEmptyString, // Path wxT(""), // Name wxT(""), // Extension _("All files|*"), @@ -6853,10 +6841,6 @@ void AudacityProject::OnImportRaw() if (fileName == wxT("")) return; - path =::wxPathOnly(fileName); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - TrackHolders newTracks; ::ImportRaw(this, fileName, GetTrackFactory(), newTracks); @@ -8231,7 +8215,8 @@ void AudacityProject::OnAudioDeviceInfo() if (dlg.ShowModal() == wxID_OK) { - wxString fName = FileSelector(_("Save Device Info"), + wxString fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Save Device Info"), wxEmptyString, wxT("deviceinfo.txt"), wxT("txt"), @@ -8271,7 +8256,8 @@ void AudacityProject::OnMidiDeviceInfo() if (dlg.ShowModal() == wxID_OK) { - wxString fName = FileSelector(_("Save MIDI Device Info"), + wxString fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Save MIDI Device Info"), wxEmptyString, wxT("midideviceinfo.txt"), wxT("txt"), diff --git a/src/Project.cpp b/src/Project.cpp index 241da0d43..144079c8f 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2830,7 +2830,7 @@ wxArrayString AudacityProject::ShowOpenDialog(const wxString &extraformat, const // we built up earlier into the mask // Retrieve saved path and type - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd()); + auto path = FileNames::FindDefaultPath(FileNames::Operation::Open); wxString type = gPrefs->Read(wxT("/DefaultOpenType"),mask.BeforeFirst(wxT('|'))); // Convert the type to the filter index @@ -2927,8 +2927,7 @@ void AudacityProject::OpenFiles(AudacityProject *proj) if (AudacityProject::IsAlreadyOpen(fileName)) continue; // Skip ones that are already open. - gPrefs->Write(wxT("/DefaultOpenPath"), wxPathOnly(fileName)); - gPrefs->Flush(); + FileNames::UpdateDefaultPath(FileNames::Operation::Open, fileName); // 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 @@ -4317,16 +4316,7 @@ bool AudacityProject::SaveAs(bool bWantSaveCompressed /*= false*/) // Bug 1304: Set a default file path if none was given. For Save/SaveAs if( filename.GetFullPath().IsEmpty() ){ bHasPath = false; - filename.AssignHomeDir(); -#ifdef __WIN32__ - filename.SetPath(gPrefs->Read( wxT("/SaveAs/Path"), filename.GetPath() + "\\Documents\\Audacity")); - // The path might not exist. - // There is no error if the path could not be created. That's OK. - // The dialog that Audacity offers will allow the user to select a valid directory. - filename.Mkdir(0755, wxPATH_MKDIR_FULL); -#else - filename.SetPath(gPrefs->Read( wxT("/SaveAs/Path"), filename.GetPath() + "/Documents")); -#endif + filename = FileNames::DefaultToDocumentsFolder(wxT("/SaveAs/Path")); } wxString sDialogTitle; @@ -4361,7 +4351,8 @@ For an audio file that will open in other apps, use 'Export'.\n"), // for overwrite ourselves later, and we disallow it. // We disallow overwrite because we would have to DELETE the many // smaller files too, or prompt to move them. - wxString fName = FileSelector(sDialogTitle, + wxString fName = FileNames::SelectFile(FileNames::Operation::Export, + sDialogTitle, filename.GetPath(), filename.GetFullName(), wxT("aup"), diff --git a/src/Tags.cpp b/src/Tags.cpp index 11778d16d..d98e1b92a 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -41,7 +41,6 @@ #include #endif -#include "FileDialog.h" #include "FileNames.h" #include "Internat.h" #include "Prefs.h" @@ -51,6 +50,7 @@ #include #include +#include #include #include #include @@ -1152,7 +1152,8 @@ void TagsEditor::OnLoad(wxCommandEvent & WXUNUSED(event)) wxString fn; // Ask the user for the real name - fn = FileSelector(_("Load Metadata As:"), + fn = FileNames::SelectFile(FileNames::Operation::None, + _("Load Metadata As:"), FileNames::DataDir(), wxT("Tags.xml"), wxT("xml"), @@ -1206,7 +1207,8 @@ void TagsEditor::OnSave(wxCommandEvent & WXUNUSED(event)) TransferDataFromWindow(); // Ask the user for the real name - fn = FileSelector(_("Save Metadata As:"), + fn = FileNames::SelectFile(FileNames::Operation::None, + _("Save Metadata As:"), FileNames::DataDir(), wxT("Tags.xml"), wxT("xml"), diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index 275fe9269..3dab6035c 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -291,7 +292,8 @@ void TimerRecordDialog::OnTimeText_Duration(wxCommandEvent& WXUNUSED(event)) // New events for timer recording automation void TimerRecordDialog::OnAutoSavePathButton_Click(wxCommandEvent& WXUNUSED(event)) { - wxString fName = FileSelector(_("Save Timer Recording As"), + wxString fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Save Timer Recording As"), m_fnAutoSaveFile.GetPath(), m_fnAutoSaveFile.GetFullName(), wxT("aup"), diff --git a/src/effects/Contrast.cpp b/src/effects/Contrast.cpp index 9bf8242a3..251123ad9 100644 --- a/src/effects/Contrast.cpp +++ b/src/effects/Contrast.cpp @@ -20,7 +20,6 @@ #include "../widgets/LinkingHtmlWindow.h" #include "../widgets/HelpSystem.h" #include "../widgets/NumericTextCtrl.h" -#include "../lib-src/FileDialog/FileDialog.h" #include #include @@ -30,6 +29,7 @@ #define finite(x) _finite(x) #endif +#include #include #include @@ -489,7 +489,8 @@ void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event)) AudacityProject * project = GetActiveProject(); wxString fName = wxT("contrast.txt"); - fName = FileSelector(_("Export Contrast Result As:"), + fName = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Contrast Result As:"), wxEmptyString, fName, wxT("txt"), diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index af48a3cc2..18337af24 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -78,7 +78,6 @@ // TODO: Unfortunately we have some dependencies on Audacity provided // dialogs, widgets and other stuff. This will need to be cleaned up. -#include "FileDialog.h" #include "../../FileNames.h" #include "../../Internat.h" #include "../../PlatformCompatibility.h" @@ -1798,8 +1797,9 @@ void VSTEffect::ExportPresets() // Ask the user for the real name // // Passing a valid parent will cause some effects dialogs to malfunction - // upon returning from the FileSelector(). - path = FileSelector(_("Save VST Preset As:"), + // upon returning from the FileNames::SelectFile(). + path = FileNames::SelectFile(FileNames::Operation::None, + _("Save VST Preset As:"), FileNames::DataDir(), wxEmptyString, wxT("xml"), @@ -1850,7 +1850,8 @@ void VSTEffect::ImportPresets() wxString path; // Ask the user for the real name - path = FileSelector(_("Load VST Preset:"), + path = FileNames::SelectFile(FileNames::Operation::None, + _("Load VST Preset:"), FileNames::DataDir(), wxEmptyString, wxT("xml"), diff --git a/src/export/Export.cpp b/src/export/Export.cpp index 9d06fb103..c0b475450 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -69,6 +69,7 @@ #include "../widgets/Warning.h" #include "../AColor.h" #include "../Dependencies.h" +#include "../FileNames.h" //---------------------------------------------------------------------------- // ExportPlugin @@ -524,18 +525,7 @@ bool Exporter::GetFilename() wxString defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower(); //Bug 1304: Set a default path if none was given. For Export. -#ifdef __WIN32__ - wxFileName tmpFile; - tmpFile.AssignHomeDir(); - wxString tmpDirLoc = tmpFile.GetPath(wxPATH_GET_VOLUME); - mFilename.SetPath(gPrefs->Read(wxT("/Export/Path"), tmpDirLoc + "\\Documents\\Audacity")); - // The path might not exist. - // There is no error if the path could not be created. That's OK. - // The dialog that Audacity offers will allow the user to select a valid directory. - mFilename.Mkdir(0755, wxPATH_MKDIR_FULL); -#else - mFilename.SetPath(gPrefs->Read(wxT("/Export/Path"), wxT("~/Documents"))); -#endif + mFilename = FileNames::DefaultToDocumentsFolder(wxT("/Export/Path")); mFilename.SetName(mProject->GetName()); if (mFilename.GetName().empty()) mFilename.SetName(_("untitled")); diff --git a/src/export/Export.h b/src/export/Export.h index c3ea5796f..d9fe8090c 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -21,8 +21,8 @@ #include "../SampleFormat.h" #include "../widgets/wxPanelWrapper.h" -#include "FileDialog.h" - +class FileDialog; +class wxFileCtrlEvent; class wxMemoryDC; class wxStaticText; class AudacityProject; diff --git a/src/export/ExportCL.cpp b/src/export/ExportCL.cpp index e1c41230c..f05dfd4bb 100644 --- a/src/export/ExportCL.cpp +++ b/src/export/ExportCL.cpp @@ -18,12 +18,13 @@ #include #include #include +#include #include #include #include #include #include -#include +#include "FileNames.h" #include "Export.h" #include "../Mix.h" @@ -169,7 +170,8 @@ void ExportCLOptions::OnBrowse(wxCommandEvent& WXUNUSED(event)) ext = wxT(".exe"); #endif - path = FileSelector(_("Find path to command"), + path = FileNames::SelectFile(FileNames::Operation::Open, + _("Find path to command"), wxEmptyString, wxEmptyString, ext, diff --git a/src/export/ExportFFmpegDialogs.cpp b/src/export/ExportFFmpegDialogs.cpp index 8401a3f56..b7a369c20 100644 --- a/src/export/ExportFFmpegDialogs.cpp +++ b/src/export/ExportFFmpegDialogs.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include "../FileFormats.h" #include "../Internat.h" diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index 615035879..be25a5051 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -91,8 +92,6 @@ #include "../Track.h" #include "../widgets/LinkingHtmlWindow.h" -#include "FileDialog.h" - #include "Export.h" #include @@ -661,7 +660,8 @@ public: * "Where would I find the file %s" instead if you want. */ question.Printf(_("Where is %s?"), mName.c_str()); - wxString path = FileSelector(question, + wxString path = FileNames::SelectFile(FileNames::Operation::None, + question, mLibPath.GetPath(), mLibPath.GetName(), wxT(""), diff --git a/src/export/ExportMultiple.cpp b/src/export/ExportMultiple.cpp index 0005b4d64..3be991adf 100644 --- a/src/export/ExportMultiple.cpp +++ b/src/export/ExportMultiple.cpp @@ -241,13 +241,7 @@ void ExportMultiple::PopulateOrExchange(ShuttleGui& S) // Bug 1304: Set the default file path. It's used if none stored in config. - wxFileName filename("foo"); - filename.AssignHomeDir(); -#ifdef __WIN32__ - filename.SetPath(filename.GetPath() + "\\Documents\\Audacity"); -#else - filename.SetPath(filename.GetPath() + "/Documents"); -#endif + auto filename = FileNames::DefaultToDocumentsFolder(wxT("/Export/Path")); wxString DefaultPath = filename.GetPath(); if (mPluginIndex == -1) @@ -268,7 +262,7 @@ void ExportMultiple::PopulateOrExchange(ShuttleGui& S) mDir = S.Id(DirID) .TieTextBox(_("Folder:"), wxT("/Export/MultiplePath"), - gPrefs->Read(wxT("/Export/Path"), DefaultPath ), + DefaultPath, 64); S.Id(ChooseID).AddButton(_("Choose...")); S.Id(CreateID).AddButton(_("Create")); diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index f89129342..035e91bba 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -39,7 +39,7 @@ KeyConfigPrefs and MousePrefs use. #include "../Internat.h" #include "../ShuttleGui.h" -#include "FileDialog.h" +#include "FileNames.h" #if defined(EXPERIMENTAL_KEY_VIEW) @@ -333,11 +333,10 @@ void KeyConfigPrefs::RefreshBindings(bool bSort) void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) { wxString file = wxT("Audacity-keys.xml"); - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), - ::wxGetCwd()); - file = FileSelector(_("Select an XML file containing Audacity keyboard shortcuts..."), - path, + file = FileNames::SelectFile(FileNames::Operation::Open, + _("Select an XML file containing Audacity keyboard shortcuts..."), + wxEmptyString, file, wxT(""), _("XML files (*.xml)|*.xml|All files|*"), @@ -348,10 +347,6 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) return; } - path = wxPathOnly(file); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - XMLFileReader reader; if (!reader.Parse(mManager, file)) { wxMessageBox(reader.GetErrorStr(), @@ -365,11 +360,10 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) { wxString file = wxT("Audacity-keys.xml"); - wxString path = gPrefs->Read(wxT("/DefaultExportPath"), - ::wxGetCwd()); - file = FileSelector(_("Export Keyboard Shortcuts As:"), - path, + file = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Keyboard Shortcuts As:"), + wxEmptyString, file, wxT("xml"), _("XML files (*.xml)|*.xml|All files|*"), @@ -380,10 +374,6 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) return; } - path = wxPathOnly(file); - gPrefs->Write(wxT("/DefaultExportPath"), path); - gPrefs->Flush(); - GuardedCall< void >( [&] { XMLFileWriter prefFile{ file, _("Error Exporting Keyboard Shortcuts") }; mManager->WriteXML(prefFile); @@ -993,11 +983,10 @@ void KeyConfigPrefs::RepopulateBindingsList() void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) { wxString file = wxT("Audacity-keys.xml"); - wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), - ::wxGetCwd()); - file = FileSelector(_("Select an XML file containing Audacity keyboard shortcuts..."), - path, + file = FileNames::SelectFile(FileNames::Operation::Open, + _("Select an XML file containing Audacity keyboard shortcuts..."), + wxEmptyString, file, wxT(""), _("XML files (*.xml)|*.xml|All files|*"), @@ -1008,10 +997,6 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) return; } - path = wxPathOnly(file); - gPrefs->Write(wxT("/DefaultOpenPath"), path); - gPrefs->Flush(); - XMLFileReader reader; if (!reader.Parse(mManager, file)) { wxMessageBox(reader.GetErrorStr(), @@ -1025,10 +1010,9 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) { wxString file = wxT("Audacity-keys.xml"); - wxString path = gPrefs->Read(wxT("/DefaultExportPath"), - ::wxGetCwd()); - file = FileSelector(_("Export Keyboard Shortcuts As:"), + file = FileNames::SelectFile(FileNames::Operation::Export, + _("Export Keyboard Shortcuts As:"), path, file, wxT("xml"), @@ -1040,10 +1024,6 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) return; } - path = wxPathOnly(file); - gPrefs->Write(wxT("/DefaultExportPath"), path); - gPrefs->Flush(); - GuardedCall< void >( [&] { XMLFileWriter prefFile{ file, _("Error Exporting Keyboard Shortcuts") }; mManager->WriteXML(prefFile);