From a1650771b1bd100cf7a8a1b59cf45659fb00d1f5 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 19 May 2021 13:14:28 -0400 Subject: [PATCH] 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. --- src/AudacityApp.cpp | 3 ++- src/AutoRecoveryDialog.cpp | 2 +- src/ProjectManager.cpp | 6 ++++-- src/ProjectManager.h | 14 ++++++++++---- src/import/ImportLOF.cpp | 3 ++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 8236d12cf..66220b96d 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -815,7 +815,8 @@ bool AudacityApp::MRUOpen(const FilePath &fullPathStr) { if (proj && !ProjectManager::SafeToOpenProjectInto(*proj)) proj = nullptr; - ( void ) ProjectManager::OpenProject( proj, fullPathStr ); + ( void ) ProjectManager::OpenProject( proj, fullPathStr, + true /* addtohistory */, false /* reuseNonemptyProject */ ); } else { // File doesn't exist - remove file from history diff --git a/src/AutoRecoveryDialog.cpp b/src/AutoRecoveryDialog.cpp index b09a591ef..ba9683c6c 100644 --- a/src/AutoRecoveryDialog.cpp +++ b/src/AutoRecoveryDialog.cpp @@ -430,7 +430,7 @@ static bool RecoverAllProjects(const FilePaths &files, std::swap(proj, pproj); // Open project. - if (ProjectManager::OpenProject(proj, file, false) == nullptr) + if (ProjectManager::OpenProject(proj, file, false, true) == nullptr) { return false; } diff --git a/src/ProjectManager.cpp b/src/ProjectManager.cpp index d5b5a4c17..07e9a4317 100644 --- a/src/ProjectManager.cpp +++ b/src/ProjectManager.cpp @@ -873,7 +873,8 @@ void ProjectManager::OpenFiles(AudacityProject *proj) if (proj && !SafeToOpenProjectInto(*proj)) 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 *pProject, const FilePath &fileNameArg, bool addtohistory) + AudacityProject *pProject, const FilePath &fileNameArg, + bool addtohistory, bool) { bool success = false; AudacityProject *pNewProject = nullptr; diff --git a/src/ProjectManager.h b/src/ProjectManager.h index f635f4388..22d800ed2 100644 --- a/src/ProjectManager.h +++ b/src/ProjectManager.h @@ -48,12 +48,18 @@ public: //! False when it is unsafe to overwrite proj with contents of an .aup3 file static bool SafeToOpenProjectInto(AudacityProject &proj); - // Return the given project if that is not NULL, else create a project. - // Then open the given project path. - // But if an exception escapes this function, create no NEW project. + //! Open a file into an AudacityProject, returning the project, or nullptr for failure + /*! + 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( AudacityProject *pProject, - const FilePath &fileNameArg, bool addtohistory = true); + const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject); void ResetProjectToEmpty(); diff --git a/src/import/ImportLOF.cpp b/src/import/ImportLOF.cpp index f0909d0da..a9ca369bc 100644 --- a/src/import/ImportLOF.cpp +++ b/src/import/ImportLOF.cpp @@ -410,7 +410,8 @@ void LOFImportFileHandle::lofOpenFiles(wxString* ln) * audio file. TODO: Some sort of message here? */ #endif // USE_MIDI - mProject = ProjectManager::OpenProject( mProject, targetfile ); + mProject = ProjectManager::OpenProject( mProject, targetfile, + true /* addtohistory */, true /* reuseNonemptyProject */ ); // Set tok to right after filename temptok2.SetString(targettoken);