mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Don't hold a dangling pointer to a menu bar in CommandManager
This commit is contained in:
parent
fefc3bf35d
commit
01875db4bd
@ -1397,6 +1397,9 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
std::unique_ptr<wxMenuBar> menubar2;
|
||||
if( !bShowExtraMenus )
|
||||
{
|
||||
// Make a temporary menu bar collecting items added below.
|
||||
// This bar will be discarded but other side effects on the command
|
||||
// manager persist.
|
||||
menubar2 = c->AddMenuBar(wxT("ext-menu"));
|
||||
c->SetOccultCommands(true);
|
||||
}
|
||||
@ -1791,7 +1794,7 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
|
||||
|
||||
if (!bShowExtraMenus)
|
||||
{
|
||||
c->SwapMenuBars();
|
||||
c->PopMenuBar();
|
||||
c->SetOccultCommands(false);
|
||||
}
|
||||
|
||||
|
@ -597,17 +597,17 @@ wxMenuBar * CommandManager::CurrentMenuBar() const
|
||||
}
|
||||
|
||||
///
|
||||
/// Swap the last two menu bars in the list,
|
||||
/// to make the previous menu bar 'current' again.
|
||||
/// Typically used to switch back and forth
|
||||
/// between adding to a hidden menu bar and
|
||||
/// adding to one that is visible,
|
||||
/// adding to one that is visible
|
||||
///
|
||||
void CommandManager::SwapMenuBars()
|
||||
void CommandManager::PopMenuBar()
|
||||
{
|
||||
int l = mMenuBarList.size();
|
||||
wxASSERT(l >= 2);
|
||||
std::swap(mMenuBarList[l - 2], mMenuBarList[l - 1]);
|
||||
auto iter = mMenuBarList.end();
|
||||
if ( iter != mMenuBarList.begin() )
|
||||
mMenuBarList.erase( --iter );
|
||||
else
|
||||
wxASSERT( false );
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ struct MenuBarListEntry
|
||||
{}
|
||||
|
||||
wxString name;
|
||||
wxMenuBar *menubar; // This structure does not assume memory ownership!
|
||||
wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
|
||||
};
|
||||
|
||||
struct SubMenuListEntry
|
||||
@ -211,7 +211,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
const wxChar *accel,
|
||||
CommandFlag flags);
|
||||
|
||||
void SwapMenuBars();
|
||||
void PopMenuBar();
|
||||
void SetOccultCommands( bool bOccult);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user