mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 17:10:55 +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;
|
wxUNIXaddress addr;
|
||||||
addr.Filename(sockFile);
|
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
|
// Setup the socket
|
||||||
sock->Connect(addr, true);
|
// A wxSocketClient must not be deleted by us, but rather, let the
|
||||||
if (sock->IsConnected())
|
// 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
|
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
|
||||||
wxString param = parser->GetParam(i);
|
{
|
||||||
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
|
// Send the filename
|
||||||
|
wxString param = parser->GetParam(i);
|
||||||
|
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sock->Destroy();
|
wxMilliSleep(100);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMilliSleep(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sock->Destroy();
|
|
||||||
#endif
|
#endif
|
||||||
// There is another copy of Audacity running. Force quit.
|
// There is another copy of Audacity running. Force quit.
|
||||||
|
|
||||||
|
@ -111,14 +111,15 @@ class ScreenFrame final : public wxFrame
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
static ScreenFrame *mFrame = NULL;
|
using ScreenFramePtr = Destroy_ptr<ScreenFrame>;
|
||||||
|
ScreenFramePtr mFrame;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void OpenScreenshotTools()
|
void OpenScreenshotTools()
|
||||||
{
|
{
|
||||||
if (!mFrame) {
|
if (!mFrame) {
|
||||||
mFrame = new ScreenFrame(NULL, -1);
|
mFrame = ScreenFramePtr{ safenew ScreenFrame(NULL, -1) };
|
||||||
}
|
}
|
||||||
mFrame->Show();
|
mFrame->Show();
|
||||||
mFrame->Raise();
|
mFrame->Raise();
|
||||||
@ -126,10 +127,7 @@ void OpenScreenshotTools()
|
|||||||
|
|
||||||
void CloseScreenshotTools()
|
void CloseScreenshotTools()
|
||||||
{
|
{
|
||||||
if (mFrame) {
|
mFrame.reset();
|
||||||
mFrame->Destroy();
|
|
||||||
mFrame = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -485,7 +483,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
|
|||||||
|
|
||||||
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
mFrame = NULL;
|
if (this == mFrame.get())
|
||||||
|
mFrame.release();
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,15 +779,15 @@ void Effect::Preview()
|
|||||||
|
|
||||||
wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client)
|
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())
|
if (dlg->Initialize())
|
||||||
{
|
{
|
||||||
return dlg;
|
// release() is safe because parent will own it
|
||||||
|
return dlg.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete dlg;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
|||||||
mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
|
mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
|
||||||
|
|
||||||
// Create the indicator frame
|
// Create the indicator frame
|
||||||
mIndicator = new wxFrame( NULL,
|
mIndicator = FramePtr{ safenew wxFrame( NULL,
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
wxEmptyString,
|
wxEmptyString,
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
@ -372,7 +372,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
|||||||
wxFRAME_SHAPED |
|
wxFRAME_SHAPED |
|
||||||
wxNO_BORDER |
|
wxNO_BORDER |
|
||||||
wxFRAME_NO_TASKBAR |
|
wxFRAME_NO_TASKBAR |
|
||||||
wxSTAY_ON_TOP );
|
wxSTAY_ON_TOP )
|
||||||
|
};
|
||||||
|
|
||||||
// Hook the creation event...only needed on GTK, but doesn't hurt for all
|
// Hook the creation event...only needed on GTK, but doesn't hurt for all
|
||||||
mIndicator->Connect( wxEVT_CREATE,
|
mIndicator->Connect( wxEVT_CREATE,
|
||||||
@ -462,9 +463,6 @@ ToolManager::~ToolManager()
|
|||||||
wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
|
wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
|
||||||
NULL,
|
NULL,
|
||||||
this );
|
this );
|
||||||
|
|
||||||
// Must destroy the window since it doesn't have a parent
|
|
||||||
mIndicator->Destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This table describes the default configuration of the toolbars as
|
// This table describes the default configuration of the toolbars as
|
||||||
|
@ -97,7 +97,8 @@ class ToolManager final : public wxEvtHandler
|
|||||||
wxPoint mLastPos;
|
wxPoint mLastPos;
|
||||||
wxRect mBarPos;
|
wxRect mBarPos;
|
||||||
|
|
||||||
wxFrame *mIndicator;
|
using FramePtr = Destroy_ptr<wxFrame>;
|
||||||
|
FramePtr mIndicator;
|
||||||
std::unique_ptr<wxRegion> mLeft, mDown;
|
std::unique_ptr<wxRegion> mLeft, mDown;
|
||||||
wxRegion *mCurrent;
|
wxRegion *mCurrent;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user