From 5cd0c6b4f33c54a2fdbe2d7317b840a36098b014 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 28 Feb 2022 07:09:09 +0100 Subject: [PATCH] #5841: Save and restore the state of all floating ortho views when using Docking layout --- install/user.xml | 3 -- radiant/ui/mainframe/AuiLayout.cpp | 6 +++ radiant/xyview/GlobalXYWnd.cpp | 70 +++++++++++++----------------- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/install/user.xml b/install/user.xml index 1d8a02b6ff..5cb005ec7d 100644 --- a/install/user.xml +++ b/install/user.xml @@ -152,9 +152,6 @@ - - - diff --git a/radiant/ui/mainframe/AuiLayout.cpp b/radiant/ui/mainframe/AuiLayout.cpp index b95dfdf65d..151095bd80 100644 --- a/radiant/ui/mainframe/AuiLayout.cpp +++ b/radiant/ui/mainframe/AuiLayout.cpp @@ -130,10 +130,16 @@ void AuiLayout::activate() GlobalMenuManager().setVisibility("main/view/cameraview", false); // Hide the console/texture browser toggles for non-floating/non-split views GlobalMenuManager().setVisibility("main/view/textureBrowser", false); + + // Restore all floating XY views + GlobalXYWnd().restoreState(); } void AuiLayout::deactivate() { + // Save all floating XYWnd states + GlobalXYWnd().saveState(); + // Store perspective GlobalRegistry().set(RKEY_ROOT, _auiMgr.SavePerspective().ToStdString()); diff --git a/radiant/xyview/GlobalXYWnd.cpp b/radiant/xyview/GlobalXYWnd.cpp index 9bbc07cc9c..3a39563088 100644 --- a/radiant/xyview/GlobalXYWnd.cpp +++ b/radiant/xyview/GlobalXYWnd.cpp @@ -72,49 +72,38 @@ XYWndManager::XYWndManager() : */ void XYWndManager::restoreState() { - xml::NodeList views = GlobalRegistry().findXPath(RKEY_XYVIEW_ROOT + "//views"); + auto views = GlobalRegistry().findXPath(RKEY_XYVIEW_ROOT + "//views"); - if (!views.empty()) + if (views.empty()) return; + + // Find all tags under the first found tag + auto viewList = views[0].getNamedChildren("view"); + + for (const auto& node : viewList) { - // Find all tags under the first found tag - xml::NodeList viewList = views[0].getNamedChildren("view"); + // Assemble the XPath for the viewstate + std::string path = RKEY_XYVIEW_ROOT + + "/views/view[@name='" + node.getAttributeValue("name") + "']"; + + const std::string typeStr = node.getAttributeValue("type"); - for (xml::NodeList::const_iterator i = viewList.begin(); - i != viewList.end(); - ++i) + EViewType type = XY; + + if (typeStr == "YZ") { - // Assemble the XPath for the viewstate - std::string path = RKEY_XYVIEW_ROOT + - "/views/view[@name='" + i->getAttributeValue("name") + "']"; - - const std::string typeStr = i->getAttributeValue("type"); - - EViewType type = XY; - - if (typeStr == "YZ") - { - type = YZ; - } - else if (typeStr == "XZ") - { - type = XZ; - } - else - { - type = XY; - } - - // Create the view and restore the size - XYWndPtr newWnd = createFloatingOrthoView(type); + type = YZ; + } + else if (typeStr == "XZ") + { + type = XZ; + } + else + { + type = XY; } - } - else - { - // Create at least one XYView, if no view info is found - rMessage() << "XYWndManager: No xywindow information found in XMLRegistry, creating default view.\n"; - // Create a default OrthoView - createFloatingOrthoView(XY); + // Create the view and restore the size + createFloatingOrthoView(type); } } @@ -126,10 +115,10 @@ void XYWndManager::saveState() // Create a new node std::string rootNodePath(RKEY_XYVIEW_ROOT + "/views"); - for (XYWndMap::iterator i = _xyWnds.begin(); i != _xyWnds.end(); ++i) + for (auto& [_, view] : _xyWnds) { // Save each XYView state to the registry - FloatingOrthoViewPtr floatingView = std::dynamic_pointer_cast(i->second); + auto floatingView = std::dynamic_pointer_cast(view); if (floatingView) { @@ -138,11 +127,10 @@ void XYWndManager::saveState() } } -// Free the allocated XYViews from the heap void XYWndManager::destroyViews() { // Discard the whole list - for (XYWndMap::iterator i = _xyWnds.begin(); i != _xyWnds.end(); /* in-loop incr.*/) + for (auto i = _xyWnds.begin(); i != _xyWnds.end(); /* in-loop incr.*/) { // Extract the pointer to prevent the destructor from firing XYWndPtr candidate = i->second;