mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-22 06:22:58 +02:00
Remove a few more naked new in CommandManager.cpp
This commit is contained in:
@@ -413,7 +413,6 @@ private:
|
|||||||
CommandManager::CommandManager():
|
CommandManager::CommandManager():
|
||||||
mCurrentID(17000),
|
mCurrentID(17000),
|
||||||
mCurrentMenuName(COMMAND),
|
mCurrentMenuName(COMMAND),
|
||||||
mCurrentMenu(NULL),
|
|
||||||
mDefaultFlags(AlwaysEnabledFlag),
|
mDefaultFlags(AlwaysEnabledFlag),
|
||||||
mDefaultMask(AlwaysEnabledFlag)
|
mDefaultMask(AlwaysEnabledFlag)
|
||||||
{
|
{
|
||||||
@@ -442,7 +441,6 @@ void CommandManager::PurgeData()
|
|||||||
mCommandKeyHash.clear();
|
mCommandKeyHash.clear();
|
||||||
mCommandIDHash.clear();
|
mCommandIDHash.clear();
|
||||||
|
|
||||||
mCurrentMenu = NULL;
|
|
||||||
mCurrentMenuName = COMMAND;
|
mCurrentMenuName = COMMAND;
|
||||||
mCurrentID = 0;
|
mCurrentID = 0;
|
||||||
}
|
}
|
||||||
@@ -504,9 +502,7 @@ wxMenuBar * CommandManager::CurrentMenuBar() const
|
|||||||
///
|
///
|
||||||
void CommandManager::BeginMenu(const wxString & tName)
|
void CommandManager::BeginMenu(const wxString & tName)
|
||||||
{
|
{
|
||||||
wxMenu *tmpMenu = new wxMenu();
|
mCurrentMenu = std::make_unique<wxMenu>();
|
||||||
|
|
||||||
mCurrentMenu = tmpMenu;
|
|
||||||
mCurrentMenuName = tName;
|
mCurrentMenuName = tName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,8 +515,7 @@ void CommandManager::EndMenu()
|
|||||||
// Add the menu to the menubar 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
|
// added to the menu to allow OSX to rearrange special menu
|
||||||
// items like Preferences, About, and Quit.
|
// items like Preferences, About, and Quit.
|
||||||
CurrentMenuBar()->Append(mCurrentMenu, mCurrentMenuName);
|
CurrentMenuBar()->Append(mCurrentMenu.release(), mCurrentMenuName);
|
||||||
mCurrentMenu = NULL;
|
|
||||||
mCurrentMenuName = COMMAND;
|
mCurrentMenuName = COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,14 +525,10 @@ void CommandManager::EndMenu()
|
|||||||
/// the function's argument.
|
/// the function's argument.
|
||||||
wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
||||||
{
|
{
|
||||||
const auto result = new wxMenu{};
|
mSubMenuList.push_back
|
||||||
#ifdef __AUDACITY_OLD_STD__
|
(make_movable< SubMenuListEntry > ( tName, std::make_unique<wxMenu>() ));
|
||||||
mSubMenuList.push_back(SubMenuListEntry{ tName, result });
|
|
||||||
#else
|
|
||||||
mSubMenuList.emplace_back(tName, result);
|
|
||||||
#endif
|
|
||||||
mbSeparatorAllowed = false;
|
mbSeparatorAllowed = false;
|
||||||
return result;
|
return mSubMenuList.back()->menu.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -548,13 +539,14 @@ wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
|||||||
void CommandManager::EndSubMenu()
|
void CommandManager::EndSubMenu()
|
||||||
{
|
{
|
||||||
//Save the submenu's information
|
//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
|
//Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
|
||||||
mSubMenuList.pop_back();
|
mSubMenuList.pop_back();
|
||||||
|
|
||||||
//Add the submenu to the current menu
|
//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;
|
mbSeparatorAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +559,7 @@ wxMenu * CommandManager::CurrentSubMenu() const
|
|||||||
if(mSubMenuList.empty())
|
if(mSubMenuList.empty())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return mSubMenuList.back().menu;
|
return mSubMenuList.back()->menu.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -583,7 +575,7 @@ wxMenu * CommandManager::CurrentMenu() const
|
|||||||
|
|
||||||
if(!tmpCurrentSubMenu)
|
if(!tmpCurrentSubMenu)
|
||||||
{
|
{
|
||||||
return mCurrentMenu;
|
return mCurrentMenu.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmpCurrentSubMenu;
|
return tmpCurrentSubMenu;
|
||||||
@@ -834,7 +826,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
|
|||||||
|
|
||||||
wxString labelPrefix;
|
wxString labelPrefix;
|
||||||
if (!mSubMenuList.empty()) {
|
if (!mSubMenuList.empty()) {
|
||||||
labelPrefix = mSubMenuList.back().name;
|
labelPrefix = mSubMenuList.back()->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wxMac 2.5 and higher will do special things with the
|
// wxMac 2.5 and higher will do special things with the
|
||||||
|
@@ -40,12 +40,14 @@ struct MenuBarListEntry
|
|||||||
|
|
||||||
struct SubMenuListEntry
|
struct SubMenuListEntry
|
||||||
{
|
{
|
||||||
SubMenuListEntry(const wxString &name_, wxMenu *menu_)
|
SubMenuListEntry(const wxString &name_, std::unique_ptr<wxMenu> &&menu_)
|
||||||
: name(name_), menu(menu_)
|
: name(name_), menu( std::move(menu_) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
// SubMenuListEntry( SubMenuListEntry&& ) = default;
|
||||||
|
|
||||||
wxString name;
|
wxString name;
|
||||||
wxMenu *menu;
|
std::unique_ptr<wxMenu> menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CommandListEntry
|
struct CommandListEntry
|
||||||
@@ -71,7 +73,9 @@ struct CommandListEntry
|
|||||||
};
|
};
|
||||||
|
|
||||||
using MenuBarList = std::vector < MenuBarListEntry >;
|
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,
|
// 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.
|
// 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);
|
wxMenu* BeginSubMenu(const wxString & tName);
|
||||||
void EndSubMenu();
|
void EndSubMenu();
|
||||||
void SetToMenu( wxMenu * menu ){
|
|
||||||
mCurrentMenu = menu;
|
|
||||||
};
|
|
||||||
|
|
||||||
void InsertItem(const wxString & name,
|
void InsertItem(const wxString & name,
|
||||||
const wxString & label,
|
const wxString & label,
|
||||||
@@ -311,7 +312,7 @@ private:
|
|||||||
bool mbSeparatorAllowed; // false at the start of a menu and immediately after a separator.
|
bool mbSeparatorAllowed; // false at the start of a menu and immediately after a separator.
|
||||||
|
|
||||||
wxString mCurrentMenuName;
|
wxString mCurrentMenuName;
|
||||||
wxMenu * mCurrentMenu;
|
std::unique_ptr<wxMenu> mCurrentMenu;
|
||||||
|
|
||||||
CommandFlag mDefaultFlags;
|
CommandFlag mDefaultFlags;
|
||||||
CommandMask mDefaultMask;
|
CommandMask mDefaultMask;
|
||||||
|
Reference in New Issue
Block a user