| 248 | } |
| 249 | |
| 250 | std::vector<QAction*> DebuggerView::createEventActionsImplementation( |
| 251 | QMenu* menu, |
| 252 | u32 max_top_level_actions, |
| 253 | bool skip_self, |
| 254 | const char* event_type, |
| 255 | const char* action_string, |
| 256 | const char* action_overflow_string, |
| 257 | std::function<const DebuggerEvents::Event*()> event_func) |
| 258 | { |
| 259 | if (!g_debugger_window) |
| 260 | return {}; |
| 261 | |
| 262 | std::vector<DebuggerView*> receivers; |
| 263 | for (const auto& [unique_name, widget] : g_debugger_window->dockManager().debuggerViews()) |
| 264 | if ((!skip_self || widget != this) && widget->acceptsEventType(event_type)) |
| 265 | receivers.emplace_back(widget); |
| 266 | |
| 267 | std::sort(receivers.begin(), receivers.end(), [&](const DebuggerView* lhs, const DebuggerView* rhs) { |
| 268 | if (lhs->displayNameWithoutSuffix() == rhs->displayNameWithoutSuffix()) |
| 269 | return lhs->displayNameSuffixNumber() < rhs->displayNameSuffixNumber(); |
| 270 | |
| 271 | return lhs->displayNameWithoutSuffix() < rhs->displayNameWithoutSuffix(); |
| 272 | }); |
| 273 | |
| 274 | QMenu* submenu = nullptr; |
| 275 | if (receivers.size() > max_top_level_actions) |
| 276 | { |
| 277 | submenu = new QMenu(QCoreApplication::translate("DebuggerEvents", action_overflow_string), menu); |
| 278 | } |
| 279 | |
| 280 | std::vector<QAction*> actions; |
| 281 | for (size_t i = 0; i < receivers.size(); i++) |
| 282 | { |
| 283 | DebuggerView* receiver = receivers[i]; |
| 284 | |
| 285 | QAction* action; |
| 286 | if (!submenu || i + 1 < max_top_level_actions) |
| 287 | { |
| 288 | QString title_format = QCoreApplication::translate("DebuggerEvents", action_string); |
| 289 | QString title = title_format.arg(receiver->displayName()); |
| 290 | action = new QAction(title, menu); |
| 291 | menu->addAction(action); |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | action = new QAction(receiver->displayName(), submenu); |
| 296 | submenu->addAction(action); |
| 297 | } |
| 298 | |
| 299 | connect(action, &QAction::triggered, receiver, [receiver, event_func]() { |
| 300 | const DebuggerEvents::Event* event = event_func(); |
| 301 | if (event) |
| 302 | receiver->handleEvent(*event); |
| 303 | }); |
| 304 | |
| 305 | actions.emplace_back(action); |
| 306 | } |
| 307 |
nothing calls this directly
no test coverage detected