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

Calls to Disconnect or Unbind in destructors are not needed, if...

... it's either the source of the connection that is being destroyed, or other
object (such as an ancestor window) transitively owning it and so causing it to
be destroyed too;

or, the sink is being destroyed, and that sink is a wxEvtHandler (which is
always so for Disconnect, though not for Unbind in case Bind was passed a
member function of a non-wxEvtHandler).

wxWidgets takes care of erasing the connection in such cases.

This removes most calls to Disconnect and Unbind.  Many destructors shrank to
nothing.

Notably, in case of popup menu handling, the call to Disconnect is not removable
because the object being destroyed is neither the source nor the sink.
This commit is contained in:
Paul Licameli
2018-01-31 10:08:42 -05:00
parent 12983e1685
commit bf5228267a
29 changed files with 4 additions and 284 deletions

View File

@@ -57,11 +57,6 @@ AudacityLogger::AudacityLogger()
mUpdated = false;
}
AudacityLogger::~AudacityLogger()
{
Destroy();
}
void AudacityLogger::Flush()
{
if (mUpdated && mFrame && mFrame->IsShown()) {
@@ -95,50 +90,6 @@ void AudacityLogger::DoLogText(const wxString & str)
}
}
void AudacityLogger::Destroy()
{
if (mFrame) {
mFrame->Disconnect(LoggerID_Save,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnSave),
NULL,
this);
mFrame->Disconnect(LoggerID_Clear,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnClear),
NULL,
this);
mFrame->Disconnect(LoggerID_Close,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnClose),
NULL,
this);
mFrame->Disconnect(LoggerID_Save,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnSave),
NULL,
this);
mFrame->Disconnect(LoggerID_Clear,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnClear),
NULL,
this);
mFrame->Disconnect(LoggerID_Close,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnClose),
NULL,
this);
mFrame->Disconnect(wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(AudacityLogger::OnCloseWindow),
NULL,
this);
mFrame.reset();
}
}
void AudacityLogger::Show(bool show)
{
// Hide the frame if created, otherwise do nothing
@@ -272,7 +223,7 @@ void AudacityLogger::OnCloseWindow(wxCloseEvent & WXUNUSED(e))
// On the Mac, destroy the window rather than hiding it since the
// log menu will override the root windows menu if there is no
// project window open.
Destroy();
mFrame.reset();
#else
Show(false);
#endif