From 11305b956f2a45565026b54f2b33a8ddd508a692 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 10 Aug 2016 01:32:13 -0400 Subject: [PATCH] Use make_unique for wxMenu objects --- src/AudacityApp.cpp | 9 ++++---- src/effects/Effect.cpp | 49 ++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index b08ebabbe..8bd4158a7 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -1434,17 +1434,18 @@ bool AudacityApp::OnInit() // On the Mac, users don't expect a program to quit when you close the last window. // Create a menubar that will show when all project windows are closed. - wxMenu *fileMenu = new wxMenu(); - wxMenu *recentMenu = new wxMenu(); + auto fileMenu = std::make_unique(); + auto urecentMenu = std::make_unique(); + auto recentMenu = urecentMenu.get(); fileMenu->Append(wxID_NEW, wxString(_("&New")) + wxT("\tCtrl+N")); fileMenu->Append(wxID_OPEN, wxString(_("&Open...")) + wxT("\tCtrl+O")); - fileMenu->AppendSubMenu(recentMenu, _("Open &Recent...")); + fileMenu->AppendSubMenu(urecentMenu.release(), _("Open &Recent...")); fileMenu->Append(wxID_ABOUT, _("&About Audacity...")); fileMenu->Append(wxID_PREFERENCES, wxString(_("&Preferences...")) + wxT("\tCtrl+,")); { auto menuBar = std::make_unique(); - menuBar->Append(fileMenu, _("&File")); + menuBar->Append(fileMenu.release(), _("&File")); // PRL: Are we sure wxWindows will not leak this menuBar? // The online documentation is not explicit. diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 4e3cbae5e..485aefedc 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -3290,7 +3290,6 @@ void EffectUIHost::OnDebug(wxCommandEvent & evt) void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt)) { wxMenu menu; - wxMenu *sub; LoadUserPresets(); @@ -3300,12 +3299,12 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt)) } else { - sub = new wxMenu(); + auto sub = std::make_unique(); for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++) { sub->Append(kUserPresetsID + i, mUserPresets[i]); } - menu.Append(0, _("User Presets"), sub); + menu.Append(0, _("User Presets"), sub.release()); } menu.Append(kSaveAsID, _("Save Preset...")); @@ -3316,35 +3315,37 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt)) } else { - sub = new wxMenu(); + auto sub = std::make_unique(); for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++) { sub->Append(kDeletePresetID + i, mUserPresets[i]); } - menu.Append(0, _("Delete Preset"), sub); + menu.Append(0, _("Delete Preset"), sub.release()); } menu.AppendSeparator(); wxArrayString factory = mEffect->GetFactoryPresets(); - sub = new wxMenu(); - sub->Append(kDefaultsID, _("Defaults")); - if (factory.GetCount() > 0) { - sub->AppendSeparator(); - for (size_t i = 0, cnt = factory.GetCount(); i < cnt; i++) + auto sub = std::make_unique(); + sub->Append(kDefaultsID, _("Defaults")); + if (factory.GetCount() > 0) { - wxString label = factory[i]; - if (label.IsEmpty()) + sub->AppendSeparator(); + for (size_t i = 0, cnt = factory.GetCount(); i < cnt; i++) { - label = _("None"); - } + wxString label = factory[i]; + if (label.IsEmpty()) + { + label = _("None"); + } - sub->Append(kFactoryPresetsID + i, label); + sub->Append(kFactoryPresetsID + i, label); + } } + menu.Append(0, _("Factory Presets"), sub.release()); } - menu.Append(0, _("Factory Presets"), sub); menu.AppendSeparator(); menu.Append(kImportID, _("Import..."))->Enable(mClient->CanExportPresets()); @@ -3353,15 +3354,17 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt)) menu.Append(kOptionsID, _("Options..."))->Enable(mClient->HasOptions()); menu.AppendSeparator(); - sub = new wxMenu(); + { + auto sub = std::make_unique(); - sub->Append(kDummyID, wxString::Format(_("Type: %s"), mEffect->GetFamily().c_str())); - sub->Append(kDummyID, wxString::Format(_("Name: %s"), mEffect->GetName().c_str())); - sub->Append(kDummyID, wxString::Format(_("Version: %s"), mEffect->GetVersion().c_str())); - sub->Append(kDummyID, wxString::Format(_("Vendor: %s"), mEffect->GetVendor().c_str())); - sub->Append(kDummyID, wxString::Format(_("Description: %s"), mEffect->GetDescription().c_str())); + sub->Append(kDummyID, wxString::Format(_("Type: %s"), mEffect->GetFamily().c_str())); + sub->Append(kDummyID, wxString::Format(_("Name: %s"), mEffect->GetName().c_str())); + sub->Append(kDummyID, wxString::Format(_("Version: %s"), mEffect->GetVersion().c_str())); + sub->Append(kDummyID, wxString::Format(_("Vendor: %s"), mEffect->GetVendor().c_str())); + sub->Append(kDummyID, wxString::Format(_("Description: %s"), mEffect->GetDescription().c_str())); - menu.Append(0, _("About"), sub); + menu.Append(0, _("About"), sub.release()); + } wxWindow *btn = FindWindow(kMenuID); wxRect r = btn->GetRect();