1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

AudacityProject.cpp does not need gIsQuitting from AudacityApp.h

This commit is contained in:
Paul Licameli 2019-04-25 23:59:42 -04:00
parent 4a4f8ebe4e
commit d4b0fd1b83
4 changed files with 51 additions and 33 deletions

View File

@ -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();
}
}

View File

@ -44,8 +44,6 @@ void SaveWindowSize();
void QuitAudacity(bool bForce);
void QuitAudacity();
extern bool gIsQuitting;
class AliasBlockFile;
class AudacityApp final : public wxApp {

View File

@ -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<bool> 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) {

View File

@ -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;