From d4b0fd1b834b466ca9684feab029ee6bdf2d0884 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 25 Apr 2019 23:59:42 -0400 Subject: [PATCH] AudacityProject.cpp does not need gIsQuitting from AudacityApp.h --- src/AudacityApp.cpp | 41 ++++++++++++----------------------------- src/AudacityApp.h | 2 -- src/Project.cpp | 27 +++++++++++++++++++++++++-- src/Project.h | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index a720aa12f..ad03061ae 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -264,10 +264,11 @@ static void wxOnAssert(const wxChar *fileName, int lineNumber, const wxChar *msg #endif static bool gInited = false; -bool gIsQuitting = false; +static bool gIsQuitting = false; void QuitAudacity(bool bForce) { + // guard against recursion if (gIsQuitting) return; @@ -292,22 +293,11 @@ void QuitAudacity(bool bForce) /*end+*/ { SaveWindowSize(); - while (gAudacityProjects.size()) + bool closedAll = AllProjects::Close( bForce ); + if ( !closedAll ) { - // Closing the project has global side-effect - // of deletion from gAudacityProjects - if (bForce) - { - gAudacityProjects[0]->Close(true); - } - else - { - if (!gAudacityProjects[0]->Close()) - { - gIsQuitting = false; - return; - } - } + gIsQuitting = false; + return; } } @@ -1949,19 +1939,12 @@ void AudacityApp::OnEndSession(wxCloseEvent & event) // Try to close each open window. If the user hits Cancel // in a Save Changes dialog, don't continue. - if (!gAudacityProjects.empty()) { - while (gAudacityProjects.size()) { - // Closing the project has side-effect of - // deletion from gAudacityProjects - if (force) { - gAudacityProjects[0]->Close(true); - } - else if (!gAudacityProjects[0]->Close()) { - gIsQuitting = false; - event.Veto(); - break; - } - } + gIsQuitting = true; + bool closedAll = AllProjects::Close( force ); + if ( !closedAll ) + { + gIsQuitting = false; + event.Veto(); } } diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 148954602..3e2ac916a 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -44,8 +44,6 @@ void SaveWindowSize(); void QuitAudacity(bool bForce); void QuitAudacity(); -extern bool gIsQuitting; - class AliasBlockFile; class AudacityApp final : public wxApp { diff --git a/src/Project.cpp b/src/Project.cpp index 2e9833a48..1b72c01b8 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -173,6 +173,28 @@ scroll information. It also has some status flags. #include "widgets/WindowAccessible.h" #endif +bool AllProjects::sbClosing = false; + +bool AllProjects::Close( bool force ) +{ + ValueRestorer cleanup{ sbClosing, true }; + while (gAudacityProjects.size()) + { + // Closing the project has global side-effect + // of deletion from gAudacityProjects + if ( force ) + { + gAudacityProjects[0]->Close(true); + } + else + { + if (!gAudacityProjects[0]->Close()) + return false; + } + } + return true; +} + ODLock &AudacityProject::AllProjectDeleteMutex() { static ODLock theMutex; @@ -2575,7 +2597,8 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) // DanH: If we're definitely about to quit, clear the clipboard. // Doing this after Deref'ing the DirManager causes problems. - if ((gAudacityProjects.size() == 1) && (quitOnClose || gIsQuitting)) + if ((gAudacityProjects.size() == 1) && + (quitOnClose || AllProjects::Closing())) Clipboard::Get().Clear(); // JKC: For Win98 and Linux do not detach the menu bar. @@ -2677,7 +2700,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) gAudioIO->SetListener(gActiveProject); } - if (gAudacityProjects.empty() && !gIsQuitting) { + if (gAudacityProjects.empty() && !AllProjects::Closing()) { #if !defined(__WXMAC__) if (quitOnClose) { diff --git a/src/Project.h b/src/Project.h index 586b904c6..fabcbca5b 100644 --- a/src/Project.h +++ b/src/Project.h @@ -150,6 +150,20 @@ class ImportXMLTagHandler final : public XMLTagHandler AudacityProject* mProject; }; +class AllProjects +{ +public: + // Return true if all projects do close (always so if force == true) + // But if return is false, that means the user cancelled close of at least + // one un-saved project. + static bool Close( bool force = false ); + + static bool Closing() { return sbClosing; } + +private: + static bool sbClosing; +}; + class EffectPlugs; class CommandContext; class CommandManager;