mirror of
https://github.com/cookiengineer/audacity
synced 2026-02-05 19:21:59 +01:00
Define and use TranslatableStringArray. This lets you define "listeners"...
... for language changes, without inserting extra code to send the notifications.
This commit is contained in:
80
src/TranslatableStringArray.h
Normal file
80
src/TranslatableStringArray.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
TranslatableStringArray.h
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __AUDACITY_TRANSLATABLE_STRING_ARRAY__
|
||||
#define __AUDACITY_TRANSLATABLE_STRING_ARRAY__
|
||||
|
||||
#include <vector>
|
||||
#include <wx/app.h>
|
||||
#include <wx/event.h>
|
||||
|
||||
class wxArrayString;
|
||||
|
||||
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_LANGUAGE_CHANGE, -1);
|
||||
|
||||
/*
|
||||
This class can maintain a static table containing user visible strings that updates
|
||||
itself properly when the language is changed in Preferences.
|
||||
|
||||
Typical usage is to define a derived class, override Populate(), and then
|
||||
make a singleton instance of the class.
|
||||
|
||||
Populate() is called only as needed to fill the table on demand the first
|
||||
time it is used after application startup or language change.
|
||||
*/
|
||||
|
||||
template<typename ArrayType> class TranslatableArray
|
||||
: public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
|
||||
TranslatableArray()
|
||||
{
|
||||
if (wxTheApp)
|
||||
wxTheApp->Connect(EVT_LANGUAGE_CHANGE,
|
||||
wxCommandEventHandler(TranslatableArray::Invalidate),
|
||||
NULL,
|
||||
this);
|
||||
}
|
||||
|
||||
~TranslatableArray()
|
||||
{
|
||||
if (wxTheApp)
|
||||
wxTheApp->Disconnect(EVT_LANGUAGE_CHANGE,
|
||||
wxCommandEventHandler(TranslatableArray::Invalidate),
|
||||
NULL,
|
||||
this);
|
||||
}
|
||||
|
||||
const ArrayType& Get()
|
||||
{
|
||||
if (mContents.empty())
|
||||
Populate();
|
||||
return mContents;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Override this function to fill in mContents,
|
||||
// typically by lines like
|
||||
// mContents.push_back(_("Translate me"));
|
||||
virtual void Populate() = 0;
|
||||
|
||||
void Invalidate(wxCommandEvent &evt)
|
||||
{
|
||||
mContents.clear();
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
ArrayType mContents;
|
||||
};
|
||||
|
||||
typedef TranslatableArray<wxArrayString> TranslatableStringArray;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user