Audacity 3.2.0
Public Member Functions | List of all members
FileActions::Handler Struct Reference
Inheritance diagram for FileActions::Handler:
[legend]
Collaboration diagram for FileActions::Handler:
[legend]

Public Member Functions

void OnNew (const CommandContext &)
 
void OnOpen (const CommandContext &context)
 
void OnProjectReset (const CommandContext &context)
 
void OnClose (const CommandContext &context)
 
void OnCompact (const CommandContext &context)
 
void OnSave (const CommandContext &context)
 
void OnSaveAs (const CommandContext &context)
 
void OnSaveCopy (const CommandContext &context)
 
void OnExportMp3 (const CommandContext &context)
 
void OnExportWav (const CommandContext &context)
 
void OnExportOgg (const CommandContext &context)
 
void OnExportAudio (const CommandContext &context)
 
void OnExportSelection (const CommandContext &context)
 
void OnExportLabels (const CommandContext &context)
 
void OnExportMultiple (const CommandContext &context)
 
void OnExportMIDI (const CommandContext &context)
 
void OnImport (const CommandContext &context)
 
void OnImportLabels (const CommandContext &context)
 
void OnImportMIDI (const CommandContext &context)
 
void OnImportRaw (const CommandContext &context)
 
void OnPageSetup (const CommandContext &context)
 
void OnPrint (const CommandContext &context)
 
void OnExit (const CommandContext &WXUNUSED(context))
 
void OnExportFLAC (const CommandContext &context)
 

Detailed Description

Definition at line 176 of file FileMenus.cpp.

Member Function Documentation

◆ OnClose()

void FileActions::Handler::OnClose ( const CommandContext context)
inline

Definition at line 200 of file FileMenus.cpp.

201{
202 auto &project = context.project;
203 auto &window = ProjectWindow::Get( project );
204 ProjectFileManager::Get( project ).SetMenuClose(true);
205 window.Close();
206}
AudacityProject & project
static ProjectFileManager & Get(AudacityProject &project)
void SetMenuClose(bool value)
static ProjectWindow & Get(AudacityProject &project)

References ProjectFileManager::Get(), ProjectWindow::Get(), CommandContext::project, and ProjectFileManager::SetMenuClose().

Here is the call graph for this function:

◆ OnCompact()

void FileActions::Handler::OnCompact ( const CommandContext context)
inline

Definition at line 208 of file FileMenus.cpp.

References ProjectFileManager::Compact(), ProjectFileManager::Get(), and CommandContext::project.

Here is the call graph for this function:

◆ OnExit()

void FileActions::Handler::OnExit ( const CommandContext WXUNUSEDcontext)
inline

Definition at line 527 of file FileMenus.cpp.

528{
529 // Simulate the application Exit menu item
530 wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT };
531 wxTheApp->ProcessEvent( evt );
532}

◆ OnExportAudio()

void FileActions::Handler::OnExportAudio ( const CommandContext context)
inline

Definition at line 252 of file FileMenus.cpp.

253{
254 auto &project = context.project;
255 DoExport(project, "");
256}
void DoExport(AudacityProject &project, const FileExtension &format)
Definition: FileMenus.cpp:43

References anonymous_namespace{FileMenus.cpp}::DoExport(), and CommandContext::project.

Here is the call graph for this function:

◆ OnExportFLAC()

void FileActions::Handler::OnExportFLAC ( const CommandContext context)
inline

Definition at line 534 of file FileMenus.cpp.

535{
536 DoExport(context.project, "FLAC");
537}

References anonymous_namespace{FileMenus.cpp}::DoExport(), and CommandContext::project.

Here is the call graph for this function:

◆ OnExportLabels()

void FileActions::Handler::OnExportLabels ( const CommandContext context)
inline

Definition at line 269 of file FileMenus.cpp.

270{
271 auto &project = context.project;
272 auto &tracks = TrackList::Get( project );
273 auto &window = GetProjectFrame( project );
274
275 /* i18n-hint: filename containing exported text from label tracks */
276 wxString fName = _("labels.txt");
277 auto trackRange = tracks.Any<const LabelTrack>();
278 auto numLabelTracks = trackRange.size();
279
280 if (numLabelTracks == 0) {
281 AudacityMessageBox( XO("There are no label tracks to export.") );
282 return;
283 }
284 else
285 fName = (*trackRange.rbegin())->GetName();
286
287 fName = SelectFile(FileNames::Operation::Export,
288 XO("Export Labels As:"),
289 wxEmptyString,
290 fName,
291 wxT("txt"),
293 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
294 &window);
295
296 if (fName.empty())
297 return;
298
299 // Move existing files out of the way. Otherwise wxTextFile will
300 // append to (rather than replace) the current file.
301
302 if (wxFileExists(fName)) {
303#ifdef __WXGTK__
304 wxString safetyFileName = fName + wxT("~");
305#else
306 wxString safetyFileName = fName + wxT(".bak");
307#endif
308
309 if (wxFileExists(safetyFileName))
310 wxRemoveFile(safetyFileName);
311
312 wxRename(fName, safetyFileName);
313 }
314
315 wxTextFile f(fName);
316 f.Create();
317 f.Open();
318 if (!f.IsOpened()) {
320 XO( "Couldn't write to file: %s" ).Format( fName ) );
321 return;
322 }
323
324 for (auto lt : trackRange)
325 lt->Export(f);
326
327 f.Write();
328 f.Close();
329}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:251
FILES_API const FileType TextFiles
Definition: FileNames.h:74
Abstract base class used in importing a file.
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486

References _, AudacityMessageBox(), TrackList::Get(), GetProjectFrame(), CommandContext::project, SelectFile(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), FileNames::TextFiles, wxT(), and XO.

Here is the call graph for this function:

◆ OnExportMIDI()

void FileActions::Handler::OnExportMIDI ( const CommandContext context)
inline

Definition at line 340 of file FileMenus.cpp.

341{
342 auto &project = context.project;
343 auto &tracks = TrackList::Get( project );
344 auto &window = GetProjectFrame( project );
345
346 // Make sure that there is
347 // exactly one NoteTrack selected.
348 const auto range = tracks.Selected< const NoteTrack >();
349 const auto numNoteTracksSelected = range.size();
350
351 if(numNoteTracksSelected > 1) {
353 XO("Please select only one Note Track at a time.") );
354 return;
355 }
356 else if(numNoteTracksSelected < 1) {
358 XO("Please select a Note Track.") );
359 return;
360 }
361
362 wxASSERT(numNoteTracksSelected);
363 if (!numNoteTracksSelected)
364 return;
365
366 const auto nt = *range.begin();
367
368 while(true) {
369
370 wxString fName;
371
372 fName = SelectFile(FileNames::Operation::Export,
373 XO("Export MIDI As:"),
374 wxEmptyString,
375 fName,
376 wxT("mid"),
377 {
378 { XO("MIDI file"), { wxT("mid") }, true },
379 { XO("Allegro file"), { wxT("gro") }, true },
380 },
381 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
382 &window);
383
384 if (fName.empty())
385 return;
386
387 if(!fName.Contains(wxT("."))) {
388 fName = fName + wxT(".mid");
389 }
390
391 // Move existing files out of the way. Otherwise wxTextFile will
392 // append to (rather than replace) the current file.
393
394 if (wxFileExists(fName)) {
395#ifdef __WXGTK__
396 wxString safetyFileName = fName + wxT("~");
397#else
398 wxString safetyFileName = fName + wxT(".bak");
399#endif
400
401 if (wxFileExists(safetyFileName))
402 wxRemoveFile(safetyFileName);
403
404 wxRename(fName, safetyFileName);
405 }
406
407 if(fName.EndsWith(wxT(".mid")) || fName.EndsWith(wxT(".midi"))) {
408 nt->ExportMIDI(fName);
409 } else if(fName.EndsWith(wxT(".gro"))) {
410 nt->ExportAllegro(fName);
411 } else {
412 auto msg = XO(
413"You have selected a filename with an unrecognized file extension.\nDo you want to continue?");
414 auto title = XO("Export MIDI");
415 int id = AudacityMessageBox( msg, title, wxYES_NO );
416 if (id == wxNO) {
417 continue;
418 } else if (id == wxYES) {
419 nt->ExportMIDI(fName);
420 }
421 }
422 break;
423 }
424}
static const auto title
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:63

References AudacityMessageBox(), TrackList::Get(), GetProjectFrame(), CommandContext::project, SelectFile(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), title, wxT(), and XO.

Here is the call graph for this function:

◆ OnExportMp3()

void FileActions::Handler::OnExportMp3 ( const CommandContext context)
inline

Definition at line 234 of file FileMenus.cpp.

235{
236 auto &project = context.project;
237 DoExport(project, "MP3");
238}

References anonymous_namespace{FileMenus.cpp}::DoExport(), and CommandContext::project.

Here is the call graph for this function:

◆ OnExportMultiple()

void FileActions::Handler::OnExportMultiple ( const CommandContext context)
inline

Definition at line 331 of file FileMenus.cpp.

332{
333 auto &project = context.project;
334 ExportMultipleDialog em(&project);
335
336 em.ShowModal();
337}
Presents a dialog box allowing the user to export multiple files either by exporting each track as a ...

References CommandContext::project, and ExportMultipleDialog::ShowModal().

Here is the call graph for this function:

◆ OnExportOgg()

void FileActions::Handler::OnExportOgg ( const CommandContext context)
inline

Definition at line 246 of file FileMenus.cpp.

247{
248 auto &project = context.project;
249 DoExport(project, "OGG");
250}

References anonymous_namespace{FileMenus.cpp}::DoExport(), and CommandContext::project.

Here is the call graph for this function:

◆ OnExportSelection()

void FileActions::Handler::OnExportSelection ( const CommandContext context)
inline

Definition at line 258 of file FileMenus.cpp.

259{
260 auto &project = context.project;
261 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
262 Exporter e{ project };
263
264 e.SetFileDialogTitle( XO("Export Selected Audio") );
265 e.Process(true, selectedRegion.t0(),
266 selectedRegion.t1());
267}
void SetFileDialogTitle(const TranslatableString &DialogTitle)
Definition: Export.cpp:380
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References ViewInfo::Get(), CommandContext::project, ViewInfo::selectedRegion, Exporter::SetFileDialogTitle(), and XO.

Here is the call graph for this function:

◆ OnExportWav()

void FileActions::Handler::OnExportWav ( const CommandContext context)
inline

Definition at line 240 of file FileMenus.cpp.

241{
242 auto &project = context.project;
243 DoExport(project, "WAV");
244}

References anonymous_namespace{FileMenus.cpp}::DoExport(), and CommandContext::project.

Here is the call graph for this function:

◆ OnImport()

void FileActions::Handler::OnImport ( const CommandContext context)
inline

Definition at line 427 of file FileMenus.cpp.

428{
429 DoImport(context, false);
430}
void DoImport(const CommandContext &context, bool isRaw)
Definition: FileMenus.cpp:123

References anonymous_namespace{FileMenus.cpp}::DoImport().

Here is the call graph for this function:

◆ OnImportLabels()

void FileActions::Handler::OnImportLabels ( const CommandContext context)
inline

Definition at line 432 of file FileMenus.cpp.

433{
434 auto &project = context.project;
435 auto &trackFactory = WaveTrackFactory::Get( project );
436 auto &tracks = TrackList::Get( project );
437 auto &window = ProjectWindow::Get( project );
438
439 wxString fileName =
440 SelectFile(FileNames::Operation::Open,
441 XO("Select a text file containing labels"),
442 wxEmptyString, // Path
443 wxT(""), // Name
444 wxT("txt"), // Extension
446 wxRESIZE_BORDER, // Flags
447 &window); // Parent
448
449 if (!fileName.empty()) {
450 wxTextFile f;
451
452 f.Open(fileName);
453 if (!f.IsOpened()) {
455 XO("Could not open file: %s").Format( fileName ) );
456 return;
457 }
458
459 auto newTrack = std::make_shared<LabelTrack>();
460 wxString sTrackName;
461 wxFileName::SplitPath(fileName, NULL, NULL, &sTrackName, NULL);
462 newTrack->SetName(sTrackName);
463
464 newTrack->Import(f);
465
467 newTrack->SetSelected(true);
468 tracks.Add( newTrack );
469
471 XO("Imported labels from '%s'").Format( fileName ),
472 XO("Import Labels"));
473
474 window.ZoomAfterImport(nullptr);
475 }
476}
FILES_API const FileType AllFiles
Definition: FileNames.h:71
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2810
void SelectNone(AudacityProject &project)

References FileNames::AllFiles, AudacityMessageBox(), ProjectHistory::Get(), TrackList::Get(), ProjectWindow::Get(), WaveTrackFactory::Get(), CommandContext::project, ProjectHistory::PushState(), SelectFile(), SelectUtilities::SelectNone(), FileNames::TextFiles, wxT(), and XO.

Here is the call graph for this function:

◆ OnImportMIDI()

void FileActions::Handler::OnImportMIDI ( const CommandContext context)
inline

Definition at line 479 of file FileMenus.cpp.

480{
481 auto &project = context.project;
482 auto &window = GetProjectFrame( project );
483
484 wxString fileName = SelectFile(FileNames::Operation::Open,
485 XO("Select a MIDI file"),
486 wxEmptyString, // Path
487 wxT(""), // Name
488 wxT(""), // Extension
489 {
490 { XO("MIDI and Allegro files"),
491 { wxT("mid"), wxT("midi"), wxT("gro"), }, true },
492 { XO("MIDI files"),
493 { wxT("mid"), wxT("midi"), }, true },
494 { XO("Allegro files"),
495 { wxT("gro"), }, true },
497 },
498 wxRESIZE_BORDER, // Flags
499 &window); // Parent
500
501 if (!fileName.empty())
502 DoImportMIDI(project, fileName);
503}
bool DoImportMIDI(AudacityProject &project, const FilePath &fileName)
Definition: ImportMIDI.cpp:37

References FileNames::AllFiles, DoImportMIDI(), GetProjectFrame(), CommandContext::project, SelectFile(), wxT(), and XO.

Here is the call graph for this function:

◆ OnImportRaw()

void FileActions::Handler::OnImportRaw ( const CommandContext context)
inline

Definition at line 506 of file FileMenus.cpp.

507{
508 DoImport(context, true);
509}

References anonymous_namespace{FileMenus.cpp}::DoImport().

Here is the call graph for this function:

◆ OnNew()

void FileActions::Handler::OnNew ( const CommandContext )
inline

Definition at line 178 of file FileMenus.cpp.

179{
180 ( void ) ProjectManager::New();
181}
static AudacityProject * New()

References ProjectManager::New().

Here is the call graph for this function:

◆ OnOpen()

void FileActions::Handler::OnOpen ( const CommandContext context)
inline

Definition at line 183 of file FileMenus.cpp.

184{
185 auto &project = context.project;
187}
static void OpenFiles(AudacityProject *proj)

References ProjectManager::OpenFiles(), and CommandContext::project.

Here is the call graph for this function:

◆ OnPageSetup()

void FileActions::Handler::OnPageSetup ( const CommandContext context)
inline

Definition at line 511 of file FileMenus.cpp.

512{
513 auto &project = context.project;
514 auto &window = GetProjectFrame( project );
515 HandlePageSetup(&window);
516}
void HandlePageSetup(wxWindow *parent)
Definition: Printing.cpp:161

References GetProjectFrame(), HandlePageSetup(), and CommandContext::project.

Here is the call graph for this function:

◆ OnPrint()

void FileActions::Handler::OnPrint ( const CommandContext context)
inline

Definition at line 518 of file FileMenus.cpp.

519{
520 auto &project = context.project;
521 auto name = project.GetProjectName();
522 auto &tracks = TrackList::Get( project );
523 auto &window = GetProjectFrame( project );
524 HandlePrint(&window, name, &tracks, TrackPanel::Get( project ));
525}
const TranslatableString name
Definition: Distortion.cpp:82
void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks, TrackPanel &panel)
Definition: Printing.cpp:171
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230

References TrackList::Get(), TrackPanel::Get(), GetProjectFrame(), HandlePrint(), name, and CommandContext::project.

Here is the call graph for this function:

◆ OnProjectReset()

void FileActions::Handler::OnProjectReset ( const CommandContext context)
inline

Definition at line 194 of file FileMenus.cpp.

195{
196 auto &project = context.project;
198}
static ProjectManager & Get(AudacityProject &project)
void ResetProjectToEmpty()

References ProjectManager::Get(), CommandContext::project, and ProjectManager::ResetProjectToEmpty().

Here is the call graph for this function:

◆ OnSave()

void FileActions::Handler::OnSave ( const CommandContext context)
inline

Definition at line 213 of file FileMenus.cpp.

214{
215 auto &project = context.project;
216 auto &projectFileManager = ProjectFileManager::Get( project );
217 projectFileManager.Save();
218}

References ProjectFileManager::Get(), and CommandContext::project.

Here is the call graph for this function:

◆ OnSaveAs()

void FileActions::Handler::OnSaveAs ( const CommandContext context)
inline

Definition at line 220 of file FileMenus.cpp.

221{
222 auto &project = context.project;
223 auto &projectFileManager = ProjectFileManager::Get( project );
224 projectFileManager.SaveAs();
225}

References ProjectFileManager::Get(), and CommandContext::project.

Here is the call graph for this function:

◆ OnSaveCopy()

void FileActions::Handler::OnSaveCopy ( const CommandContext context)
inline

Definition at line 227 of file FileMenus.cpp.

228{
229 auto &project = context.project;
230 auto &projectFileManager = ProjectFileManager::Get( project );
231 projectFileManager.SaveCopy();
232}

References ProjectFileManager::Get(), and CommandContext::project.

Here is the call graph for this function:

The documentation for this struct was generated from the following file: