1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-21 16:37:12 +01: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 #endif
static bool gInited = false; static bool gInited = false;
bool gIsQuitting = false; static bool gIsQuitting = false;
void QuitAudacity(bool bForce) void QuitAudacity(bool bForce)
{ {
// guard against recursion
if (gIsQuitting) if (gIsQuitting)
return; return;
@@ -292,22 +293,11 @@ void QuitAudacity(bool bForce)
/*end+*/ /*end+*/
{ {
SaveWindowSize(); SaveWindowSize();
while (gAudacityProjects.size()) bool closedAll = AllProjects::Close( bForce );
if ( !closedAll )
{ {
// Closing the project has global side-effect gIsQuitting = false;
// of deletion from gAudacityProjects return;
if (bForce)
{
gAudacityProjects[0]->Close(true);
}
else
{
if (!gAudacityProjects[0]->Close())
{
gIsQuitting = false;
return;
}
}
} }
} }
@@ -1949,19 +1939,12 @@ void AudacityApp::OnEndSession(wxCloseEvent & event)
// Try to close each open window. If the user hits Cancel // Try to close each open window. If the user hits Cancel
// in a Save Changes dialog, don't continue. // in a Save Changes dialog, don't continue.
if (!gAudacityProjects.empty()) { gIsQuitting = true;
while (gAudacityProjects.size()) { bool closedAll = AllProjects::Close( force );
// Closing the project has side-effect of if ( !closedAll )
// deletion from gAudacityProjects {
if (force) { gIsQuitting = false;
gAudacityProjects[0]->Close(true); event.Veto();
}
else if (!gAudacityProjects[0]->Close()) {
gIsQuitting = false;
event.Veto();
break;
}
}
} }
} }

View File

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

View File

@@ -173,6 +173,28 @@ scroll information. It also has some status flags.
#include "widgets/WindowAccessible.h" #include "widgets/WindowAccessible.h"
#endif #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() ODLock &AudacityProject::AllProjectDeleteMutex()
{ {
static ODLock theMutex; static ODLock theMutex;
@@ -2575,7 +2597,8 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
// DanH: If we're definitely about to quit, clear the clipboard. // DanH: If we're definitely about to quit, clear the clipboard.
// Doing this after Deref'ing the DirManager causes problems. // 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(); Clipboard::Get().Clear();
// JKC: For Win98 and Linux do not detach the menu bar. // JKC: For Win98 and Linux do not detach the menu bar.
@@ -2677,7 +2700,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
gAudioIO->SetListener(gActiveProject); gAudioIO->SetListener(gActiveProject);
} }
if (gAudacityProjects.empty() && !gIsQuitting) { if (gAudacityProjects.empty() && !AllProjects::Closing()) {
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
if (quitOnClose) { if (quitOnClose) {

View File

@@ -150,6 +150,20 @@ class ImportXMLTagHandler final : public XMLTagHandler
AudacityProject* mProject; 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 EffectPlugs;
class CommandContext; class CommandContext;
class CommandManager; class CommandManager;