| 53 | class PopupMenuBuilder : public MenuRegistry::Visitor<PopupMenuTableTraits> { |
| 54 | public: |
| 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 } |
nothing calls this directly
no test coverage detected