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 674 of file ProjectManager.cpp.

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

704{
705 mpUsedProject = nullptr;
706}

◆ operator()()

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

May create a fresh project.

Definition at line 689 of file ProjectManager.cpp.

690{
691 if (mpGivenProject) {
692 // Always check before opening a project file (for safety);
693 // May check even when opening other files
694 // (to preserve old behavior; as with the File > Open command specifying
695 // multiple files of whatever types, so that each gets its own window)
696 bool checkReuse = (openingProjectFile || !mReuseNonemptyProject);
697 if (!checkReuse || SafeToOpenProjectInto(*mpGivenProject))
698 return *(mpUsedProject = mpGivenProject);
699 }
700 return *(mpUsedProject = New());
701}
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: