| 353 | } |
| 354 | |
| 355 | void DockManager::createWindowsMenu(QMenu* menu) |
| 356 | { |
| 357 | menu->clear(); |
| 358 | |
| 359 | if (m_current_layout == DockLayout::INVALID_INDEX) |
| 360 | return; |
| 361 | |
| 362 | DockLayout& layout = m_layouts.at(m_current_layout); |
| 363 | |
| 364 | // Create a menu that allows for multiple dock widgets of the same type to |
| 365 | // be opened. |
| 366 | QMenu* add_another_menu = menu->addMenu(tr("Add Another...")); |
| 367 | |
| 368 | std::vector<DebuggerView*> add_another_widgets; |
| 369 | std::set<std::string> add_another_types; |
| 370 | for (const auto& [unique_name, widget] : layout.debuggerViews()) |
| 371 | { |
| 372 | std::string type = widget->metaObject()->className(); |
| 373 | |
| 374 | if (widget->supportsMultipleInstances() && !add_another_types.contains(type)) |
| 375 | { |
| 376 | add_another_widgets.emplace_back(widget); |
| 377 | add_another_types.emplace(type); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | std::sort(add_another_widgets.begin(), add_another_widgets.end(), |
| 382 | [](const DebuggerView* lhs, const DebuggerView* rhs) { |
| 383 | if (lhs->displayNameWithoutSuffix() == rhs->displayNameWithoutSuffix()) |
| 384 | return lhs->displayNameSuffixNumber() < rhs->displayNameSuffixNumber(); |
| 385 | |
| 386 | return lhs->displayNameWithoutSuffix() < rhs->displayNameWithoutSuffix(); |
| 387 | }); |
| 388 | |
| 389 | for (DebuggerView* widget : add_another_widgets) |
| 390 | { |
| 391 | const char* type = widget->metaObject()->className(); |
| 392 | |
| 393 | const auto description_iterator = DockTables::DEBUGGER_VIEWS.find(type); |
| 394 | pxAssert(description_iterator != DockTables::DEBUGGER_VIEWS.end()); |
| 395 | |
| 396 | QString display_name = QCoreApplication::translate( |
| 397 | "DebuggerView", description_iterator->second.display_name); |
| 398 | |
| 399 | QAction* action = add_another_menu->addAction(display_name); |
| 400 | connect(action, &QAction::triggered, this, [this, type]() { |
| 401 | if (m_current_layout == DockLayout::INVALID_INDEX) |
| 402 | return; |
| 403 | |
| 404 | m_layouts.at(m_current_layout).createDebuggerView(type); |
| 405 | }); |
| 406 | } |
| 407 | |
| 408 | if (add_another_widgets.empty()) |
| 409 | add_another_menu->setDisabled(true); |
| 410 | |
| 411 | menu->addSeparator(); |
| 412 |
no test coverage detected