MCPcopy Create free account
hub / github.com/audacity/audacity / PopupMenuBuilder

Method PopupMenuBuilder

src/widgets/PopupMenuTable.cpp:55–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53class PopupMenuBuilder : public MenuRegistry::Visitor<PopupMenuTableTraits> {
54public:
55 PopupMenuBuilder(PopupMenuTable &table, PopupMenuImpl &menu, void *pUserData)
56 : MenuRegistry::Visitor<PopupMenuTableTraits>{ std::tuple{
57 [this](const PopupSubMenu &item, const auto &){
58 if (!item.caption.empty()) {
59 auto newMenu =
60 std::make_unique<PopupMenuImpl>(mMenu->pUserData);
61 mMenu = newMenu.get();
62 mMenus.push_back(std::move(newMenu));
63 }
64 },
65
66 [this](const PopupMenuTableEntry &entry, const auto &){
67 switch (entry.type) {
68 case PopupMenuTable::Entry::Item:
69 {
70 mMenu->Append(entry.id, entry.caption.Translation());
71 break;
72 }
73 case PopupMenuTable::Entry::RadioItem:
74 {
75 mMenu->AppendRadioItem(entry.id, entry.caption.Translation());
76 break;
77 }
78 case PopupMenuTable::Entry::CheckItem:
79 {
80 mMenu->AppendCheckItem(entry.id, entry.caption.Translation());
81 break;
82 }
83 default:
84 assert(false);
85 break;
86 }
87
88 // This call is necessary for externally registered items, else
89 // harmlessly redundant
90 entry.handler.InitUserData(mpUserData);
91
92 if (entry.init)
93 entry.init(entry.handler, *mMenu, entry.id);
94
95 mMenu->Bind(
96 wxEVT_COMMAND_MENU_SELECTED, entry.func, &entry.handler, entry.id);
97 },
98
99 [this](const PopupSubMenu &item, const auto &){
100 if (!item.caption.empty()) {
101 auto subMenu = std::move(mMenus.back());
102 mMenus.pop_back();
103 mMenu = mMenus.empty() ? mRoot : mMenus.back().get();
104 mMenu->AppendSubMenu(subMenu.release(), item.caption.Translation());
105 }
106 }},
107
108 [this]() {
109 mMenu->AppendSeparator();
110 }
111 }
112 , mMenu{ &menu }

Callers

nothing calls this directly

Calls 11

moveFunction · 0.85
TranslationMethod · 0.80
BindMethod · 0.80
AppendSubMenuMethod · 0.80
emptyMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45
AppendMethod · 0.45
InitUserDataMethod · 0.45
initMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected