1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

New argument for ProjectManager::OpenProject, not yet implemented...

... It is false in exactly the cases where there is now also a check first for
the safety of opening a project file.

Those are the cases where a new project was made for imports, but this was not
necessary for safety.  Yet old behavior will be preserved in such cases.
This commit is contained in:
Paul Licameli 2021-05-19 13:14:28 -04:00
parent 97cf411dd5
commit a1650771b1
5 changed files with 19 additions and 9 deletions

View File

@ -815,7 +815,8 @@ bool AudacityApp::MRUOpen(const FilePath &fullPathStr) {
if (proj && !ProjectManager::SafeToOpenProjectInto(*proj)) if (proj && !ProjectManager::SafeToOpenProjectInto(*proj))
proj = nullptr; proj = nullptr;
( void ) ProjectManager::OpenProject( proj, fullPathStr ); ( void ) ProjectManager::OpenProject( proj, fullPathStr,
true /* addtohistory */, false /* reuseNonemptyProject */ );
} }
else { else {
// File doesn't exist - remove file from history // File doesn't exist - remove file from history

View File

@ -430,7 +430,7 @@ static bool RecoverAllProjects(const FilePaths &files,
std::swap(proj, pproj); std::swap(proj, pproj);
// Open project. // Open project.
if (ProjectManager::OpenProject(proj, file, false) == nullptr) if (ProjectManager::OpenProject(proj, file, false, true) == nullptr)
{ {
return false; return false;
} }

View File

@ -873,7 +873,8 @@ void ProjectManager::OpenFiles(AudacityProject *proj)
if (proj && !SafeToOpenProjectInto(*proj)) if (proj && !SafeToOpenProjectInto(*proj))
proj = nullptr; proj = nullptr;
proj = OpenProject( proj, fileName ); proj = OpenProject( proj, fileName,
true /* addtohistory */, false /* reuseNonemptyProject */ );
} }
} }
@ -901,7 +902,8 @@ bool ProjectManager::SafeToOpenProjectInto(AudacityProject &proj)
} }
AudacityProject *ProjectManager::OpenProject( AudacityProject *ProjectManager::OpenProject(
AudacityProject *pProject, const FilePath &fileNameArg, bool addtohistory) AudacityProject *pProject, const FilePath &fileNameArg,
bool addtohistory, bool)
{ {
bool success = false; bool success = false;
AudacityProject *pNewProject = nullptr; AudacityProject *pNewProject = nullptr;

View File

@ -48,12 +48,18 @@ public:
//! False when it is unsafe to overwrite proj with contents of an .aup3 file //! False when it is unsafe to overwrite proj with contents of an .aup3 file
static bool SafeToOpenProjectInto(AudacityProject &proj); static bool SafeToOpenProjectInto(AudacityProject &proj);
// Return the given project if that is not NULL, else create a project. //! Open a file into an AudacityProject, returning the project, or nullptr for failure
// Then open the given project path. /*!
// But if an exception escapes this function, create no NEW project. If an exception escapes this function, no projects are created.
@param pProject if not null, a project that may be reused
@param fileNameArg path to the file to open; not always an Audacity project file, may be an import
@param addtohistory whether to add .aup3 files to the MRU list (but always done for imports)
@param reuseNonemptyProject if true, may reuse the given project when nonempty,
but only if importing (not for a project file)
*/
static AudacityProject *OpenProject( static AudacityProject *OpenProject(
AudacityProject *pProject, AudacityProject *pProject,
const FilePath &fileNameArg, bool addtohistory = true); const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject);
void ResetProjectToEmpty(); void ResetProjectToEmpty();

View File

@ -410,7 +410,8 @@ void LOFImportFileHandle::lofOpenFiles(wxString* ln)
* audio file. TODO: Some sort of message here? */ * audio file. TODO: Some sort of message here? */
#endif // USE_MIDI #endif // USE_MIDI
mProject = ProjectManager::OpenProject( mProject, targetfile ); mProject = ProjectManager::OpenProject( mProject, targetfile,
true /* addtohistory */, true /* reuseNonemptyProject */ );
// Set tok to right after filename // Set tok to right after filename
temptok2.SetString(targettoken); temptok2.SetString(targettoken);