| 252 | */ |
| 253 | template <class TMenuItem = ui::MenuItem> |
| 254 | TMenuItem* createCheckMenuItem(std::string text, std::string rightText, std::function<bool()> checked, std::function<void()> action, bool disabled = false, bool alwaysConsume = false) { |
| 255 | struct Item : TMenuItem { |
| 256 | std::string rightTextPrefix; |
| 257 | std::function<bool()> checked; |
| 258 | std::function<void()> action; |
| 259 | bool alwaysConsume; |
| 260 | |
| 261 | void step() override { |
| 262 | this->rightText = rightTextPrefix; |
| 263 | if (checked()) { |
| 264 | if (!rightTextPrefix.empty()) |
| 265 | this->rightText += " "; |
| 266 | this->rightText += CHECKMARK_STRING; |
| 267 | } |
| 268 | TMenuItem::step(); |
| 269 | } |
| 270 | void onAction(const event::Action& e) override { |
| 271 | action(); |
| 272 | if (alwaysConsume) |
| 273 | e.consume(this); |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | Item* item = createMenuItem<Item>(text); |
| 278 | item->rightTextPrefix = rightText; |
| 279 | item->checked = checked; |
| 280 | item->action = action; |
| 281 | item->disabled = disabled; |
| 282 | item->alwaysConsume = alwaysConsume; |
| 283 | return item; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /** Creates a MenuItem that controls a boolean value with a check mark. |
no outgoing calls
no test coverage detected