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

Remove AudacityApp::GetLogger() & HelpActions::DoShowLog()

This commit is contained in:
Paul Licameli 2019-04-26 10:20:49 -04:00
parent e845bd9544
commit 8da6529329
7 changed files with 34 additions and 32 deletions

View File

@ -831,13 +831,6 @@ locations of the missing files."), missingFileName);
} }
} }
AudacityLogger *AudacityApp::GetLogger()
{
// Use dynamic_cast so that we get a NULL ptr if we haven't yet
// setup our logger.
return dynamic_cast<AudacityLogger *>(wxLog::GetActiveTarget());
}
#if defined(__WXMSW__) #if defined(__WXMSW__)
#define WL(lang, sublang) (lang), (sublang), #define WL(lang, sublang) (lang), (sublang),
#else #else
@ -944,7 +937,7 @@ void AudacityApp::GenerateCrashReport(wxDebugReport::Context ctx)
#endif #endif
} }
AudacityLogger *logger = GetLogger(); auto logger = AudacityLogger::Get();
if (logger) if (logger)
{ {
rpt.AddText(wxT("log.txt"), logger->GetLog(), _TS("Audacity Log")); rpt.AddText(wxT("log.txt"), logger->GetLog(), _TS("Audacity Log"));
@ -1051,11 +1044,8 @@ bool AudacityApp::OnInit()
// Ensure we have an event loop during initialization // Ensure we have an event loop during initialization
wxEventLoopGuarantor eventLoop; wxEventLoopGuarantor eventLoop;
// wxWidgets will clean up the logger for the main thread, so we can say // cause initialization of wxWidgets' global logger target
// safenew. See: (void) AudacityLogger::Get();
// http://docs.wxwidgets.org/3.0/classwx_log.html#a2525bf54fa3f31dc50e6e3cd8651e71d
std::unique_ptr < wxLog >
{ wxLog::SetActiveTarget(safenew AudacityLogger) }; // DELETE old
#if defined(__WXMAC__) #if defined(__WXMAC__)
// Disable window animation // Disable window animation

View File

@ -36,7 +36,6 @@ class IPCServ;
class Importer; class Importer;
class CommandHandler; class CommandHandler;
class AppCommandEvent; class AppCommandEvent;
class AudacityLogger;
class AudacityProject; class AudacityProject;
class AliasBlockFile; class AliasBlockFile;
@ -93,8 +92,6 @@ class AudacityApp final : public wxApp {
void AssociateFileTypes(); void AssociateFileTypes();
#endif #endif
AudacityLogger *GetLogger();
#if defined(EXPERIMENTAL_CRASH_REPORT) #if defined(EXPERIMENTAL_CRASH_REPORT)
void GenerateCrashReport(wxDebugReport::Context ctx); void GenerateCrashReport(wxDebugReport::Context ctx);
#endif #endif

View File

@ -22,6 +22,7 @@ Provides thread-safe logging based on the wxWidgets log facility.
#include "FileNames.h" #include "FileNames.h"
#include "ShuttleGui.h" #include "ShuttleGui.h"
#include <mutex>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/frame.h> #include <wx/frame.h>
@ -50,6 +51,22 @@ enum
LoggerID_Close LoggerID_Close
}; };
AudacityLogger *AudacityLogger::Get()
{
static std::once_flag flag;
std::call_once( flag, []{
// wxWidgets will clean up the logger for the main thread, so we can say
// safenew. See:
// http://docs.wxwidgets.org/3.0/classwx_log.html#a2525bf54fa3f31dc50e6e3cd8651e71d
std::unique_ptr < wxLog > // DELETE any previous logger
{ wxLog::SetActiveTarget(safenew AudacityLogger) };
} );
// Use dynamic_cast so that we get a NULL ptr in case our logger
// is no longer the target.
return dynamic_cast<AudacityLogger *>(wxLog::GetActiveTarget());
}
AudacityLogger::AudacityLogger() AudacityLogger::AudacityLogger()
: wxEvtHandler(), : wxEvtHandler(),
wxLog() wxLog()

View File

@ -27,7 +27,9 @@ class wxTextCtrl;
class AudacityLogger final : public wxEvtHandler, public wxLog { class AudacityLogger final : public wxEvtHandler, public wxLog {
public: public:
AudacityLogger();
// Get the singleton instance or null
static AudacityLogger *Get();
void Show(bool show = true); void Show(bool show = true);
@ -40,6 +42,8 @@ class AudacityLogger final : public wxEvtHandler, public wxLog {
void DoLogText(const wxString & msg) override; void DoLogText(const wxString & msg) override;
private: private:
AudacityLogger();
void OnCloseWindow(wxCloseEvent & e); void OnCloseWindow(wxCloseEvent & e);
void OnClose(wxCommandEvent & e); void OnClose(wxCommandEvent & e);
void OnClear(wxCommandEvent & e); void OnClear(wxCommandEvent & e);

View File

@ -180,7 +180,6 @@ bool DoAudacityCommand(
/// Namespace for functions for Help menu /// Namespace for functions for Help menu
namespace HelpActions { namespace HelpActions {
void DoHelpWelcome( AudacityProject & ); void DoHelpWelcome( AudacityProject & );
void DoShowLog( AudacityProject& );
} }
#endif #endif

View File

@ -75,14 +75,6 @@ namespace HelpActions {
// exported helper functions // exported helper functions
void DoShowLog( AudacityProject & )
{
AudacityLogger *logger = wxGetApp().GetLogger();
if (logger) {
logger->Show();
}
}
void DoHelpWelcome( AudacityProject &project ) void DoHelpWelcome( AudacityProject &project )
{ {
SplashDialog::Show2( &project ); SplashDialog::Show2( &project );
@ -135,7 +127,10 @@ void OnMidiDeviceInfo(const CommandContext &context)
void OnShowLog( const CommandContext &context ) void OnShowLog( const CommandContext &context )
{ {
DoShowLog( context.project ); auto logger = AudacityLogger::Get();
if (logger) {
logger->Show();
}
} }
#if defined(EXPERIMENTAL_CRASH_REPORT) #if defined(EXPERIMENTAL_CRASH_REPORT)

View File

@ -21,8 +21,6 @@ for each problem encountered, since there can be many orphans.
#include "../Audacity.h" #include "../Audacity.h"
#include "MultiDialog.h" #include "MultiDialog.h"
#include "../Project.h"
#include <wx/app.h> #include <wx/app.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/dialog.h> #include <wx/dialog.h>
@ -34,7 +32,7 @@ for each problem encountered, since there can be many orphans.
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/radiobox.h> #include <wx/radiobox.h>
#include "../Menus.h" #include "../AudacityLogger.h"
#include "wxPanelWrapper.h" #include "wxPanelWrapper.h"
class MultiDialog final : public wxDialogWrapper class MultiDialog final : public wxDialogWrapper
@ -153,8 +151,10 @@ void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event)) void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
{ {
auto project = GetActiveProject(); auto logger = AudacityLogger::Get();
HelpActions::DoShowLog(*project); if (logger) {
logger->Show();
}
} }