Audacity 3.2.0
HelpText.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 HelpText.cpp
6
7 James Crook
8
9********************************************************************//********************************************************************/
14
15
16#include "HelpText.h"
17
18#include <wx/colour.h>
19#include <wx/sstream.h>
20#include <wx/txtstrm.h>
21
22#include "FileNames.h"
23#include "Internat.h"
24#include "AllThemeResources.h"
25#include "Theme.h"
26
27
28wxString HtmlColourOfIndex( int i ){
29 wxColour c = theTheme.Colour(i);
30 return wxString::Format("\"#%02X%02X%02X\"",
31 c.Red(), c.Green(), c.Blue() );
32}
33
34static wxString WrapText( const wxString & Text )
35{
36 return wxString(wxT(""))+
37 wxT("<html><head></head>") +
38 wxT("<body bgcolor=") + HtmlColourOfIndex(clrTrackInfo) + wxT(">") +
39 wxT("<font color=") + HtmlColourOfIndex(clrTrackPanelText) + wxT(">") +
40 wxT("<p>") + Text +
41 wxT("</font>")+
42 wxT("</body></html>");
43}
44
45static wxString InnerLink( const wxString &Key, const wxString& Text )
46{
47 return wxString(wxT("")) +
48 wxT("<a href='innerlink:") +
49 Key +
50 wxT("'>") +
51 Text +
52 wxT("</a>");
53}
54
55static wxString FileLink( const wxString &Key, const wxString& Text )
56{
57 return wxString(wxT("")) +
58 wxT("<a href='") +
59 wxT("file:") +
61 Key +
62 wxT("'>") +
63 Text +
64 wxT("</a>");
65}
66
67static wxString TypedLink( const wxString &Key, const wxString& Text )
68{
69 return wxString(wxT("")) +
70 wxT("<a href='") +
71 Key +
72 wxT("'>") +
73 Text +
74 wxT("</a>");
75}
76
77static wxString LinkExpand( const wxString & Text )
78{
79 wxString Temp = Text;
80 int i,j,k;
81 while( (i=Temp.First( wxT("[[") ))!= wxNOT_FOUND )
82 {
83 wxString Key = Temp.Mid(i+2);
84 j = Key.First( wxT("|") );
85 if( j==wxNOT_FOUND )
86 return Temp;
87 wxString LinkText = Key.Mid( j+1);
88 k = LinkText.First( wxT("]]") );
89 if( k==wxNOT_FOUND )
90 return Temp;
91 Key = Key.Mid( 0, j );
92 LinkText = LinkText.Mid( 0, k );
93
94 LinkText=wxString("<font color=") + HtmlColourOfIndex(clrSample) + wxT(">") +LinkText+"</font>";
95 wxString Replacement;
96 if( Key.StartsWith( wxT("file:") ))
97 {
98 Replacement = FileLink( Key.Mid( 5 ), LinkText );
99 }
100 else if( Key.StartsWith( wxT("http:") ))
101 {
102 Replacement = TypedLink( Key, LinkText );
103 }
104 else if( Key.StartsWith( wxT("https:") ))
105 {
106 Replacement = TypedLink( Key, LinkText );
107 }
108 else if( Key.StartsWith( wxT("mailto:") ))
109 {
110 Replacement = TypedLink( Key, LinkText );
111 }
112 else if( Key.StartsWith( wxT("*URL*") ))
113 {
114 Replacement = TypedLink( Key, LinkText );
115 }
116 else
117 {
118 Replacement = InnerLink( Key, LinkText );
119 }
120
121
122 Temp = Temp.Mid( 0, i ) + Replacement + Temp.Mid( i + j + k + 5 );// 5 for the [[|]]
123 }
124 return Temp;
125}
126
127TranslatableString TitleText( const wxString & Key )
128{
129 if(Key==wxT("welcome"))
130 {
131 return XO("Welcome!");
132 }
133
134 if(Key ==wxT("play") )
135 {
136 /* i18n-hint: Title for a topic.*/
137 return XO("Playing Audio");
138 }
139 if((Key ==wxT("record") ) || (Key ==wxT("norecord") ))
140 {
141 /* i18n-hint: Title for a topic.*/
142 return XO("Recording Audio");
143 }
144 if(Key ==wxT("inputdevice") )
145 {
146 /* i18n-hint: Title for a topic.*/
147 return XO("Recording - Choosing the Recording Device");
148 }
149 if(Key ==wxT("inputsource") )
150 {
151 /* i18n-hint: Title for a topic.*/
152 return XO("Recording - Choosing the Recording Source");
153 }
154 if(Key ==wxT("inputlevel") )
155 {
156 /* i18n-hint: Title for a topic.*/
157 return XO("Recording - Setting the Recording Level");
158 }
159 if((Key ==wxT("edit") ) || (Key==wxT("grey")))
160 {
161 /* i18n-hint: Title for a topic.*/
162 return XO("Editing and greyed out Menus");
163 }
164 if(Key ==wxT("export") )
165 {
166 /* i18n-hint: Title for a topic.*/
167 return XO("Exporting an Audio File");
168 }
169 if(Key ==wxT("save") )
170 {
171 /* i18n-hint: Title for a topic.*/
172 return XO("Saving an Audacity Project");
173 }
174 if(Key ==wxT("wma-proprietary") )
175 {
176 /* i18n-hint: Title for a topic.*/
177 return XO("Support for Other Formats");
178 }
179 if(Key ==wxT("burncd") )
180 {
181 /* i18n-hint: Title for a topic.*/
182 return XO("Burn to CD" );
183 }
184 if(Key == wxT("remotehelp") )
185 {
186 return XO("No Local Help");
187 }
188 // Uh oh, no translation...
189 return Verbatim( Key );
190}
191
192static wxString HelpTextBuiltIn( const wxString & Key )
193{
194 if(Key==wxT("wma-proprietary"))
195 {
196 wxStringOutputStream o;
197 wxTextOutputStream s(o);
198 s
199 << wxT("<p>")
200 << XO(
201"Audacity can import unprotected files in many other formats (such as M4A and WMA, \
202compressed WAV files from portable recorders and audio from video files) if you download and install \
203the optional [[https://support.audacityteam.org/basics/installing-ffmpeg| \
204FFmpeg library]] to your computer.")
205 << wxT("</p><p>")
206 << XO(
207"You can also read our help on importing \
208[[https://manual.audacityteam.org/man/playing_and_recording.html#midi|MIDI files]] \
209and tracks from [[https://manual.audacityteam.org/man/faq_opening_and_saving_files.html#fromcd| \
210audio CDs]].")
211 << wxT("</p>")
212 ;
213 return WrapText( o.GetString() );
214 }
215
216 // Remote help allows us to link to a local copy of the help if it exists,
217 // or provide a message that takes you to the Internet if it does not.
218 // It's used by the menu item Help > Index
219 if(Key == wxT("remotehelp") )
220 {
221 wxStringOutputStream o;
222 wxTextOutputStream s(o);
223 s
224// *URL* will be replaced by whatever URL we are looking for.
225 << XO(
226"The Manual does not appear to be installed. \
227Please [[*URL*|view the Manual online]] or \
228[[https://manual.audacityteam.org/man/unzipping_the_manual.html| \
229download the Manual]].<br><br>\
230To always view the Manual online, change \"Location of Manual\" in \
231Interface Preferences to \"From Internet\".")
232 ;
233 return WrapText( o.GetString() );
234 }
235 return {};
236}
237
238wxString HelpText( const wxString & Key )
239{
240
241 // Possible future enhancement...
242 // We could look for the text as a local file and use
243 // that if we find it...
244 // if( wxFileExists( Path+Key ) )
245 // ...
246
247 wxString Text;
248 Text = HelpTextBuiltIn( Key );
249
250 if( !Text.empty())
251 return LinkExpand( Text );
252
253 // Perhaps useful for debugging - we'll return key that we didn't find.
254 return WrapText( Key );
255}
256
257
258wxString FormatHtmlText( const wxString & Text ){
259
260 wxString localeStr = wxLocale::GetSystemEncodingName();
261
262 return
263 wxT("<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=") +
264 localeStr +
265 wxT("\"></head>") +
266 WrapText( LinkExpand( Text ))+
267 wxT("</html>");
268}
269
wxT("CloseDown"))
XO("Cut/Copy/Paste")
TranslatableString TitleText(const wxString &Key)
Definition: HelpText.cpp:127
static wxString TypedLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:67
static wxString HelpTextBuiltIn(const wxString &Key)
Definition: HelpText.cpp:192
static wxString WrapText(const wxString &Text)
Definition: HelpText.cpp:34
static wxString LinkExpand(const wxString &Text)
Definition: HelpText.cpp:77
wxString FormatHtmlText(const wxString &Text)
Definition: HelpText.cpp:258
static wxString FileLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:55
wxString HelpText(const wxString &Key)
Definition: HelpText.cpp:238
static wxString InnerLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:45
wxString HtmlColourOfIndex(int i)
Definition: HelpText.cpp:28
THEME_API Theme theTheme
Definition: Theme.cpp:82
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
wxColour & Colour(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
FILES_API FilePath HtmlHelpDir()