diff --git a/plug-ins/eq-xml-to-txt-converter.ny b/plug-ins/eq-xml-to-txt-converter.ny index 926af144d..1e9581aa1 100644 --- a/plug-ins/eq-xml-to-txt-converter.ny +++ b/plug-ins/eq-xml-to-txt-converter.ny @@ -20,7 +20,8 @@ $copyright (_ "Released under terms of the GNU General Public License version 2" $control fxname (_ "Select target EQ effect") choice (("Graphic" (_ "Graphic EQ")) ("FilterCurve" (_ "Filter Curve EQ"))) 0 -$control infile (_ "Equalization XML file") file "" "*default*/EQCurves.xml" "XML file|*.xml;*.XML|All files|*.*;*" "open,exists" +$control infile (_ "Equalization XML file") file "" "*default*/EQCurves.xml" (((_ "XML file") (xml XML)) + ((_ "All files") (""))) "open,exists" $control overwrite (_ "If output text file exists") choice (("Append" (_ "Append number")) ("Overwrite" (_ "Overwrite")) diff --git a/plug-ins/nyquist-plug-in-installer.ny b/plug-ins/nyquist-plug-in-installer.ny index d303bf887..8aca53c92 100644 --- a/plug-ins/nyquist-plug-in-installer.ny +++ b/plug-ins/nyquist-plug-in-installer.ny @@ -17,7 +17,12 @@ $copyright (_ "Released under terms of the GNU General Public License version 2" ;i18n-hint: "Browse..." is text on a button that launches a file browser. -$control files (_ "Select file(s) to install") file (_ "Browse...") "~/Desktop/" "Plug-in|*.ny;*.NY|Lisp file|*.lsp;*.LSP|HTML file|*.htm;*.HTM;*.html;*.HTML|Text file|*.txt;*.TXT|All supported|*.ny;*.NY;*.lsp;*.LSP;*.htm;*.HTM;*.html;*.HTML;*.txt;*.TXT|All files|*.*;*" "open,exists,multiple" +$control files (_ "Select file(s) to install") file (_ "Browse...") "~/Desktop/" (((_ "Plug-in") (ny NY)) + ((_ "Lisp file") (lsp LSP)) + ((_ "HTML file") (htm HTM html HTML)) + ((_ "Text file") (txt TXT)) + ((_ "All supported") (ny NY lsp LSP htm HTM html HTML txt TXT)) + ((_ "All files") (""))) "open,exists,multiple" $control overwrite (_ "Allow overwriting") choice ((_ "Disallow") (_ "Allow")) 0 diff --git a/plug-ins/sample-data-export.ny b/plug-ins/sample-data-export.ny index d337ceed8..6e4cacd90 100644 --- a/plug-ins/sample-data-export.ny +++ b/plug-ins/sample-data-export.ny @@ -12,7 +12,10 @@ $copyright (_ "Released under terms of the GNU General Public License version 2" $control number (_ "Limit output to first") int-text (_ "samples") 100 1 1000000 $control units (_ "Measurement scale") choice ((_ "dB") (_ "Linear")) 0 -$control filename (_ "Export data to") file (_ "Select a file") "*default*/sample-data.txt" "Text file|*.txt;*.TXT|CSV files|*.csv;*.CSV|HTML files|*.html;*.HTML;*.htm;*.HTM|All files|*.*;*" "save,overwrite" +$control filename (_ "Export data to") file (_ "Select a file") "*default*/sample-data.txt" (((_ "Text file") (txt TXT)) + ((_ "CSV files") (csv CSV)) + ((_ "HTML files") (html HTML htm HTM)) + ((_ "All files") (""))) "save,overwrite" $control fileformat (_ "Index (text files only)") choice ((_ "None") ("Count" (_ "Sample Count")) ("Time" (_ "Time Indexed"))) diff --git a/plug-ins/sample-data-import.ny b/plug-ins/sample-data-import.ny index 05a67110b..3df9f0d3f 100644 --- a/plug-ins/sample-data-import.ny +++ b/plug-ins/sample-data-import.ny @@ -8,7 +8,8 @@ $author (_ "Steve Daulton") $release 2.3.0 $copyright (_ "Released under terms of the GNU General Public License version 2") -$control filename (_ "Select file") file "" "*default*/sample-data.txt" "Text file|*.txt;*.TXT|All files|*.*;*" "open,exists" +$control filename (_ "Select file") file "" "*default*/sample-data.txt" (((_ "Text file") (txt TXT)) + ((_ "All files") (""))) "open,exists" $control bad-data (_ "Invalid data handling") choice (("ThrowError" (_ "Throw Error")) ("ReadAsZero" (_ "Read as Zero"))) 0 diff --git a/src/AudacityHeaders.h b/src/AudacityHeaders.h index 176ed192b..5aee78fc5 100644 --- a/src/AudacityHeaders.h +++ b/src/AudacityHeaders.h @@ -31,7 +31,6 @@ #include #include -#include #include #include #include diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 20cb792c0..dd627c1b5 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -21,7 +21,6 @@ processing. See also MacrosWindow and ApplyMacroDialog. #include #include -#include #include #include "Project.h" diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index e35ae1531..da753a78a 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Benchmark.cpp b/src/Benchmark.cpp index 6b405bf80..e317a0120 100644 --- a/src/Benchmark.cpp +++ b/src/Benchmark.cpp @@ -25,7 +25,6 @@ of the BlockFile system. #include #include #include -#include #include #include #include diff --git a/src/FFmpeg.cpp b/src/FFmpeg.cpp index 0f227d976..8948b85cc 100644 --- a/src/FFmpeg.cpp +++ b/src/FFmpeg.cpp @@ -27,7 +27,6 @@ License: GPL v2. See License.txt. #include #include #include -#include #include #include diff --git a/src/FreqWindow.cpp b/src/FreqWindow.cpp index 5d53ca3ae..17b9c6c41 100644 --- a/src/FreqWindow.cpp +++ b/src/FreqWindow.cpp @@ -48,7 +48,6 @@ the mouse around. #include #include #include -#include #include #include #include diff --git a/src/LabelDialog.cpp b/src/LabelDialog.cpp index 53703af44..a124290ac 100644 --- a/src/LabelDialog.cpp +++ b/src/LabelDialog.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Tags.cpp b/src/Tags.cpp index a51f24b44..31711b157 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -55,7 +55,6 @@ #include #include -#include #include #include #include diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index 8040cffda..fa2fab4c4 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/src/VoiceKey.cpp b/src/VoiceKey.cpp index 08b219752..53b992e9c 100644 --- a/src/VoiceKey.cpp +++ b/src/VoiceKey.cpp @@ -25,7 +25,6 @@ or "OFF" point #include #include -#include #include #include #include diff --git a/src/effects/Contrast.cpp b/src/effects/Contrast.cpp index fc1efc24e..3f4bf7385 100644 --- a/src/effects/Contrast.cpp +++ b/src/effects/Contrast.cpp @@ -35,7 +35,6 @@ #endif #include -#include #include #include #include diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index ae0766e3d..c761681a6 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -663,6 +663,15 @@ bool Effect::CanExportPresets() return true; } +static const FileNames::FileTypes &PresetTypes() +{ + static const FileNames::FileTypes result { + { XO("Presets"), { wxT("txt") }, true }, + FileNames::AllFiles + }; + return result; +}; + void Effect::ExportPresets() { wxString params; @@ -672,11 +681,11 @@ void Effect::ExportPresets() auto path = FileNames::DefaultToDocumentsFolder(wxT("Presets/Path")); - wxFileDialog dlog(NULL, - _("Export Effect Parameters"), + FileDialogWrapper dlog(nullptr, + XO("Export Effect Parameters"), path.GetFullPath(), wxEmptyString, - _("Presets (*.txt)|*.txt|All files|*"), + PresetTypes(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER); if (dlog.ShowModal() != wxID_OK) { @@ -721,11 +730,11 @@ void Effect::ImportPresets() auto path = FileNames::DefaultToDocumentsFolder(wxT("Presets/Path")); - wxFileDialog dlog(NULL, - _("Import Effect Parameters"), + FileDialogWrapper dlog(nullptr, + XO("Import Effect Parameters"), path.GetPath(), wxEmptyString, - _("Presets (*.txt)|*.txt|All files|*"), + PresetTypes(), wxFD_OPEN | wxRESIZE_BORDER); if (dlog.ShowModal() != wxID_OK) { diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index cbeeeeaf7..9a2fde3ed 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -3721,16 +3721,20 @@ void EditCurvesDialog::OnDelete(wxCommandEvent & WXUNUSED(event)) #endif } -static const auto XMLtypes = FileNames::FileTypes{ - FileNames::XMLFiles -}; +static const FileNames::FileTypes &XMLtypes() +{ + static const FileNames::FileTypes results{ + FileNames::XMLFiles + }; + return results; +} void EditCurvesDialog::OnImport( wxCommandEvent & WXUNUSED(event)) { FileDialogWrapper filePicker( this, XO("Choose an EQ curve file"), FileNames::DataDir(), wxT(""), - XMLtypes ); + XMLtypes() ); wxString fileName; if( filePicker.ShowModal() == wxID_CANCEL) return; @@ -3752,7 +3756,7 @@ void EditCurvesDialog::OnExport( wxCommandEvent & WXUNUSED(event)) { FileDialogWrapper filePicker(this, XO("Export EQ curves as..."), FileNames::DataDir(), wxT(""), - XMLtypes, + XMLtypes(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER); // wxFD_CHANGE_DIR? wxString fileName; if( filePicker.ShowModal() == wxID_CANCEL) diff --git a/src/effects/ScoreAlignDialog.cpp b/src/effects/ScoreAlignDialog.cpp index 80bde3303..3bdfa32ce 100644 --- a/src/effects/ScoreAlignDialog.cpp +++ b/src/effects/ScoreAlignDialog.cpp @@ -37,7 +37,6 @@ It \TODO: description #include #include #include -#include #include #include #include diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 0ac0c29ae..a54baf7e0 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -1657,6 +1657,48 @@ std::vector NyquistEffect::ParseChoice(const wxString & text) return results; } +FileExtensions NyquistEffect::ParseFileExtensions(const wxString & text) +{ + // todo: error handling + FileExtensions results; + if (text[0] == wxT('(')) { + Tokenizer tzer; + tzer.Tokenize(text, true, 1, 1); + for (const auto &token : tzer.tokens) + results.push_back( UnQuote( token ) ); + } + return results; +} + +FileNames::FileType NyquistEffect::ParseFileType(const wxString & text) +{ + // todo: error handling + FileNames::FileType result; + if (text[0] == wxT('(')) { + Tokenizer tzer; + tzer.Tokenize(text, true, 1, 1); + auto &tokens = tzer.tokens; + if ( tokens.size() == 2 ) + result = + { UnQuoteMsgid( tokens[0] ), ParseFileExtensions( tokens[1] ) }; + } + return result; +} + +FileNames::FileTypes NyquistEffect::ParseFileTypes(const wxString & text) +{ + // todo: error handling + FileNames::FileTypes results; + if (text[0] == wxT('(')) { + Tokenizer tzer; + tzer.Tokenize(text, true, 1, 1); + auto &types = tzer.tokens; + for (auto &type : types) + results.push_back( ParseFileType( type ) ); + } + return results; +} + void NyquistEffect::RedirectOutput() { mRedirectOutput = true; @@ -1686,7 +1728,7 @@ void NyquistEffect::Stop() mStop = true; } -wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, +TranslatableString NyquistEffect::UnQuoteMsgid(const wxString &s, bool allowParens, wxString *pExtraString) { if (pExtraString) @@ -1695,7 +1737,8 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, int len = s.length(); if (len >= 2 && s[0] == wxT('\"') && s[len - 1] == wxT('\"')) { auto unquoted = s.Mid(1, len - 2); - return wxGetTranslation( unquoted ); + // Sorry, no context strings, yet + return TranslatableString{ unquoted, {} }; } else if (allowParens && len >= 2 && s[0] == wxT('(') && s[len - 1] == wxT(')')) { @@ -1708,12 +1751,13 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, // ("InternalString" (_ "Visible string")) // Recur to find the two strings *pExtraString = UnQuote(tokens[0], false); - return UnQuote(tokens[1]); + return UnQuoteMsgid(tokens[1]); } else { // Assume the first token was _ -- we don't check that // And the second is the string, which is internationalized - return UnQuote( tokens[1], false ); + // Sorry, no context strings, yet + return UnQuoteMsgid( tokens[1], false ); } } else @@ -1721,7 +1765,13 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, } else // If string was not quoted, assume no translation exists - return s; + return Verbatim( s ); +} + +wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens, + wxString *pExtraString) +{ + return UnQuoteMsgid( s, allowParens, pExtraString ).Translation(); } double NyquistEffect::GetCtrlValue(const wxString &s) @@ -2088,6 +2138,13 @@ bool NyquistEffect::Parse( ctrl.choices = ParseChoice(ctrl.label); ctrl.label = wxT(""); } + else if (tokens[3] == wxT("file")) { + ctrl.type = NYQ_CTRL_FILE; + ctrl.fileTypes = ParseFileTypes(tokens[6]); + // will determine file dialog styles: + ctrl.highStr = UnQuote( tokens[7] ); + ctrl.label = wxT(""); + } else { ctrl.label = UnQuote( ctrl.label ); @@ -2106,8 +2163,6 @@ bool NyquistEffect::Parse( ctrl.type = NYQ_CTRL_INT_TEXT; else if (tokens[3] == wxT("time")) ctrl.type = NYQ_CTRL_TIME; - else if (tokens[3] == wxT("file")) - ctrl.type = NYQ_CTRL_FILE; else { wxString str; @@ -2767,18 +2822,11 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S) S.AddSpace(10, 10); // Get default file extension if specified in wildcards - wxString defaultExtension; - size_t len = ctrl.lowStr.length(); - int characters = ctrl.lowStr.Find("*"); - - if (characters != wxNOT_FOUND) - { - if (static_cast(ctrl.lowStr.find("|", characters)) != wxNOT_FOUND) - len = ctrl.lowStr.find("|", characters) - 1; - if (static_cast(ctrl.lowStr.find(";", characters)) != wxNOT_FOUND) - len = std::min(static_cast(len), static_cast(ctrl.lowStr.find(";", characters)) - 1); - - defaultExtension = ctrl.lowStr.wxString::Mid(characters + 1, len - characters); + FileExtension defaultExtension; + if (!ctrl.fileTypes.empty()) { + const auto &type = ctrl.fileTypes[0]; + if ( !type.extensions.empty() ) + defaultExtension = type.extensions[0]; } resolveFilePath(ctrl.valStr, defaultExtension); @@ -3014,36 +3062,6 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt) { int i = evt.GetId() - ID_FILE; NyqControl & ctrl = mControls[i]; - ctrl.lowStr.Trim(true).Trim(false); // Wildcard filter. - - // Basic sanity check of wildcard flags so that we - // don't show scary wxFAIL_MSG from wxParseCommonDialogsFilter. - if (!ctrl.lowStr.empty()) - { - bool validWildcards = true; - size_t wildcards = 0; - wxStringTokenizer tokenizer(ctrl.lowStr, "|"); - while (tokenizer.HasMoreTokens()) - { - wxString token = tokenizer.GetNextToken().Trim(true).Trim(false); - if (token.empty()) - { - validWildcards = false; - break; - } - wildcards += 1; - } - // Users should not normally see this, unless they are writing Nyquist plug-ins. - if (wildcards % 2 != 0 || !validWildcards || ctrl.lowStr.EndsWith("|")) - { - Effect::MessageBox( - XO("Invalid wildcard string in 'path' control.'\n" - "Using empty string instead."), - wxOK | wxICON_EXCLAMATION | wxCENTRE, - XO("Error") ); - ctrl.lowStr = ""; - } - } // Get style flags: // Ensure legal combinations so that wxWidgets does not throw an assert error. @@ -3087,18 +3105,18 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt) wxFileName fname = ctrl.valStr; wxString defaultDir = fname.GetPath(); wxString defaultFile = fname.GetName(); - wxString message = _("Select a file"); + auto message = XO("Select a file"); if (flags & wxFD_MULTIPLE) - message = _("Select one or more files"); + message = XO("Select one or more files"); else if (flags & wxFD_SAVE) - message = _("Save file as"); + message = XO("Save file as"); - wxFileDialog openFileDialog(mUIParent->FindWindow(ID_FILE + i), + FileDialogWrapper openFileDialog(mUIParent->FindWindow(ID_FILE + i), message, defaultDir, defaultFile, - ctrl.lowStr, // wildcard filter + ctrl.fileTypes, flags); // styles if (openFileDialog.ShowModal() == wxID_CANCEL) @@ -3128,7 +3146,7 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt) mUIParent->FindWindow(ID_Text + i)->GetValidator()->TransferToWindow(); } -void NyquistEffect::resolveFilePath(wxString& path, wxString extension /* empty string */) +void NyquistEffect::resolveFilePath(wxString& path, FileExtension extension /* empty string */) { #if defined(__WXMSW__) path.Replace("/", wxFileName::GetPathSeparator()); @@ -3181,7 +3199,7 @@ void NyquistEffect::resolveFilePath(wxString& path, wxString extension /* empty { path = fname.GetPathWithSep() + _("untitled"); if (!extension.empty()) - path = path + extension; + path = path + '.' + extension; } } diff --git a/src/effects/nyquist/Nyquist.h b/src/effects/nyquist/Nyquist.h index b1ac01af4..299b621a9 100644 --- a/src/effects/nyquist/Nyquist.h +++ b/src/effects/nyquist/Nyquist.h @@ -12,6 +12,7 @@ #define __AUDACITY_EFFECT_NYQUIST__ #include "../Effect.h" +#include "../../FileNames.h" #include "nyx.h" @@ -49,6 +50,7 @@ public: wxString name; wxString label; std::vector choices; + FileNames::FileTypes fileTypes; wxString valStr; wxString lowStr; wxString highStr; @@ -137,6 +139,10 @@ private: wxString EscapeString(const wxString & inStr); static std::vector ParseChoice(const wxString & text); + FileExtensions ParseFileExtensions(const wxString & text); + FileNames::FileType ParseFileType(const wxString & text); + FileNames::FileTypes ParseFileTypes(const wxString & text); + static int StaticGetCallback(float *buffer, int channel, long start, long len, long totlen, void *userdata); @@ -161,7 +167,7 @@ private: bool q { false }; int paren{ 0 }; wxString tok; - wxArrayString tokens; + wxArrayStringEx tokens; bool Tokenize( const wxString &line, bool eof, @@ -169,6 +175,8 @@ private: }; bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first); + static TranslatableString UnQuoteMsgid(const wxString &s, bool allowParens = true, + wxString *pExtraString = nullptr); static wxString UnQuote(const wxString &s, bool allowParens = true, wxString *pExtraString = nullptr); double GetCtrlValue(const wxString &s); @@ -183,7 +191,7 @@ private: void OnTime(wxCommandEvent & evt); void OnFileButton(wxCommandEvent & evt); - void resolveFilePath(wxString & path, wxString extension = {}); + void resolveFilePath(wxString & path, FileExtension extension = {}); bool validatePath(wxString path); wxString ToTimeFormat(double t); diff --git a/src/export/ExportCL.cpp b/src/export/ExportCL.cpp index 198a671bb..b23a3c9d5 100644 --- a/src/export/ExportCL.cpp +++ b/src/export/ExportCL.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/export/ExportFFmpegDialogs.cpp b/src/export/ExportFFmpegDialogs.cpp index 0d3ef7ad6..4f4528ef3 100644 --- a/src/export/ExportFFmpegDialogs.cpp +++ b/src/export/ExportFFmpegDialogs.cpp @@ -2278,8 +2278,11 @@ void ExportFFmpegOptions::OnLoadPreset(wxCommandEvent& WXUNUSED(event)) DoOnCodecList(); } -static const FileNames::FileTypes FileTypes{ - FileNames::XMLFiles, FileNames::AllFiles +static const FileNames::FileTypes &FileTypes() +{ + static const FileNames::FileTypes result{ + FileNames::XMLFiles, FileNames::AllFiles }; + return result; }; /// @@ -2291,7 +2294,7 @@ void ExportFFmpegOptions::OnImportPresets(wxCommandEvent& WXUNUSED(event)) XO("Select xml file with presets to import"), gPrefs->Read(wxT("/FileFormats/FFmpegPresetDir")), wxEmptyString, - FileTypes, + FileTypes(), wxFD_OPEN); if (dlg.ShowModal() == wxID_CANCEL) return; path = dlg.GetPath(); @@ -2324,7 +2327,7 @@ void ExportFFmpegOptions::OnExportPresets(wxCommandEvent& WXUNUSED(event)) XO("Select xml file to export presets into"), gPrefs->Read(wxT("/FileFormats/FFmpegPresetDir")), wxEmptyString, - FileTypes, + FileTypes(), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); if (dlg.ShowModal() == wxID_CANCEL) return; path = dlg.GetPath(); diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index 040b3cacd..20cca32a2 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include diff --git a/src/export/ExportMultiple.cpp b/src/export/ExportMultiple.cpp index 16bd4433e..84ab9ea94 100644 --- a/src/export/ExportMultiple.cpp +++ b/src/export/ExportMultiple.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index af3407c57..5b3c2032d 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -27,7 +27,6 @@ KeyConfigPrefs and MousePrefs use. #include #include #include -#include #include #include #include