From 6cde697a8e59ae11adecb0b31f7749929a90d9b6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 26 Apr 2019 00:43:17 -0400 Subject: [PATCH] Don't call QuitAudacity directly from src/menus... ... This cuts link dependency on AudacityApp.cpp, and allows the function to be private to that file --- src/Audacity.h | 3 --- src/AudacityApp.cpp | 11 ++++++++--- src/AudacityApp.h | 3 --- src/Project.cpp | 4 +++- src/menus/FileMenus.cpp | 4 +++- src/menus/TransportMenus.cpp | 6 +++++- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Audacity.h b/src/Audacity.h index 648b50611..fd4868a40 100644 --- a/src/Audacity.h +++ b/src/Audacity.h @@ -109,9 +109,6 @@ class wxWindow; -void QuitAudacity(bool bForce); -void QuitAudacity(); - // Please try to support unlimited path length instead of using PLATFORM_MAX_PATH! // Define one constant for maximum path value, so we don't have to do // platform-specific conditionals everywhere we want to check it. diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index c3c5c02cc..82f981486 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -266,7 +266,7 @@ static void wxOnAssert(const wxChar *fileName, int lineNumber, const wxChar *msg static bool gInited = false; static bool gIsQuitting = false; -void QuitAudacity(bool bForce) +static void QuitAudacity(bool bForce) { // guard against recursion if (gIsQuitting) @@ -323,7 +323,7 @@ void QuitAudacity(bool bForce) } } -void QuitAudacity() +static void QuitAudacity() { QuitAudacity(false); } @@ -647,9 +647,14 @@ BEGIN_EVENT_TABLE(AudacityApp, wxApp) EVT_MENU(wxID_OPEN, AudacityApp::OnMenuOpen) EVT_MENU(wxID_ABOUT, AudacityApp::OnMenuAbout) EVT_MENU(wxID_PREFERENCES, AudacityApp::OnMenuPreferences) - EVT_MENU(wxID_EXIT, AudacityApp::OnMenuExit) #endif + // Associate the handler with the menu id on all operating systems, even + // if they don't have an application menu bar like in macOS, so that + // other parts of the program can send the application a shut-down + // event + EVT_MENU(wxID_EXIT, AudacityApp::OnMenuExit) + #ifndef __WXMSW__ EVT_SOCKET(ID_IPC_SERVER, AudacityApp::OnServerEvent) EVT_SOCKET(ID_IPC_SOCKET, AudacityApp::OnSocketEvent) diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 32bdda6c6..55b8da308 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -39,9 +39,6 @@ class AppCommandEvent; class AudacityLogger; class AudacityProject; -void QuitAudacity(bool bForce); -void QuitAudacity(); - class AliasBlockFile; class AudacityApp final : public wxApp { diff --git a/src/Project.cpp b/src/Project.cpp index 2f4076e96..21421ea28 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2784,7 +2784,9 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) #if !defined(__WXMAC__) if (quitOnClose) { - QuitAudacity(); + // Simulate the application Exit menu item + wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT }; + wxTheApp->AddPendingEvent( evt ); } else { AllProjects::Reset(); diff --git a/src/menus/FileMenus.cpp b/src/menus/FileMenus.cpp index fdb9b4b54..e353b3237 100644 --- a/src/menus/FileMenus.cpp +++ b/src/menus/FileMenus.cpp @@ -542,7 +542,9 @@ void OnPrint(const CommandContext &context) void OnExit(const CommandContext &WXUNUSED(context) ) { - QuitAudacity(); + // Simulate the application Exit menu item + wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT }; + wxTheApp->AddPendingEvent( evt ); } }; // struct Handler diff --git a/src/menus/TransportMenus.cpp b/src/menus/TransportMenus.cpp index 548eac47e..8da59815a 100644 --- a/src/menus/TransportMenus.cpp +++ b/src/menus/TransportMenus.cpp @@ -457,7 +457,11 @@ void OnTimerRecord(const CommandContext &context) // No action required break; case POST_TIMER_RECORD_CLOSE: - wxTheApp->CallAfter( []{ QuitAudacity(); } ); + wxTheApp->CallAfter( []{ + // Simulate the application Exit menu item + wxCommandEvent evt{ wxEVT_MENU, wxID_EXIT }; + wxTheApp->AddPendingEvent( evt ); + } ); break; case POST_TIMER_RECORD_RESTART: // Restart System