Audacity 3.2.0
ThemePrefs.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ThemePrefs.cpp
6
7 James Crook
8
9 Audacity is free software.
10 This file is licensed under the wxWidgets license, see License.txt
11
12********************************************************************//********************************************************************/
30
31
32#include "ThemePrefs.h"
33
34#include <wx/app.h>
35#include <wx/wxprec.h>
36#include "Prefs.h"
37#include "Theme.h"
38#include "ShuttleGui.h"
39#include "AColor.h"
40#include "BasicUI.h"
41
49};
50
51BEGIN_EVENT_TABLE(ThemePrefs, PrefsPanel)
59
60static bool ConfirmSave()
61{
62 if (!GUIBlendThemes.Read())
63 return true;
64
65 using namespace BasicUI;
66 const auto message = Verbatim(
67"\"Blend system and Audacity theme\" in Interface Preferences was on.\n"
68"This may cause images to to be re-saved with slight changes of color."
69 );
70
71 return MessageBoxResult::Cancel != ShowMessageBox(message,
72 MessageBoxOptions{}.CancelButton().IconStyle(Icon::Warning));
73}
74
75ThemePrefs::ThemePrefs(wxWindow * parent, wxWindowID winid)
76/* i18n-hint: A theme is a consistent visual style across an application's
77 graphical user interface, including choices of colors, and similarity of images
78 such as those on button controls. Audacity can load and save alternative
79 themes. */
80: PrefsPanel(parent, winid, XO("Theme"))
81{
82 Populate();
83}
84
86{
87}
88
90{
92}
93
95{
96 return XO("Preferences for Theme");
97}
98
100{
101 return "Theme_Preferences";
102}
103
106{
107 // First any pre-processing for constructing the GUI.
108
109 //------------------------- Main section --------------------
110 // Now construct the GUI itself.
111 // Use 'eIsCreatingFromPrefs' so that the GUI is
112 // initialised with values from gPrefs.
115 // ----------------------- End of main section --------------
116}
117
120{
121 S.SetBorder(2);
122 S.StartScroller();
123
124 S.StartStatic(XO("Info"));
125 {
126 S.AddFixedText(
127 XO(
128"Themability is an experimental feature.\n\nTo try it out, click \"Save Theme Cache\" then find and modify the images and colors in\nImageCacheVxx.png using an image editor such as the Gimp.\n\nClick \"Load Theme Cache\" to load the changed images and colors back into Audacity.")
129 );
130
131#ifdef _DEBUG
132 S.AddFixedText(
133 Verbatim(
134"This is a debug version of Audacity, with an extra button, 'Output Sourcery'. This will save\nC versions of the image caches that can be compiled in as defaults.")
135 );
136#endif
137
138 S.AddFixedText(
139 XO(
140"Saving and loading individual theme files uses a separate file for each image, but is\notherwise the same idea.")
141 );
142 }
143 S.EndStatic();
144
145 /* i18n-hint: && in here is an escape character to get a single & on screen,
146 * so keep it as is */
147 S.StartStatic( XO("Theme Cache - Images && Color"));
148 {
149 S.StartHorizontalLay(wxALIGN_LEFT);
150 {
151 S.Id(idSaveThemeCache).AddButton(XXO("Save Theme Cache"));
152 S.Id(idLoadThemeCache).AddButton(XXO("Load Theme Cache"));
153
154 // This next button is only provided in Debug mode.
155 // It is for developers who are compiling Audacity themselves
156 // and who wish to generate NEW *ThemeAsCeeCode.h and compile them in.
157#ifdef _DEBUG
158 S.Id(idSaveThemeAsCode).AddButton(Verbatim("Output Sourcery"));
159#endif
160
161 S.Id(idReadThemeInternal).AddButton(XXO("&Defaults"));
162 }
163 S.EndHorizontalLay();
164 }
165 S.EndStatic();
166
167 // JKC: 'Ergonomic' details:
168 // Theme components are used much less frequently than
169 // the ImageCache. Yet it's easy to click them 'by mistake'.
170 //
171 // To reduce that risk, we use a separate box to separate them off.
172 // And choose text on the buttons that is shorter, making the
173 // buttons smaller and less tempting to click.
174 S.StartStatic( XO("Individual Theme Files"),1);
175 {
176 S.StartHorizontalLay(wxALIGN_LEFT);
177 {
178 S.Id(idSaveThemeComponents).AddButton( XXO("Save Files"));
179 S.Id(idLoadThemeComponents).AddButton( XXO("Load Files"));
180 }
181 S.EndHorizontalLay();
182 }
183 S.EndStatic();
184 S.EndScroller();
185
186}
187
189void ThemePrefs::OnLoadThemeComponents(wxCommandEvent & WXUNUSED(event))
190{
191 wxBusyCursor busy;
194}
195
197void ThemePrefs::OnSaveThemeComponents(wxCommandEvent & WXUNUSED(event))
198{
199 if (!ConfirmSave())
200 return;
201 wxBusyCursor busy;
203}
204
206void ThemePrefs::OnLoadThemeCache(wxCommandEvent & WXUNUSED(event))
207{
208 wxBusyCursor busy;
211}
212
214void ThemePrefs::OnSaveThemeCache(wxCommandEvent & WXUNUSED(event))
215{
216 if (!ConfirmSave())
217 return;
218 wxBusyCursor busy;
220 theTheme.WriteImageMap();// bonus - give them the html version.
221}
222
224void ThemePrefs::OnReadThemeInternal(wxCommandEvent & WXUNUSED(event))
225{
226 wxBusyCursor busy;
229}
230
232void ThemePrefs::OnSaveThemeAsCode(wxCommandEvent & WXUNUSED(event))
233{
234 if (!ConfirmSave())
235 return;
236 wxBusyCursor busy;
238 theTheme.WriteImageDefs();// bonus - give them the Defs too.
239}
240
243{
246
250 return true;
251}
252
254{
258}
259
260#ifdef EXPERIMENTAL_THEME_PREFS
261namespace{
263 [](wxWindow *parent, wxWindowID winid, AudacityProject *)
264 {
265 wxASSERT(parent); // to justify safenew
266 return safenew ThemePrefs(parent, winid);
267 },
268 false,
269 // Register with an explicit ordering hint because this one is
270 // only conditionally compiled
271 { "", { Registry::OrderingHint::After, "Effects" } }
272};
273}
274#endif
Toolkit-neutral facade for basic user interface services.
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:9
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46
@ eIsSavingToPrefs
Definition: ShuttleGui.h:47
THEME_API Theme theTheme
Definition: Theme.cpp:82
THEME_API BoolSetting GUIBlendThemes
eThemePrefsIds
Definition: ThemePrefs.cpp:42
@ idLoadThemeComponents
Definition: ThemePrefs.cpp:45
@ idSaveThemeAsCode
Definition: ThemePrefs.cpp:48
@ idSaveThemeCache
Definition: ThemePrefs.cpp:44
@ idReadThemeInternal
Definition: ThemePrefs.cpp:47
@ idSaveThemeComponents
Definition: ThemePrefs.cpp:46
@ idLoadThemeCache
Definition: ThemePrefs.cpp:43
static bool ConfirmSave()
Definition: ThemePrefs.cpp:60
#define THEME_PREFS_PLUGIN_SYMBOL
Definition: ThemePrefs.h:23
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
static void ApplyUpdatedImages()
Definition: AColor.cpp:860
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
void SwitchTheme(teThemeType Theme)
Definition: Theme.cpp:217
void DeleteUnusedThemes()
void SaveThemeAsCode()
teThemeType GetFallbackThemeType()
Definition: Theme.cpp:889
void WriteImageMap()
Definition: Theme.cpp:786
void CreateImageCache()
Definition: Theme.cpp:614
static bool LoadPreferredTheme()
Definition: Theme.cpp:162
void WriteImageDefs()
Writes a series of Macro definitions that can be used in the include file.
Definition: Theme.cpp:847
void SaveThemeComponents()
void LoadThemeComponents(bool bOkIfNotFound=false)
Definition: Theme.cpp:1032
A PrefsPanel that configures dynamic loading of Theme icons and colours.
Definition: ThemePrefs.h:26
void OnReadThemeInternal(wxCommandEvent &e)
Read Theme from internal storage.
Definition: ThemePrefs.cpp:224
void PopulateOrExchange(ShuttleGui &S) override
Create the dialog contents, or exchange data with it.
Definition: ThemePrefs.cpp:119
bool Commit() override
Update the preferences stored on disk.
Definition: ThemePrefs.cpp:242
ComponentInterfaceSymbol GetSymbol() const override
Definition: ThemePrefs.cpp:89
void OnSaveThemeComponents(wxCommandEvent &e)
Save Theme to multiple png files.
Definition: ThemePrefs.cpp:197
void OnSaveThemeAsCode(wxCommandEvent &e)
Save Theme as C source code.
Definition: ThemePrefs.cpp:232
void OnLoadThemeComponents(wxCommandEvent &e)
Load Theme from multiple png files.
Definition: ThemePrefs.cpp:189
~ThemePrefs(void)
Definition: ThemePrefs.cpp:85
void OnLoadThemeCache(wxCommandEvent &e)
Load Theme from single png file.
Definition: ThemePrefs.cpp:206
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: ThemePrefs.cpp:99
ThemePrefs(wxWindow *parent, wxWindowID winid)
Definition: ThemePrefs.cpp:75
void OnSaveThemeCache(wxCommandEvent &e)
Save Themes, each to a single png file.
Definition: ThemePrefs.cpp:214
void Cancel() override
Definition: ThemePrefs.cpp:253
TranslatableString GetDescription() const override
Definition: ThemePrefs.cpp:94
void Populate()
Creates the dialog and its contents.
Definition: ThemePrefs.cpp:105
Holds a msgid for the translation catalog; may also bind format arguments.
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:279
MessageBoxOptions && CancelButton() &&
Definition: BasicUI.h:114