| 530 | } |
| 531 | |
| 532 | bool DockLayout::save(DockLayout::Index layout_index) |
| 533 | { |
| 534 | if (!g_debugger_window) |
| 535 | return false; |
| 536 | |
| 537 | if (m_is_active) |
| 538 | { |
| 539 | m_toolbars = g_debugger_window->saveState(); |
| 540 | |
| 541 | // Store the geometry of all the dock widgets as JSON. |
| 542 | KDDockWidgets::LayoutSaver saver(KDDockWidgets::RestoreOption_RelativeToMainWindow); |
| 543 | m_geometry = saver.serializeLayout(); |
| 544 | } |
| 545 | |
| 546 | // Serialize the layout as JSON. |
| 547 | rapidjson::Document json(rapidjson::kObjectType); |
| 548 | rapidjson::Document geometry; |
| 549 | |
| 550 | const char* cpu_name = DebugInterface::cpuName(m_cpu); |
| 551 | u32 default_layout_hash = DockTables::hashDefaultLayouts(); |
| 552 | |
| 553 | rapidjson::Value format; |
| 554 | format.SetString(DEBUGGER_LAYOUT_FILE_FORMAT, strlen(DEBUGGER_LAYOUT_FILE_FORMAT)); |
| 555 | json.AddMember("format", format, json.GetAllocator()); |
| 556 | |
| 557 | json.AddMember("versionMajor", DEBUGGER_LAYOUT_FILE_VERSION_MAJOR, json.GetAllocator()); |
| 558 | json.AddMember("versionMinor", DEBUGGER_LAYOUT_FILE_VERSION_MINOR, json.GetAllocator()); |
| 559 | json.AddMember("defaultLayoutHash", default_layout_hash, json.GetAllocator()); |
| 560 | |
| 561 | std::string name_str = m_name.toStdString(); |
| 562 | json.AddMember("name", rapidjson::Value().SetString(name_str.c_str(), name_str.size()), json.GetAllocator()); |
| 563 | json.AddMember("target", rapidjson::Value().SetString(cpu_name, strlen(cpu_name)), json.GetAllocator()); |
| 564 | json.AddMember("index", static_cast<int>(layout_index), json.GetAllocator()); |
| 565 | json.AddMember("isDefault", m_is_default, json.GetAllocator()); |
| 566 | json.AddMember("nextId", m_next_id, json.GetAllocator()); |
| 567 | |
| 568 | if (!m_base_layout.empty()) |
| 569 | { |
| 570 | rapidjson::Value base_layout; |
| 571 | base_layout.SetString(m_base_layout.c_str(), m_base_layout.size()); |
| 572 | json.AddMember("baseLayout", base_layout, json.GetAllocator()); |
| 573 | } |
| 574 | |
| 575 | if (!m_toolbars.isEmpty()) |
| 576 | { |
| 577 | std::string toolbars_str = m_toolbars.toBase64().toStdString(); |
| 578 | rapidjson::Value toolbars; |
| 579 | toolbars.SetString(toolbars_str.data(), toolbars_str.size(), json.GetAllocator()); |
| 580 | json.AddMember("toolbars", toolbars, json.GetAllocator()); |
| 581 | } |
| 582 | |
| 583 | rapidjson::Value dock_widgets(rapidjson::kArrayType); |
| 584 | for (auto& [unique_name, widget] : m_widgets) |
| 585 | { |
| 586 | pxAssert(widget.get()); |
| 587 | |
| 588 | rapidjson::Value object(rapidjson::kObjectType); |
| 589 |
no test coverage detected