1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 23:59:37 +02:00

Reviewed allocations of wxMenuBar items.

This commit is contained in:
Paul Licameli 2016-02-20 20:23:54 -05:00
parent af16636fe2
commit cf3daebff6
5 changed files with 561 additions and 550 deletions

@ -1406,10 +1406,14 @@ bool AudacityApp::OnInit()
fileMenu->Append(wxID_ABOUT, _("&About Audacity..."));
fileMenu->Append(wxID_PREFERENCES, wxString(_("&Preferences...")) + wxT("\tCtrl+,"));
wxMenuBar *menuBar = new wxMenuBar();
{
auto menuBar = std::make_unique<wxMenuBar>();
menuBar->Append(fileMenu, _("&File"));
wxMenuBar::MacSetCommonMenuBar(menuBar);
// PRL: Are we sure wxWindows will not leak this menuBar?
// The online documentation is not explicit.
wxMenuBar::MacSetCommonMenuBar(menuBar.release());
}
mRecentFiles->UseMenu(recentMenu);
mRecentFiles->AddFilesToMenu(recentMenu);

@ -328,7 +328,9 @@ void AudacityProject::CreateMenusAndCommands()
wxArrayString names;
wxArrayInt indices;
wxMenuBar *menubar = c->AddMenuBar(wxT("appmenu"));
{
auto menubar = c->AddMenuBar(wxT("appmenu"));
wxASSERT(menubar);
/////////////////////////////////////////////////////////////////////////////
// File menu
@ -1099,7 +1101,8 @@ void AudacityProject::CreateMenusAndCommands()
/////////////////////////////////////////////////////////////////////////////
SetMenuBar(menubar);
SetMenuBar(menubar.release());
}
c->AddGlobalCommand(wxT("PrevWindow"), _("Move backward thru active windows"), FN(PrevWindow), wxT("Alt+Shift+F6"));
c->AddGlobalCommand(wxT("NextWindow"), _("Move forward thru active windows"), FN(NextWindow), wxT("Alt+F6"));
@ -1628,9 +1631,11 @@ void AudacityProject::RebuildMenuBar()
// Delete the menus, since we will soon recreate them.
// Rather oddly, the menus don't vanish as a result of doing this.
wxMenuBar *menuBar = GetMenuBar();
{
std::unique_ptr<wxMenuBar> menuBar{ GetMenuBar() };
DetachMenuBar();
delete menuBar;
// menuBar gets deleted here
}
mCommandManager.PurgeData();

@ -672,20 +672,20 @@ ShuttleGuiBase & ShuttleGuiBase::Prop( int iProp )
wxMenuBar * ShuttleGuiBase::AddMenuBar( )
{
mpMenuBar = new wxMenuBar( );
auto menuBar = std::make_unique<wxMenuBar>();
mpMenuBar = menuBar.get();
wxFrame * pFrame = (wxFrame*)mpParent;
pFrame->SetThemeEnabled( true );
mpMenuBar->SetThemeEnabled( true );
pFrame->SetMenuBar(mpMenuBar);
pFrame->SetMenuBar(menuBar.release());
return mpMenuBar;
}
wxMenu * ShuttleGuiBase::AddMenu( const wxString & Title )
{
mpMenu = new wxMenu;
mpMenuBar->Append( mpMenu, Title );
mpMenuBar->Append( (mpMenu = safenew wxMenu), Title );
return mpMenu;
}

@ -433,15 +433,17 @@ void CommandManager::PurgeData()
/// Makes a NEW menubar for placement on the top of a project
/// Names it according to the passed-in string argument.
///
/// If the menubar already exists, simply returns it.
wxMenuBar *CommandManager::AddMenuBar(const wxString & sMenu)
/// If the menubar already exists, that's unexpected.
std::unique_ptr<wxMenuBar> CommandManager::AddMenuBar(const wxString & sMenu)
{
wxMenuBar *menuBar = GetMenuBar(sMenu);
if (menuBar)
return menuBar;
if (menuBar) {
wxASSERT(false);
return {};
}
const auto result = new wxMenuBar{};
mMenuBarList.emplace_back(sMenu, result);
auto result = std::make_unique<wxMenuBar>();
mMenuBarList.emplace_back(sMenu, result.get());
return result;
}
@ -491,7 +493,7 @@ void CommandManager::BeginMenu(const wxString & tName)
///
void CommandManager::EndMenu()
{
// Add the menu to the menubard after all menu items have been
// Add the menu to the menubar after all menu items have been
// added to the menu to allow OSX to rearrange special menu
// items like Preferences, About, and Quit.
CurrentMenuBar()->Append(mCurrentMenu, mCurrentMenuName);

@ -40,7 +40,7 @@ struct MenuBarListEntry
{}
wxString name;
wxMenuBar *menubar;
wxMenuBar *menubar; // This structure does not assume memory ownership!
};
struct SubMenuListEntry
@ -109,7 +109,7 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
// Creating menus and adding commands
//
wxMenuBar *AddMenuBar(const wxString & sMenu);
std::unique_ptr<wxMenuBar> AddMenuBar(const wxString & sMenu);
void BeginMenu(const wxString & tName);
void EndMenu();