Audacity 3.2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor Struct Referencefinal
Inheritance diagram for anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor:
[legend]
Collaboration diagram for anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor:
[legend]

Classes

struct  CommandListEntryEx
 

Public Member Functions

 MenuItemVisitor (AudacityProject &proj)
 
 ~MenuItemVisitor () override
 
- Public Member Functions inherited from CommandManager::Populator
 Populator (AudacityProject &project, LeafVisitor leafVisitor, std::function< void()> doSeparator)
 
virtual ~Populator ()
 
- Public Member Functions inherited from MenuRegistry::Visitor< MenuRegistry::Traits >
 Visitor (VisitorFunctions< MenuRegistry::Traits > functions, std::function< void()> doSeparator)
 
- Public Member Functions inherited from Registry::VisitorFunctions< MenuRegistry::Traits >
 VisitorFunctions (Visitors &&visitors)
 Type-erasing constructor. More...
 
void BeginGroup (const GroupItem< MenuRegistry::Traits > &item, const Path &path) const
 Call-through for a decorating pre-visitor. More...
 
void Visit (const SingleItem &item, const Path &path) const
 Call-through for a decorating leaf-visitor. More...
 
void EndGroup (const GroupItem< MenuRegistry::Traits > &item, const Path &path) const
 Call-through for a decorating post-visitor. More...
 
- Public Member Functions inherited from MenuRegistry::detail::VisitorBase
std::pair< bool, bool > ShouldBeginGroup (const ItemProperties *pProperties)
 
void AfterBeginGroup (const ItemProperties *pProperties)
 
bool ShouldEndGroup (const ItemProperties *pProperties)
 
bool ShouldDoSeparator ()
 

Private Member Functions

std::unique_ptr< CommandManager::CommandListEntryAllocateEntry (const MenuRegistry::Options &options) final
 
void VisitEntry (CommandManager::CommandListEntry &, const MenuRegistry::Options *pOptions) final
 
void BeginMenu (const TranslatableString &tName) final
 
void EndMenu () final
 
void BeginMainMenu (const TranslatableString &tName)
 
void EndMainMenu ()
 
void BeginSubMenu (const TranslatableString &tName)
 
void EndSubMenu ()
 
void BeginOccultCommands () final
 
void EndOccultCommands () final
 
std::unique_ptr< wxMenuBar > AddMenuBar (const wxString &sMenu)
 
wxMenuBar * CurrentMenuBar () const
 
wxMenuBar * GetMenuBar (const wxString &sMenu) const
 
wxMenu * CurrentSubMenu () const
 
wxMenu * CurrentMenu () const
 

Private Attributes

std::vector< MenuBarListEntrymMenuBarList
 
std::vector< SubMenuListEntrymSubMenuList
 
std::unique_ptr< wxMenuBar > mTempMenuBar
 
std::unique_ptr< wxMenu > uCurrentMenu
 
wxMenu * mCurrentMenu {}
 

Additional Inherited Members

- Public Types inherited from CommandManager::Populator
using LeafVisitor = std::function< void(const Registry::SingleItem &, const Registry::Path &)>
 
- Public Types inherited from Registry::VisitorFunctions< MenuRegistry::Traits >
using NodeTypes = detail::VisitedNodeTypes< MenuRegistry::Traits >
 
using LeafTypes = detail::VisitedLeafTypes< MenuRegistry::Traits >
 
- Public Attributes inherited from MenuRegistry::detail::VisitorBase
std::vector< bool > firstItem
 
std::vector< bool > needSeparator
 
- Protected Member Functions inherited from CommandManager::Populator
void DoBeginGroup (const MenuRegistry::GroupItem< MenuRegistry::Traits > &item)
 
void DoVisit (const Registry::SingleItem &item)
 
void DoEndGroup (const MenuRegistry::GroupItem< MenuRegistry::Traits > &item)
 
virtual void BeginMenu (const TranslatableString &tName)
 
virtual void BeginOccultCommands ()
 
virtual void EndMenu ()
 
virtual void EndOccultCommands ()
 
virtual std::unique_ptr< CommandListEntryAllocateEntry (const MenuRegistry::Options &options)
 
virtual void VisitEntry (CommandListEntry &entry, const MenuRegistry::Options *options)
 
void DoSeparator ()
 
const TranslatableStringsMenuNames () const
 Stack of names of menus that were begun and not yet ended. More...
 
- Protected Attributes inherited from CommandManager::Populator
AudacityProjectmProject
 
bool mbSeparatorAllowed { false }
 

Detailed Description

Definition at line 109 of file MenuCreator.cpp.

Constructor & Destructor Documentation

◆ MenuItemVisitor()

anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::MenuItemVisitor ( AudacityProject proj)
inlineexplicit

Definition at line 110 of file MenuCreator.cpp.

112 // leaf visit
113 [this](const auto &item, const auto&) {
114 const auto pCurrentMenu = CurrentMenu();
115 if (!pCurrentMenu) {
116 // There may have been a mistake in the placement hint that
117 // registered this single item. It's not within any menu.
118 assert(false);
119 }
120 else TypeSwitch::VDispatch<void, LeafTypes>(item,
121 [&](const SpecialItem &special) {
122 if (auto pSpecial =
123 dynamic_cast<const MenuCreator::SpecialItem*>(&special))
124 pSpecial->fn(mProject, *pCurrentMenu);
125 },
126 [this](auto &item){ DoVisit(item); }
127 );
128 },
129
130 [this]{
132 CurrentMenu()->AppendSeparator();
133 Populator::DoSeparator();
134 }
135 }
136 {
137 auto menubar = AddMenuBar(wxT("appmenu"));
138 assert(menubar);
139
141
142 GetProjectFrame(mProject).SetMenuBar(menubar.release());
143 }
wxT("CloseDown"))
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
MENUS_API void Visit(Visitor< Traits > &visitor, AudacityProject &project)
void DoVisit(const Registry::SingleItem &item)
AudacityProject & mProject
std::unique_ptr< wxMenuBar > AddMenuBar(const wxString &sMenu)

◆ ~MenuItemVisitor()

anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::~MenuItemVisitor ( )
overridedefault

Member Function Documentation

◆ AddMenuBar()

std::unique_ptr< wxMenuBar > MenuItemVisitor::AddMenuBar ( const wxString &  sMenu)
private

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, that's unexpected.

Definition at line 967 of file MenuCreator.cpp.

968{
969 wxMenuBar *menuBar = GetMenuBar(sMenu);
970 if (menuBar) {
971 wxASSERT(false);
972 return {};
973 }
974
975 auto result = std::make_unique<wxMenuBar>();
976 mMenuBarList.emplace_back(sMenu, result.get());
977
978 return result;
979}
wxMenuBar * GetMenuBar(const wxString &sMenu) const

◆ AllocateEntry()

auto anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::AllocateEntry ( const MenuRegistry::Options options)
finalprivatevirtual

Called by DoVisit Override to make entries that carry extra information. Not called for every visit, because existing items may be reused

Postcondition
result: result != nullptr

Reimplemented from CommandManager::Populator.

Definition at line 252 of file MenuCreator.cpp.

254{
255 auto result = std::make_unique<CommandListEntryEx>();
256 if (!options.global)
257 result->menu = CurrentMenu();
258 return result;
259}

◆ BeginMainMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::BeginMainMenu ( const TranslatableString tName)
private

Definition at line 373 of file MenuCreator.cpp.

374{
375 uCurrentMenu = std::make_unique<wxMenu>();
377}

◆ BeginMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::BeginMenu ( const TranslatableString tName)
finalprivatevirtual

Called by DoBeginGroup Default implementation does nothing

Reimplemented from CommandManager::Populator.

Definition at line 355 of file MenuCreator.cpp.

356{
357 if (mCurrentMenu)
358 return BeginSubMenu(tName);
359 else
360 return BeginMainMenu(tName);
361}
void BeginSubMenu(const TranslatableString &tName)
void BeginMainMenu(const TranslatableString &tName)

◆ BeginOccultCommands()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::BeginOccultCommands ( )
finalprivatevirtual

Called by DoBeginGroup Default implementation does nothing

Reimplemented from CommandManager::Populator.

Definition at line 417 of file MenuCreator.cpp.

418{
419 // To do: perhaps allow occult item switching at lower levels of the
420 // menu tree.
421 assert(!CurrentMenu());
422
423 // Make a temporary menu bar collecting items added after.
424 // This bar will be discarded but other side effects on the command
425 // manager persist.
426 mTempMenuBar = AddMenuBar(wxT("ext-menu"));
427}

References wxT().

Here is the call graph for this function:

◆ BeginSubMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::BeginSubMenu ( const TranslatableString tName)
private

◆ CurrentMenu()

wxMenu * MenuItemVisitor::CurrentMenu ( ) const
private

This returns the current menu that we're appending to - note that it could be a submenu if BeginSubMenu was called and we haven't reached EndSubMenu yet.

Definition at line 1020 of file MenuCreator.cpp.

1021{
1022 if(!mCurrentMenu)
1023 return NULL;
1024
1025 wxMenu * tmpCurrentSubMenu = CurrentSubMenu();
1026
1027 if(!tmpCurrentSubMenu)
1028 {
1029 return mCurrentMenu;
1030 }
1031
1032 return tmpCurrentSubMenu;
1033}

◆ CurrentMenuBar()

wxMenuBar * MenuItemVisitor::CurrentMenuBar ( ) const
private

Retrieve the 'current' menubar; either NULL or the last on in the mMenuBarList.

Definition at line 998 of file MenuCreator.cpp.

999{
1000 if(mMenuBarList.empty())
1001 return NULL;
1002
1003 return mMenuBarList.back().menubar;
1004}

◆ CurrentSubMenu()

wxMenu * MenuItemVisitor::CurrentSubMenu ( ) const
private

This returns the 'Current' Submenu, which is the one at the end of the mSubMenuList (or NULL, if it doesn't exist).

Definition at line 1008 of file MenuCreator.cpp.

1009{
1010 if(mSubMenuList.empty())
1011 return NULL;
1012
1013 return mSubMenuList.back().menu.get();
1014}

◆ EndMainMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::EndMainMenu ( )
private

◆ EndMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::EndMenu ( )
finalprivatevirtual

Called by DoEndGroup Default implementation does nothing

Reimplemented from CommandManager::Populator.

◆ EndOccultCommands()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::EndOccultCommands ( )
finalprivatevirtual

Called by DoEndGroup Default implementation does nothing

Reimplemented from CommandManager::Populator.

Definition at line 429 of file MenuCreator.cpp.

430{
431 auto iter = mMenuBarList.end();
432 if (iter != mMenuBarList.begin())
433 mMenuBarList.erase(--iter);
434 else
435 assert(false);
436 mTempMenuBar.reset();
437}

◆ EndSubMenu()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::EndSubMenu ( )
private

◆ GetMenuBar()

wxMenuBar * MenuItemVisitor::GetMenuBar ( const wxString &  sMenu) const
private

Retrieves the menubar based on the name given in AddMenuBar(name)

Definition at line 984 of file MenuCreator.cpp.

985{
986 for (const auto &entry : mMenuBarList)
987 {
988 if(entry.name == sMenu)
989 return entry.menubar;
990 }
991
992 return NULL;
993}
static ProjectFileIORegistry::AttributeWriterEntry entry

References entry.

◆ VisitEntry()

void anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::VisitEntry ( CommandManager::CommandListEntry entry,
const MenuRegistry::Options options 
)
finalprivatevirtual

Called by DoVisit Override to intercept all visits of items; default implementation is noop

Parameters
optionsnull if a member of a list of commands

Reimplemented from CommandManager::Populator.

Definition at line 332 of file MenuCreator.cpp.

334{
335 if (!pOptions)
336 // command list item
337 CurrentMenu()->Append(entry.id, entry.FormatLabelForMenu());
338 else if (pOptions->global)
339 ;
340 else {
341 auto ID = entry.id;
343 auto &checker = pOptions->checker;
344 if (checker) {
345 CurrentMenu()->AppendCheckItem(ID, label);
346 CurrentMenu()->Check(ID, checker(mProject));
347 }
348 else
349 CurrentMenu()->Append(ID, label);
350 }
351}
TranslatableString label
Definition: TagsEditor.cpp:165
static wxString FormatLabelWithDisabledAccel(const CommandManager::CommandListEntry &entry)

References MenuRegistry::Options::checker, entry, anonymous_namespace{MenuCreator.cpp}::FormatLabelWithDisabledAccel(), MenuRegistry::Options::global, and label.

Here is the call graph for this function:

Member Data Documentation

◆ mCurrentMenu

wxMenu* anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::mCurrentMenu {}
private

Definition at line 183 of file MenuCreator.cpp.

◆ mMenuBarList

std::vector<MenuBarListEntry> anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::mMenuBarList
private

Definition at line 179 of file MenuCreator.cpp.

◆ mSubMenuList

std::vector<SubMenuListEntry> anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::mSubMenuList
private

Definition at line 180 of file MenuCreator.cpp.

◆ mTempMenuBar

std::unique_ptr<wxMenuBar> anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::mTempMenuBar
private

Definition at line 181 of file MenuCreator.cpp.

◆ uCurrentMenu

std::unique_ptr<wxMenu> anonymous_namespace{MenuCreator.cpp}::MenuItemVisitor::uCurrentMenu
private

Definition at line 182 of file MenuCreator.cpp.


The documentation for this struct was generated from the following file: