mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 22:12:58 +02:00
Remove a few more naked new in CommandManager.cpp
This commit is contained in:
@@ -413,7 +413,6 @@ private:
|
||||
CommandManager::CommandManager():
|
||||
mCurrentID(17000),
|
||||
mCurrentMenuName(COMMAND),
|
||||
mCurrentMenu(NULL),
|
||||
mDefaultFlags(AlwaysEnabledFlag),
|
||||
mDefaultMask(AlwaysEnabledFlag)
|
||||
{
|
||||
@@ -442,7 +441,6 @@ void CommandManager::PurgeData()
|
||||
mCommandKeyHash.clear();
|
||||
mCommandIDHash.clear();
|
||||
|
||||
mCurrentMenu = NULL;
|
||||
mCurrentMenuName = COMMAND;
|
||||
mCurrentID = 0;
|
||||
}
|
||||
@@ -504,9 +502,7 @@ wxMenuBar * CommandManager::CurrentMenuBar() const
|
||||
///
|
||||
void CommandManager::BeginMenu(const wxString & tName)
|
||||
{
|
||||
wxMenu *tmpMenu = new wxMenu();
|
||||
|
||||
mCurrentMenu = tmpMenu;
|
||||
mCurrentMenu = std::make_unique<wxMenu>();
|
||||
mCurrentMenuName = tName;
|
||||
}
|
||||
|
||||
@@ -519,8 +515,7 @@ void CommandManager::EndMenu()
|
||||
// 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);
|
||||
mCurrentMenu = NULL;
|
||||
CurrentMenuBar()->Append(mCurrentMenu.release(), mCurrentMenuName);
|
||||
mCurrentMenuName = COMMAND;
|
||||
}
|
||||
|
||||
@@ -530,14 +525,10 @@ void CommandManager::EndMenu()
|
||||
/// the function's argument.
|
||||
wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
||||
{
|
||||
const auto result = new wxMenu{};
|
||||
#ifdef __AUDACITY_OLD_STD__
|
||||
mSubMenuList.push_back(SubMenuListEntry{ tName, result });
|
||||
#else
|
||||
mSubMenuList.emplace_back(tName, result);
|
||||
#endif
|
||||
mSubMenuList.push_back
|
||||
(make_movable< SubMenuListEntry > ( tName, std::make_unique<wxMenu>() ));
|
||||
mbSeparatorAllowed = false;
|
||||
return result;
|
||||
return mSubMenuList.back()->menu.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -548,13 +539,14 @@ wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
||||
void CommandManager::EndSubMenu()
|
||||
{
|
||||
//Save the submenu's information
|
||||
SubMenuListEntry tmpSubMenu = mSubMenuList.back();
|
||||
SubMenuListEntry tmpSubMenu { std::move( *mSubMenuList.back() ) };
|
||||
|
||||
//Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
|
||||
mSubMenuList.pop_back();
|
||||
|
||||
//Add the submenu to the current menu
|
||||
CurrentMenu()->Append(0, tmpSubMenu.name, tmpSubMenu.menu, tmpSubMenu.name);
|
||||
CurrentMenu()->Append
|
||||
(0, tmpSubMenu.name, tmpSubMenu.menu.release(), tmpSubMenu.name);
|
||||
mbSeparatorAllowed = true;
|
||||
}
|
||||
|
||||
@@ -567,7 +559,7 @@ wxMenu * CommandManager::CurrentSubMenu() const
|
||||
if(mSubMenuList.empty())
|
||||
return NULL;
|
||||
|
||||
return mSubMenuList.back().menu;
|
||||
return mSubMenuList.back()->menu.get();
|
||||
}
|
||||
|
||||
///
|
||||
@@ -583,7 +575,7 @@ wxMenu * CommandManager::CurrentMenu() const
|
||||
|
||||
if(!tmpCurrentSubMenu)
|
||||
{
|
||||
return mCurrentMenu;
|
||||
return mCurrentMenu.get();
|
||||
}
|
||||
|
||||
return tmpCurrentSubMenu;
|
||||
@@ -834,7 +826,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
|
||||
|
||||
wxString labelPrefix;
|
||||
if (!mSubMenuList.empty()) {
|
||||
labelPrefix = mSubMenuList.back().name;
|
||||
labelPrefix = mSubMenuList.back()->name;
|
||||
}
|
||||
|
||||
// wxMac 2.5 and higher will do special things with the
|
||||
|
@@ -40,12 +40,14 @@ struct MenuBarListEntry
|
||||
|
||||
struct SubMenuListEntry
|
||||
{
|
||||
SubMenuListEntry(const wxString &name_, wxMenu *menu_)
|
||||
: name(name_), menu(menu_)
|
||||
SubMenuListEntry(const wxString &name_, std::unique_ptr<wxMenu> &&menu_)
|
||||
: name(name_), menu( std::move(menu_) )
|
||||
{}
|
||||
|
||||
// SubMenuListEntry( SubMenuListEntry&& ) = default;
|
||||
|
||||
wxString name;
|
||||
wxMenu *menu;
|
||||
std::unique_ptr<wxMenu> menu;
|
||||
};
|
||||
|
||||
struct CommandListEntry
|
||||
@@ -71,7 +73,9 @@ struct CommandListEntry
|
||||
};
|
||||
|
||||
using MenuBarList = std::vector < MenuBarListEntry >;
|
||||
using SubMenuList = std::vector < SubMenuListEntry >;
|
||||
|
||||
// to do: remove the extra indirection when Mac compiler moves to newer version
|
||||
using SubMenuList = std::vector < movable_ptr<SubMenuListEntry> >;
|
||||
|
||||
// This is an array of pointers, not structures, because the hash maps also point to them,
|
||||
// so we don't want the structures to relocate with vector operations.
|
||||
@@ -109,9 +113,6 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
|
||||
wxMenu* BeginSubMenu(const wxString & tName);
|
||||
void EndSubMenu();
|
||||
void SetToMenu( wxMenu * menu ){
|
||||
mCurrentMenu = menu;
|
||||
};
|
||||
|
||||
void InsertItem(const wxString & name,
|
||||
const wxString & label,
|
||||
@@ -311,7 +312,7 @@ private:
|
||||
bool mbSeparatorAllowed; // false at the start of a menu and immediately after a separator.
|
||||
|
||||
wxString mCurrentMenuName;
|
||||
wxMenu * mCurrentMenu;
|
||||
std::unique_ptr<wxMenu> mCurrentMenu;
|
||||
|
||||
CommandFlag mDefaultFlags;
|
||||
CommandMask mDefaultMask;
|
||||
|
Reference in New Issue
Block a user