1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-29 23:19:28 +02:00

Finish the job of commit 7638dd0, for i18n of file dialog masks...

... Work reamained for effect presets, and for file dialogs made from Nyquist
scripts.  The four Nyquist scripts using file dialogs were rewritten in a new
format.

This keeps strange characters like | and * out of the strings given to
translators.  Instead there are only descriptions of file types.

Also fixed a bug in static initialization of tables of file types, and removes
inclusions of wx/filedlg.h, and the last uses of class wxFileDialog.
This commit is contained in:
Paul Licameli 2020-05-22 20:37:31 -04:00
commit 928f3c8788
25 changed files with 129 additions and 93 deletions

View File

@ -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"))

View File

@ -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

View File

@ -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")))

View File

@ -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

View File

@ -31,7 +31,6 @@
#include <wx/wx.h>
#include <wx/bitmap.h>
#include <wx/filedlg.h>
#include <wx/filefn.h>
#include <wx/image.h>
#include <wx/ffile.h>

View File

@ -21,7 +21,6 @@ processing. See also MacrosWindow and ApplyMacroDialog.
#include <wx/defs.h>
#include <wx/dir.h>
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include "Project.h"

View File

@ -26,7 +26,6 @@
#include <wx/defs.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/filedlg.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/statbox.h>

View File

@ -25,7 +25,6 @@ of the BlockFile system.
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/dialog.h>
#include <wx/filedlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/timer.h>

View File

@ -27,7 +27,6 @@ License: GPL v2. See License.txt.
#include <wx/checkbox.h>
#include <wx/dynlib.h>
#include <wx/file.h>
#include <wx/filedlg.h>
#include <wx/log.h>
#include <wx/textctrl.h>

View File

@ -48,7 +48,6 @@ the mouse around.
#include <wx/font.h>
#include <wx/image.h>
#include <wx/file.h>
#include <wx/filedlg.h>
#include <wx/intl.h>
#include <wx/scrolbar.h>
#include <wx/sizer.h>

View File

@ -21,7 +21,6 @@
#include <wx/choice.h>
#include <wx/dc.h>
#include <wx/dialog.h>
#include <wx/filedlg.h>
#include <wx/grid.h>
#include <wx/intl.h>
#include <wx/scrolbar.h>

View File

@ -55,7 +55,6 @@
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/filedlg.h>
#include <wx/filename.h>
#include <wx/intl.h>
#include <wx/listctrl.h>

View File

@ -34,7 +34,6 @@
#include <wx/dir.h>
#include <wx/datectrl.h>
#include <wx/datetime.h>
#include <wx/filedlg.h>
#include <wx/intl.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>

View File

@ -25,7 +25,6 @@ or "OFF" point
#include <math.h>
#include <stdio.h>
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include <wx/intl.h>
#include <iostream>

View File

@ -35,7 +35,6 @@
#endif
#include <wx/button.h>
#include <wx/filedlg.h>
#include <wx/valtext.h>
#include <wx/log.h>
#include <wx/wfstream.h>

View File

@ -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) {

View File

@ -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)

View File

@ -37,7 +37,6 @@ It \TODO: description
#include <wx/image.h>
#include <wx/dcmemory.h>
#include <wx/file.h>
#include <wx/filedlg.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>

View File

@ -1657,6 +1657,48 @@ std::vector<EnumValueSymbol> 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<int>(ctrl.lowStr.find("|", characters)) != wxNOT_FOUND)
len = ctrl.lowStr.find("|", characters) - 1;
if (static_cast<int>(ctrl.lowStr.find(";", characters)) != wxNOT_FOUND)
len = std::min(static_cast<int>(len), static_cast<int>(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;
}
}

View File

@ -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<EnumValueSymbol> choices;
FileNames::FileTypes fileTypes;
wxString valStr;
wxString lowStr;
wxString highStr;
@ -137,6 +139,10 @@ private:
wxString EscapeString(const wxString & inStr);
static std::vector<EnumValueSymbol> 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);

View File

@ -19,7 +19,6 @@
#include <wx/button.h>
#include <wx/cmdline.h>
#include <wx/combobox.h>
#include <wx/filedlg.h>
#include <wx/log.h>
#include <wx/process.h>
#include <wx/sizer.h>

View File

@ -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();

View File

@ -69,7 +69,6 @@
#include <wx/checkbox.h>
#include <wx/dynlib.h>
#include <wx/ffile.h>
#include <wx/filedlg.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/mimetype.h>

View File

@ -26,7 +26,6 @@
#include <wx/dirdlg.h>
#include <wx/event.h>
#include <wx/listbase.h>
#include <wx/filedlg.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/intl.h>

View File

@ -27,7 +27,6 @@ KeyConfigPrefs and MousePrefs use.
#include <wx/defs.h>
#include <wx/ffile.h>
#include <wx/intl.h>
#include <wx/filedlg.h>
#include <wx/menu.h>
#include <wx/button.h>
#include <wx/radiobut.h>