forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIPrefs.cpp
239 lines (200 loc) · 6.06 KB
/
GUIPrefs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**********************************************************************
Audacity: A Digital Audio Editor
GUIPrefs.cpp
Brian Gunlogson
Joshua Haberman
Dominic Mazzoni
James Crook
*******************************************************************//**
\class GUIPrefs
\brief A PrefsPanel for general GUI preferences.
*//*******************************************************************/
#include "GUIPrefs.h"
#include <wx/defs.h>
#include <mutex> // once_flag
#include "FileNames.h"
#include "Languages.h"
#include "Theme.h"
#include "Prefs.h"
#include "ShuttleGui.h"
#include "Decibels.h"
#include "Beats.h"
#include "ThemePrefs.h"
#include "AColor.h"
#include "GUISettings.h"
GUIPrefs::GUIPrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: refers to Audacity's user interface settings */
: PrefsPanel(parent, winid, XC("Interface", "GUI"))
{
Populate();
}
GUIPrefs::~GUIPrefs()
{
}
ComponentInterfaceSymbol GUIPrefs::GetSymbol() const
{
return GUI_PREFS_PLUGIN_SYMBOL;
}
TranslatableString GUIPrefs::GetDescription() const
{
return XO("Preferences for GUI");
}
ManualPageID GUIPrefs::HelpPageName()
{
return "Interface_Preferences";
}
void GUIPrefs::GetRangeChoices(
TranslatableStrings *pChoices,
wxArrayStringEx *pCodes,
int *pDefaultRangeIndex
)
{
static const wxArrayStringEx sCodes = {
wxT("36") ,
wxT("48") ,
wxT("60") ,
wxT("72") ,
wxT("84") ,
wxT("96") ,
wxT("120") ,
wxT("145") ,
};
if (pCodes)
*pCodes = sCodes;
static const std::initializer_list<TranslatableString> sChoices = {
XO("-36 dB (shallow range for high-amplitude editing)") ,
XO("-48 dB (PCM range of 8 bit samples)") ,
XO("-60 dB (PCM range of 10 bit samples)") ,
XO("-72 dB (PCM range of 12 bit samples)") ,
XO("-84 dB (PCM range of 14 bit samples)") ,
XO("-96 dB (PCM range of 16 bit samples)") ,
XO("-120 dB (approximate limit of human hearing)") ,
XO("-145 dB (PCM range of 24 bit samples)") ,
};
if (pChoices)
*pChoices = sChoices;
if (pDefaultRangeIndex)
*pDefaultRangeIndex = 2; // 60 == ENV_DB_RANGE
}
void GUIPrefs::Populate()
{
// First any pre-processing for constructing the GUI.
Languages::GetLanguages(
FileNames::AudacityPathList(), mLangCodes, mLangNames);
GetRangeChoices(&mRangeChoices, &mRangeCodes, &mDefaultRangeIndex);
#if 0
mLangCodes.insert( mLangCodes.end(), {
// only for testing...
"kg" ,
"ep" ,
} );
mLangNames.insert( mLangNames.end(), {
"Klingon" ,
"Esperanto" ,
} );
#endif
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
// initialised with values from gPrefs.
ShuttleGui S(this, eIsCreatingFromPrefs);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void GUIPrefs::PopulateOrExchange(ShuttleGui & S)
{
ChoiceSetting LanguageSetting{ wxT("/Locale/Language"),
{ ByColumns, mLangNames, mLangCodes }
};
ChoiceSetting DBSetting{ DecibelScaleCutoff,
{ ByColumns, mRangeChoices, mRangeCodes },
mDefaultRangeIndex
};
S.SetBorder(2);
S.StartScroller();
S.StartStatic(XO("Display"));
{
S.StartMultiColumn(2);
{
S.TieChoice( XXO("&Language:"), LanguageSetting);
// S.TieChoice( XXO("Location of &Manual:"), GUIManualLocation);
S.TieChoice( XXO("Th&eme:"), GUITheme());
S.TieChoice( XXO("Meter dB &range:"), DBSetting);
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartStatic(XO("Options"));
{
// Start wording of options with a verb, if possible.
S.TieCheckBox(XXO("Show 'How to Get &Help' at launch"),
{wxT("/GUI/ShowSplashScreen"),
true});
S.TieCheckBox(XXO("Show e&xtra menus"),
{wxT("/GUI/ShowExtraMenus"),
false});
#ifdef EXPERIMENTAL_THEME_PREFS
// We do not want to make this option mainstream. It's a
// convenience for developers.
S.TieCheckBox(XXO("Show alternative &styling (Mac vs PC)"),
{wxT("/GUI/ShowMac"),
false});
#endif
S.TieCheckBox(XXO("&Beep on completion of longer activities"),
{wxT("/GUI/BeepOnCompletion"),
false});
S.TieCheckBox(XXO("Re&tain labels if selection snaps to a label"),
{wxT("/GUI/RetainLabels"),
false});
#ifndef __WXMAC__
/* i18n-hint: RTL stands for 'Right to Left' */
S.TieCheckBox(XXO("Use mostly Left-to-Right layouts in RTL languages"),
{"/GUI/RtlWorkaround",
true});
#endif
#ifdef EXPERIMENTAL_CEE_NUMBERS_OPTION
S.TieCheckBox(XXO("Never use comma as decimal point"),
{wxT("/Locale/CeeNumberFormat"),
false});
#endif
}
S.EndStatic();
S.EndScroller();
}
bool GUIPrefs::Commit()
{
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
// If language has changed, we want to change it now, not on the next reboot.
wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
wxString usedLang = GUISettings::SetLang(lang);
// Bug 1523: Previously didn't check no-language (=System Language)
if (!(lang.empty() || lang == L"System") && (lang != usedLang)) {
// lang was not usable and is not system language. We got overridden.
gPrefs->Write(wxT("/Locale/Language"), usedLang);
gPrefs->Flush();
}
// Reads preference GUITheme
{
wxBusyCursor busy;
theTheme.LoadPreferredTheme();
theTheme.DeleteUnusedThemes();
}
AColor::ApplyUpdatedImages();
DecibelScaleCutoff.Invalidate();
return true;
}
int ShowClippingPrefsID()
{
static int value = wxNewId();
return value;
}
namespace{
PrefsPanel::Registration sAttachment{ "GUI",
[](wxWindow *parent, wxWindowID winid, AudacityProject *)
{
wxASSERT(parent); // to justify safenew
return safenew GUIPrefs(parent, winid);
}
};
}