MCPcopy Create free account
hub / github.com/audacity/audacity / WriteMacro

Method WriteMacro

src/BatchCommands.cpp:208–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208wxString MacroCommands::WriteMacro(const wxString & macro, wxWindow *parent)
209{
210 // Build the default filename
211 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
212
213 // But, ask the user for the real name if we're exporting
214 if (parent) {
215 FilePath fn = SelectFile(FileNames::Operation::_None,
216 XO("Export Macro"),
217 wxEmptyString,
218 name.GetName(),
219 wxT("txt"),
220 { FileNames::TextFiles },
221 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
222 parent);
223
224 // User canceled...
225 if (fn.empty()) {
226 return wxEmptyString;
227 }
228
229 name.Assign(fn);
230 }
231
232 // Set the file name
233 wxTextFile tf(name.GetFullPath());
234
235 // Create the file (Create() doesn't leave the file open)
236 if (!tf.Exists()) {
237 tf.Create();
238 }
239
240 // Open it
241 tf.Open();
242
243 if (!tf.IsOpened()) {
244 // wxTextFile will display any errors
245 return wxEmptyString;
246 }
247
248 // Start with a clean slate
249 tf.Clear();
250
251 // Copy over the commands
252 int lines = mCommandMacro.size();
253 for (int i = 0; i < lines; i++) {
254 // using GET to serialize macro definition to a text file
255 tf.AddLine(mCommandMacro[i].GET() + wxT(":") + mParamsMacro[ i ]);
256 }
257
258 // Write the macro
259 tf.Write();
260
261 // Done with the file
262 tf.Close();
263
264 return name.GetName();
265}

Callers 3

ChangeOKMethod · 0.80
OnExportMethod · 0.80
SaveChangesMethod · 0.80

Calls 12

SelectFileFunction · 0.85
ExistsMethod · 0.80
IsOpenedMethod · 0.80
GetNameMethod · 0.45
emptyMethod · 0.45
AssignMethod · 0.45
CreateMethod · 0.45
OpenMethod · 0.45
ClearMethod · 0.45
sizeMethod · 0.45
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected