Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ProjectManager::ProjectChooser Class Reference

Callable object that supplies the chooser argument of ProjectFileManager::OpenFile. More...

#include <ProjectManager.h>

Collaboration diagram for ProjectManager::ProjectChooser:
[legend]

Public Member Functions

 ProjectChooser (AudacityProject *pProject, bool reuseNonemptyProject)
 
 ProjectChooser (const ProjectChooser &)=delete
 Don't copy. Use std::ref to pass it to ProjectFileManager. More...
 
 ~ProjectChooser ()
 Destroy any fresh project, or rollback the existing project, unless committed. More...
 
AudacityProjectoperator() (bool openingProjectFile)
 May create a fresh project. More...
 
void Commit ()
 Commit the creation of any fresh project or changes to the existing project. More...
 

Private Attributes

AudacityProjectmpGivenProject
 
AudacityProjectmpUsedProject = nullptr
 
bool mReuseNonemptyProject
 

Detailed Description

Callable object that supplies the chooser argument of ProjectFileManager::OpenFile.

Its operator(), called lower down in ProjectFileManager, decides which project to put new file data into, using file type information deduced there. It may have the side effect of creating a project.

At the higher level where it is constructed, it provides conditional RAII. One indicates there that the file opening succeeded by calling Commit(). But if that is never called, creation of projects, or changes to a preexisting project, are undone.

Definition at line 65 of file ProjectManager.h.

Constructor & Destructor Documentation

◆ ProjectChooser() [1/2]

ProjectManager::ProjectChooser::ProjectChooser ( AudacityProject pProject,
bool  reuseNonemptyProject 
)
inline
Parameters
pProjectif not null, an existing project to reuse if possible
reuseNonemptyProjectif true, may reuse the given project when nonempty, but only if importing (not for a project file)

Definition at line 72 of file ProjectManager.h.

73 : mpGivenProject{ pProject }
74 , mReuseNonemptyProject{ reuseNonemptyProject }
75 {}
AudacityProject * mpGivenProject

◆ ProjectChooser() [2/2]

ProjectManager::ProjectChooser::ProjectChooser ( const ProjectChooser )
delete

Don't copy. Use std::ref to pass it to ProjectFileManager.

◆ ~ProjectChooser()

ProjectManager::ProjectChooser::~ProjectChooser ( )

Destroy any fresh project, or rollback the existing project, unless committed.

Definition at line 675 of file ProjectManager.cpp.

676{
677 if (mpUsedProject) {
679 // Ensure that it happens here: don't wait for the application level
680 // exception handler, because the exception may be intercepted
681 ProjectHistory::Get(*mpGivenProject).RollbackState();
682 // Any exception now continues propagating
683 }
684 else
685 GetProjectFrame( *mpUsedProject ).Close(true);
686 }
687}
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 ...
static ProjectHistory & Get(AudacityProject &project)
AudacityProject * mpUsedProject

References ProjectHistory::Get(), GetProjectFrame(), mpGivenProject, mpUsedProject, and ProjectHistory::RollbackState().

Here is the call graph for this function:

Member Function Documentation

◆ Commit()

void ProjectManager::ProjectChooser::Commit ( )

Commit the creation of any fresh project or changes to the existing project.

Definition at line 704 of file ProjectManager.cpp.

705{
706 mpUsedProject = nullptr;
707}

◆ operator()()

AudacityProject & ProjectManager::ProjectChooser::operator() ( bool  openingProjectFile)

May create a fresh project.

Definition at line 690 of file ProjectManager.cpp.

691{
692 if (mpGivenProject) {
693 // Always check before opening a project file (for safety);
694 // May check even when opening other files
695 // (to preserve old behavior; as with the File > Open command specifying
696 // multiple files of whatever types, so that each gets its own window)
697 bool checkReuse = (openingProjectFile || !mReuseNonemptyProject);
698 if (!checkReuse || SafeToOpenProjectInto(*mpGivenProject))
699 return *(mpUsedProject = mpGivenProject);
700 }
701 return *(mpUsedProject = New());
702}
static AudacityProject * New()
static bool SafeToOpenProjectInto(AudacityProject &proj)
False when it is unsafe to overwrite proj with contents of an .aup3 file.

References ProjectManager::New(), and ProjectManager::SafeToOpenProjectInto().

Here is the call graph for this function:

Member Data Documentation

◆ mpGivenProject

AudacityProject* ProjectManager::ProjectChooser::mpGivenProject
private

Definition at line 86 of file ProjectManager.h.

Referenced by ~ProjectChooser().

◆ mpUsedProject

AudacityProject* ProjectManager::ProjectChooser::mpUsedProject = nullptr
private

Definition at line 87 of file ProjectManager.h.

Referenced by ~ProjectChooser().

◆ mReuseNonemptyProject

bool ProjectManager::ProjectChooser::mReuseNonemptyProject
private

Definition at line 88 of file ProjectManager.h.


The documentation for this class was generated from the following files: