mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 23:59:37 +02:00
Some uses of Destroy_ptr let us remove some naked news
This commit is contained in:
parent
aaeaadff07
commit
fec4069d9d
@ -1766,33 +1766,34 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
|
||||
wxUNIXaddress addr;
|
||||
addr.Filename(sockFile);
|
||||
|
||||
// Setup the socket
|
||||
wxSocketClient *sock = new wxSocketClient();
|
||||
sock->SetFlags(wxSOCKET_WAITALL);
|
||||
|
||||
// We try up to 50 times since there's a small window
|
||||
// where the server may not have been fully initialized.
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
// Connect to the existing Audacity
|
||||
sock->Connect(addr, true);
|
||||
if (sock->IsConnected())
|
||||
// Setup the socket
|
||||
// A wxSocketClient must not be deleted by us, but rather, let the
|
||||
// framework do appropriate delayed deletion after Destroy()
|
||||
Destroy_ptr<wxSocketClient> sock { safenew wxSocketClient() };
|
||||
sock->SetFlags(wxSOCKET_WAITALL);
|
||||
|
||||
// We try up to 50 times since there's a small window
|
||||
// where the server may not have been fully initialized.
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
|
||||
// Connect to the existing Audacity
|
||||
sock->Connect(addr, true);
|
||||
if (sock->IsConnected())
|
||||
{
|
||||
// Send the filename
|
||||
wxString param = parser->GetParam(i);
|
||||
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
|
||||
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
|
||||
{
|
||||
// Send the filename
|
||||
wxString param = parser->GetParam(i);
|
||||
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
sock->Destroy();
|
||||
return false;
|
||||
wxMilliSleep(100);
|
||||
}
|
||||
|
||||
wxMilliSleep(100);
|
||||
}
|
||||
|
||||
sock->Destroy();
|
||||
#endif
|
||||
// There is another copy of Audacity running. Force quit.
|
||||
|
||||
|
@ -111,14 +111,15 @@ class ScreenFrame final : public wxFrame
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
static ScreenFrame *mFrame = NULL;
|
||||
using ScreenFramePtr = Destroy_ptr<ScreenFrame>;
|
||||
ScreenFramePtr mFrame;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OpenScreenshotTools()
|
||||
{
|
||||
if (!mFrame) {
|
||||
mFrame = new ScreenFrame(NULL, -1);
|
||||
mFrame = ScreenFramePtr{ safenew ScreenFrame(NULL, -1) };
|
||||
}
|
||||
mFrame->Show();
|
||||
mFrame->Raise();
|
||||
@ -126,10 +127,7 @@ void OpenScreenshotTools()
|
||||
|
||||
void CloseScreenshotTools()
|
||||
{
|
||||
if (mFrame) {
|
||||
mFrame->Destroy();
|
||||
mFrame = NULL;
|
||||
}
|
||||
mFrame.reset();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -485,7 +483,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
|
||||
|
||||
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
||||
{
|
||||
mFrame = NULL;
|
||||
if (this == mFrame.get())
|
||||
mFrame.release();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
@ -779,15 +779,15 @@ void Effect::Preview()
|
||||
|
||||
wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client)
|
||||
{
|
||||
EffectUIHost *dlg = new EffectUIHost(parent, this, client);
|
||||
Destroy_ptr<EffectUIHost> dlg
|
||||
{ safenew EffectUIHost{ parent, this, client} };
|
||||
|
||||
if (dlg->Initialize())
|
||||
{
|
||||
return dlg;
|
||||
// release() is safe because parent will own it
|
||||
return dlg.release();
|
||||
}
|
||||
|
||||
delete dlg;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
||||
mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
|
||||
|
||||
// Create the indicator frame
|
||||
mIndicator = new wxFrame( NULL,
|
||||
mIndicator = FramePtr{ safenew wxFrame( NULL,
|
||||
wxID_ANY,
|
||||
wxEmptyString,
|
||||
wxDefaultPosition,
|
||||
@ -372,7 +372,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
||||
wxFRAME_SHAPED |
|
||||
wxNO_BORDER |
|
||||
wxFRAME_NO_TASKBAR |
|
||||
wxSTAY_ON_TOP );
|
||||
wxSTAY_ON_TOP )
|
||||
};
|
||||
|
||||
// Hook the creation event...only needed on GTK, but doesn't hurt for all
|
||||
mIndicator->Connect( wxEVT_CREATE,
|
||||
@ -462,9 +463,6 @@ ToolManager::~ToolManager()
|
||||
wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
|
||||
NULL,
|
||||
this );
|
||||
|
||||
// Must destroy the window since it doesn't have a parent
|
||||
mIndicator->Destroy();
|
||||
}
|
||||
|
||||
// This table describes the default configuration of the toolbars as
|
||||
|
@ -97,7 +97,8 @@ class ToolManager final : public wxEvtHandler
|
||||
wxPoint mLastPos;
|
||||
wxRect mBarPos;
|
||||
|
||||
wxFrame *mIndicator;
|
||||
using FramePtr = Destroy_ptr<wxFrame>;
|
||||
FramePtr mIndicator;
|
||||
std::unique_ptr<wxRegion> mLeft, mDown;
|
||||
wxRegion *mCurrent;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user