Audacity 3.2.0
CommandTargets.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 License: wxwidgets
6
7 Dan Horgan
8
9******************************************************************//*******************************************************************/
15#include "CommandTargets.h"
16#include "BasicUI.h"
17#include <locale>
18#include <sstream>
19
21
23{
24 Flush();
25}
26
28{
29 wxString Padding;
30 Padding.Pad( mCounts.size() *2 -2);
31 Update( wxString::Format( "%s%s[ ", ( mCounts.back() > 0 ) ? ",\n" : "\n", Padding ));
32 mCounts.back() += 1;
33 mCounts.push_back( 0 );
34}
35
37 if( mCounts.size() > 1 ){
38 mCounts.pop_back();
39 }
40 Update( " ]" );
41}
43 wxString Padding;
44 Padding.Pad( mCounts.size() *2 -2);
45 Update( wxString::Format( "%s%s{ ", ( mCounts.back() > 0 ) ? ",\n" : "\n", Padding ));
46 mCounts.back() += 1;
47 mCounts.push_back( 0 );
48}
50 if( mCounts.size() > 1 ){
51 mCounts.pop_back();
52 }
53 Update( " }" );
54}
55void CommandMessageTarget::AddItem(const wxString &value, const wxString &name){
56 wxString Padding;
57 Padding.Pad( mCounts.size() *2 -2);
58 Padding = (( value.length() < 15 ) || (mCounts.back()<=0)) ? wxString{} : wxString("\n") + Padding;
59 if( name.empty() )
60 Update( wxString::Format( "%s%s\"%s\"", (mCounts.back()>0)?", ":"", Padding, Escaped(value)));
61 else
62 Update( wxString::Format( "%s%s\"%s\":\"%s\"", (mCounts.back()>0)?", ":"", Padding, name, Escaped(value)));
63 mCounts.back() += 1;
64}
65
66void CommandMessageTarget::AddBool(const bool value, const wxString &name){
67 if( name.empty() )
68 Update( wxString::Format( "%s\"%s\"", (mCounts.back()>0)?", ":"", value?"true":"false"));
69 else
70 Update( wxString::Format( "%s\"%s\":\"%s\"", (mCounts.back()>0)?", ":"", name,value?"true":"false"));
71 mCounts.back() += 1;
72}
73
74void CommandMessageTarget::AddItem(const double value, const wxString &name){
75 std::stringstream str;
76 std::locale nolocale("C");
77 str.imbue(nolocale);
78
79 if( name.empty() )
80 str << ((mCounts.back()>0)? ", " : "") << value;
81 else
82 str << ((mCounts.back()>0)? ", " : "") << "\"" << name << "\"" << ":" << value;
83
84 Update( str.str() );
85 mCounts.back() += 1;
86}
87
89 if( name.empty() )
90 Update( wxString::Format( "%s", (mCounts.back()>0)? ", " : ""));
91 else
92 Update( wxString::Format( "%s\"%s\":", (mCounts.back()>0) ?", ":"", name));
93 mCounts.back() += 1;
94 mCounts.push_back( 0 );
95}
96
98 if( mCounts.size() > 1 ){
99 mCounts.pop_back();
100 }
101}
102
104}
105
106wxString CommandMessageTarget::Escaped( const wxString & str){
107 wxString Temp = str;
108 Temp.Replace( "\"", "\\\"");
109 return Temp;
110}
111
113
115
117{
118 wxString Padding;
119 Padding.Pad( mCounts.size() *2 -2);
120 Update( wxString::Format( (mCounts.back()>0)?"\n%s(":"(", Padding ));
121 mCounts.back() += 1;
122 mCounts.push_back( 0 );
123}
124
126 if( mCounts.size() > 1 ){
127 mCounts.pop_back();
128 }
129 Update( ")" );
130}
132 wxString Padding;
133 Padding.Pad( mCounts.size() *2 -2);
134 Update( wxString::Format( (mCounts.back()>0)?"\n%s(":"(", Padding ));
135 mCounts.back() += 1;
136 mCounts.push_back( 0 );
137}
139 if( mCounts.size() > 1 ){
140 mCounts.pop_back();
141 }
142 Update( ")" );
143}
144void LispyCommandMessageTarget::AddItem(const wxString &value, const wxString &name){
145 wxString Padding;
146 if( name.empty() )
147 Update( wxString::Format( "%s%s\"%s\"", (mCounts.back()>0)?" ":"", Padding, Escaped(value)));
148 else
149 Update( wxString::Format( "%s%s(%s \"%s\")", (mCounts.back()>0)?" ":"", Padding, name, Escaped(value)));
150 mCounts.back() += 1;
151}
152void LispyCommandMessageTarget::AddBool(const bool value, const wxString &name){
153 if( name.empty() )
154 Update( wxString::Format( "%s%s", (mCounts.back()>0)?" ":"",value?"True":"False"));
155 else
156 Update( wxString::Format( "%s(%s %s)", (mCounts.back()>0)?" ":"", name,value?"True":"False"));
157 mCounts.back() += 1;
158}
159void LispyCommandMessageTarget::AddItem(const double value, const wxString &name){
160 if( name.empty() )
161 Update( wxString::Format( "%s%g", (mCounts.back()>0)?" ":"", value));
162 else
163 Update( wxString::Format( "%s(%s %g)", (mCounts.back()>0)?" ":"", name,value));
164 mCounts.back() += 1;
165}
166
168 Update( wxString::Format( "%s(%s", (mCounts.back()>0)?" ":"", name ));
169 mCounts.back() += 1;
170 mCounts.push_back( 0 );
171}
172
174 if( mCounts.size() > 1 ){
175 mCounts.pop_back();
176 }
177 Update( ")" );
178}
179
181
183{
184 wxString Padding;
185 Padding.Pad( mCounts.size() *2 -2);
186 if( mCounts.size() <= 3 )
187 Update( wxString::Format( "%s%s ", ( mCounts.back() > 0 ) ? " \n" : "", Padding ));
188 mCounts.back() += 1;
189 mCounts.push_back( 0 );
190}
191
193 if( mCounts.size() > 1 ){
194 mCounts.pop_back();
195 }
196 if( mCounts.size() <= 3 )
197 Update( " " );
198}
200 wxString Padding;
201 Padding.Pad( mCounts.size() *2 -2);
202 if( mCounts.size() <= 3 )
203 Update( wxString::Format( "%s%s ", ( mCounts.back() > 0 ) ? " \n" : "", Padding ));
204 mCounts.back() += 1;
205 mCounts.push_back( 0 );
206}
208 if( mCounts.size() > 1 ){
209 mCounts.pop_back();
210 }
211 if( mCounts.size() <= 3 )
212 Update( " " );
213}
214void BriefCommandMessageTarget::AddItem(const wxString &value, const wxString &WXUNUSED(name)){
215 if( mCounts.size() <= 3 )
216 Update( wxString::Format( "%s\"%s\"", (mCounts.back()>0)?" ":"",Escaped(value)));
217 mCounts.back() += 1;
218}
219void BriefCommandMessageTarget::AddBool(const bool value, const wxString &WXUNUSED(name)){
220 if( mCounts.size() <= 3 )
221 Update( wxString::Format( "%s%s", (mCounts.back()>0)?" ":"",value?"True":"False"));
222 mCounts.back() += 1;
223}
224void BriefCommandMessageTarget::AddItem(const double value, const wxString &WXUNUSED(name)){
225 if( mCounts.size() <= 3 )
226 Update( wxString::Format( "%s%g", (mCounts.back()>0)?" ":"", value));
227 mCounts.back() += 1;
228}
229
230void BriefCommandMessageTarget::StartField(const wxString &WXUNUSED(name)){
231 mCounts.back() += 1;
232 mCounts.push_back( 0 );
233}
234
236 if( mCounts.size() > 1 ){
237 mCounts.pop_back();
238 }
239}
240
242
244
246
248
249void MessageBoxTarget::Update(const wxString &message)
250{
251 // Should these messages be localized?
253}
254
256
258
261 pToRestore( &target )
262{
263 mProgressTarget = std::move(target.mProgressTarget),
264 mStatusTarget = std::make_shared<LispyCommandMessageTarget>( *target.mStatusTarget.get() ),
265 mErrorTarget = std::move( target.mErrorTarget );
266}
267
269{
271 //The status was never captured so does not need restoring.
272 //pToRestore->mStatusTarget = std::move( mStatusTarget );
273 pToRestore->mErrorTarget = std::move( mErrorTarget );
274}
275
278 pToRestore( &target )
279{
280 mProgressTarget = std::move(target.mProgressTarget),
281 mStatusTarget = std::make_shared<BriefCommandMessageTarget>( *target.mStatusTarget.get() ),
282 mErrorTarget = std::move( target.mErrorTarget );
283}
284
286{
288 //The status was never captured so does not need restoring.
289 //pToRestore->mStatusTarget = std::move( mStatusTarget );
290 pToRestore->mErrorTarget = std::move( mErrorTarget );
291}
Toolkit-neutral facade for basic user interface services.
#define str(a)
wxString name
Definition: TagsEditor.cpp:166
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
virtual void StartStruct() override
virtual void EndArray() override
virtual void EndStruct() override
virtual void AddBool(const bool value, const wxString &name={}) override
virtual void StartField(const wxString &name={}) override
virtual void EndField() override
virtual void AddItem(const wxString &value, const wxString &name={}) override
~BriefCommandMessageTarget() override
virtual void StartArray() override
CommandOutputTargets * pToRestore
BriefCommandOutputTargets(CommandOutputTargets &target)
~CombinedMessageTarget() override
~CommandMessageTargetDecorator() override
void Update(const wxString &message) override
virtual void AddBool(const bool value, const wxString &name={})
std::vector< int > mCounts
virtual void AddItem(const wxString &value, const wxString &name={})
virtual void Update(const wxString &message)=0
virtual void StartField(const wxString &name={})
virtual void EndArray()
virtual ~CommandMessageTarget()
virtual void EndField()
virtual void StartStruct()
wxString Escaped(const wxString &str)
virtual void EndStruct()
virtual void StartArray()
CommandOutputTargets a mix of three output classes to output progress indication, status messages and...
std::shared_ptr< CommandMessageTarget > mStatusTarget
std::unique_ptr< CommandProgressTarget > mProgressTarget
std::shared_ptr< CommandMessageTarget > mErrorTarget
virtual ~CommandProgressTarget()
CommandOutputTargets * pToRestore
LispifiedCommandOutputTargets(CommandOutputTargets &target)
virtual void StartStruct() override
virtual void StartField(const wxString &name={}) override
virtual void EndArray() override
~LispyCommandMessageTarget() override
virtual void AddBool(const bool value, const wxString &name={}) override
virtual void EndField() override
virtual void EndStruct() override
virtual void StartArray() override
virtual void AddItem(const wxString &value, const wxString &name={}) override
void Update(const wxString &message) override
~MessageBoxTarget() override
~NullMessageTarget() override
~NullProgressTarget() override
~ProgressToMessageTarget() override
~ResponseTarget() override
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:287