From 5d48e96942ffa4a53a33e27f4c57bda8b63911e5 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 2 Aug 2017 12:41:29 -0400 Subject: [PATCH] Where FileSelector was used, default to Documents not cwd; save prefs --- src/AudacityLogger.cpp | 6 ++-- src/Benchmark.cpp | 5 +-- src/FFmpeg.cpp | 4 ++- src/FFmpeg.h | 1 - src/FileNames.cpp | 55 ++++++++++++++++++++++++++++++ src/FileNames.h | 34 ++++++++++++++++++ src/FreqWindow.cpp | 5 +-- src/Internat.cpp | 4 +-- src/LabelDialog.cpp | 16 ++++----- src/Menus.cpp | 49 ++++++++++---------------- src/Project.cpp | 3 +- src/Tags.cpp | 8 +++-- src/TimerRecordDialog.cpp | 4 ++- src/effects/Contrast.cpp | 5 +-- src/effects/VST/VSTEffect.cpp | 9 ++--- src/export/Export.h | 4 +-- src/export/ExportCL.cpp | 6 ++-- src/export/ExportFFmpegDialogs.cpp | 1 + src/export/ExportMP3.cpp | 6 ++-- src/prefs/KeyConfigPrefs.cpp | 44 +++++++----------------- 20 files changed, 168 insertions(+), 101 deletions(-) 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/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 565c477e4..e8642845a 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -31,6 +31,7 @@ used throughout Audacity into this one place. #include "Internat.h" #include "PlatformCompatibility.h" #include "wxFileNameWrapper.h" +#include "../lib-src/FileDialog/FileDialog.h" #if defined(__WXMAC__) || defined(__WXGTK__) #include @@ -336,3 +337,57 @@ wxFileNameWrapper FileNames::DefaultToDocumentsFolder 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 6fb9d91c8..d54409afc 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -69,6 +69,40 @@ public: 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..ebbf094e7 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"), @@ -6741,11 +6742,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 +6753,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 +6783,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 +6829,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 +6842,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 +8216,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 +8257,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 856cb08d5..8021a6ea8 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -4352,7 +4352,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.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/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);